比如在某一oracle function中有如下代码:
dd varchar2(20); select aa into dd from table_A where bb= 'c'; // sql_a IF dd = ? THEN -- do something
END IF; .....
提问:若sql_a找不到记录,然后IF语句是判断是否返回记录的, 请问 上述代码中的 ? 究竟是个什么值,我尝试过“ dd = null ”,“dd is null”,“ dd = '' ”都不行,知道的请回帖一下,谢谢!
dd varchar2(20); select aa into dd from table_A where bb= 'c'; // sql_a IF dd = ? THEN -- do something
END IF; .....
提问:若sql_a找不到记录,然后IF语句是判断是否返回记录的, 请问 上述代码中的 ? 究竟是个什么值,我尝试过“ dd = null ”,“dd is null”,“ dd = '' ”都不行,知道的请回帖一下,谢谢!
begin
select aa into dd from table_A where bb= 'c';
exception
when no_data_found then
dd := null;
endif dd is null then
....调调代码,可能有些地方要改
when no_data_found then
do something;
end ; 没有记录的时候用 no_data_found 捕获
select aa into dd from table_A where bb= 'c';
如果无返回结果,就将触发异常。SQL> set serveroutput on
SQL>
SQL> declare
2 v_test char(1);
3 begin
4 select * into v_test from dual where 1=2;
5 if v_test is null then
6 dbms_output.put_line('哈哈,为空!');
7 end if;
8 end;
9 /declare
v_test char(1);
begin
select * into v_test from dual where 1=2;
if v_test is null then
dbms_output.put_line('哈哈,为空!');
end if;
end;ORA-01403: 未找到数据
ORA-06512: 在 line 4SQL>
SQL> declare
2 v_test char(1);
3 begin
4 begin
5 select * into v_test from dual where 1=2;
6 exception
7 when no_data_found then
8 dbms_output.put_line('爱慕所瑞,为空!');
9 end;
10 end;
11 /爱慕所瑞,为空!PL/SQL procedure successfully completedSQL>