the syntax is not working in oracle , but oracle has some other way to do it :
select count(*)
into li_count
from user where id = 3;
if li_count > 0 then
do something;
else
do other things;
end if;
select count(*)
into li_count
from user where id = 3;
if li_count > 0 then
do something;
else
do other things;
end if;
Just one sql:-) select * from user where id = 3
and not exists ( select * from user where id = 4)
Union
select * from user where id = 4;
begin
select * from user where id=3
-- 存在,do something
exception
when no_data_found then
--不存在,do something
select count(*) into li_count
from user_dict where id = 3;
if li_count > 0 then
select * from user_dict where id=3;
else
select * from user_dict where id=4;
end if;
但在sql worksheet中执行出错,
总是说我“ORA-00900: 无效 SQL 语句”
不知是不是我写错了
请指教!
SQL> declare
2 num number;
3 begin
4 select count(*) into num from aa where rownum<=1;
5 if sql%notfound then
6 dbms_output.put_line('没有');
7 else
8 dbms_output.put_line('有');
9 end if;
10 end;
11 /
有
select * from user_dict where id=3;
else
select * from user_dict where id=4;
end if;
有问题,你必须用into 把值取出来.
2 num number;
3 begin
4 select count(*) into num from aa where 1=2;
5 if num>0 then
6 dbms_output.put_line('没有');
7 else
8 dbms_output.put_line('有');
9 end if;
10 end;
11 /
有0>0根本不能判断,0不能大于0,iv
SQL> declare
2 num number;
3 begin
4 select count(*) into num from aa where 1=2;
5 if num>0 then
6 dbms_output.put_line('没有');
7 else
8 dbms_output.put_line('有');
9 end if;
10 end;
11 /
有what's the problem , because num = 0 , so if condition failed
and system go to else condition and output '有'??????please use >0 anyway , it's safe anyway:-)