if exists(select * from Table where Col='hhhh') then 执行插入 end if
Sorry 不存在應該為: if not exists(select * from Table where Col='hhhh') then 执行插入 end if
在Oracle中, 不能将exists用于if判断中, 类似MSSQL这样的写法是错误的 因此,只能 select fieldname into fieldvar from tablename if fieldvar then ... else ... end if;
declare n_count integer; begin select count(1) into n_count from dual where exists (select fieldname from tablename where ???); if n_count = 0 then -- 插入语句 end if; end;
执行插入
end if
不存在應該為:
if not exists(select * from Table where Col='hhhh') then
执行插入
end if
因此,只能
select fieldname into fieldvar from tablename
if fieldvar then
...
else
...
end if;
n_count integer;
begin
select count(1)
into n_count
from dual
where exists (select fieldname from tablename where ???);
if n_count = 0 then
-- 插入语句
end if;
end;