SQL> declare v_null varchar2(100) :='ttt'; 2 begin 3 dbms_output.put_line('v_null:'||v_null); 4 select null into v_null from dual; 5 if v_null is null then 6 dbms_output.put_line('hello world'); 7 end if; 8 end; 9 / v_null:ttt hello worldPL/SQL 过程已成功完成。
针对你的情况可以做如下处理SQL> select * from t;NN --------------------------------------------------------- --------------------------------------------------------- --------------------------------------------------------- 100 100SQL> declare v_nn varchar2(100); 2 begin 3 select distinct nn into v_nn from t where nn='100'; 4 dbms_output.put_line('v_nn='||v_nn); 5 end; 6 / v_nn=100
select a.id
into v_id
from test a
where a.id = '100'
excption when NO_DATA_FOUND then
--没有找到数据
when TOO_MANY_ROWS then
--找到多条数据
end;
select count(a.id) to is_exists
from test a
where a.id = '100';
if IS_EXISTS = 1
THEN
select a.id into v_id
from test a
where a.id = '100';
else
end if;
end;
If the v_count ...
else...
end if.
如果是要一行一行的处理的话,先将结果select到collect集合中再做处理。
2 begin
3 dbms_output.put_line('v_null:'||v_null);
4 select null into v_null from dual;
5 if v_null is null then
6 dbms_output.put_line('hello world');
7 end if;
8 end;
9 /
v_null:ttt
hello worldPL/SQL 过程已成功完成。
---------------------------------------------------------
---------------------------------------------------------
---------------------------------------------------------
100
100SQL> declare v_nn varchar2(100);
2 begin
3 select distinct nn into v_nn from t where nn='100';
4 dbms_output.put_line('v_nn='||v_nn);
5 end;
6 /
v_nn=100