我在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
答案 0 :(得分:4)
您应该使用=
代替==
。
以下是您可以使用的不同比较运算符的列表:
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
答案 1 :(得分:3)
正如所指出的,相等的比较运算符是=
而不是==
。但是,您应该将条件写为:
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%');