Oracle - 在IF THEN ELSE语句中处理空结果集

时间:2011-07-15 14:26:53

标签: stored-procedures plsql oracle10g

当变量赋值来自空结果集时,它应该是IF条件?

示例:

CREATE OR REPLACE Function get_values
     ( chv_input IN varchar2 )
     RETURN varchar2
IS
     chv_output varchar2(100);

  BEGIN

select 'value'
    into chv_output
from dual where 1=2; 

IF chv_output is null THEN --this condition is not working

    chv_output := 'null';

ELSE
     chv_output := 'not null';

END IF;

  RETURN chv_output;

END;

--select 1, get_values('112') from dual

1 个答案:

答案 0 :(得分:2)

请改为尝试:

EXCEPTION
WHEN NO_DATA_FOUND
  chv_output := 'null';