create or replace function getStkCode(p_gzcode varchar2)
return varchar2 as
v_stkcode varchar2(100);
begin
with temp_kvs_stkgzcode as(select * from srv_kvs_stkgzcode)
select stkcode
into v_stkcode
from temp_kvs_stkgzcode a
where a.GZCODE = p_gzcode and rownum = 1 ;
return v_stkcode;
exception
when NO_DATA_FOUND then v_stkcode :=p_gzcode;
return v_stkcode;
END;
如果根据入参执行sql查不到数据,就把入参返回给出参;
如果sql查不到数据,into的时候就会报异常:No Data found,该处为异常并不适合使用IF,所以通过捕获异常处理。
参考:oracle的异常https://blog.youkuaiyun.com/xu810260277/article/details/89166559