我在postgres函数中使用这些语句。
Select count(*) into V_check
from employee
where employee_name like 'Raj%';
if V_check == 0
then
update exception set exception_found = 'Raj';
end if;
我收到此错误:
ERROR: operator does not exist: integer == integer LINE 1: SELECT V_check == 0
你应该使用=
而不是==
。
以下是您可以使用的不同比较运算符的列表:
Operator Description
= Equal
<> Not equal. Note: In some versions of SQL this operator may be written as !=
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
BETWEEN Between an inclusive range
LIKE Search for a pattern
IN To specify multiple possible values for a column
正如所指出的,相等的比较运算符是=
而不是==
。但是,您应该将条件写为:
if not exists (select 1 from employee where employee_name like 'Raj%')
then
update exception
set exception_found = 'Raj';
end if;
这可以为您节省声明。此外,not exists
比count(*)
快 - 因为not exists
可以停在第一个匹配的行。
或完全免除条件:
update exception
set exception_found = 'Raj'
where not exists (select 1 from employee where employee_name like 'Raj%');