function query_db(v_df_dk_yhxx in varchar2) return number is
f_db number;
f_flag varchar2(2);
begin
select flag into f_flag from ceshi where yhbh=v_df_dk_yhxx;
if f_flag=1 or f_flag is null then
return 0;
else
select YHDJ into f_db from ceshi where yhbh=v_df_dk_yhxx;
return f_db;
end if;
end query_db;
我的程序包体,select flag into f_flag from ceshi where yhbh=v_df_dk_yhxx,如果传入的值v_df_dk_yhxx,在这个ceshi表里面根本就没有数据的话,就会报错
“为找到数据”,怎么写才能避免这个错误?
f_db number;
f_flag varchar2(2);
begin
select flag into f_flag from ceshi where yhbh=v_df_dk_yhxx;
if f_flag=1 or f_flag is null then
return 0;
else
select YHDJ into f_db from ceshi where yhbh=v_df_dk_yhxx;
return f_db;
end if;
end query_db;
我的程序包体,select flag into f_flag from ceshi where yhbh=v_df_dk_yhxx,如果传入的值v_df_dk_yhxx,在这个ceshi表里面根本就没有数据的话,就会报错
“为找到数据”,怎么写才能避免这个错误?
是不是要改成
select flag into f_flag from ceshi where yhbh=:v_df_dk_yhxx
execption
when no_data_found then
dbms_output_line('没有数据');
end;
f_db integer;
f_flag varchar2(2);
count_db integer;
begin
select count(*) into count_db from ceshi where yhbh=v_df_dk_yhxx;
if count_db>0 then
select flag into f_flag from ceshi where yhbh=v_df_dk_yhxx;
if f_flag=1 or f_flag is null then
return 0;
else
select YHDJ into f_db from ceshi where yhbh=v_df_dk_yhxx;
return f_db;
end if;
else
return 0;
end if;
end query_db;
自己解决了,回楼上上的=:就是赋值了