mysql no data found_ORA-01403:no data found exception的解决小道

问题:在使用select into from tablename这样的隐式游标的时候,如果查不到数据,那么会报ora-01403的错误。而每次使用显式游标,

问题:在使用select into from tablename这样的隐式游标的时候,如果查不到数据,那么会报ora-01403的错误。而每次使用显式游标,再打开取值就显得很麻烦。一个经验丰富的老师提出可以用类似max min等这样的聚合函数,,来避免select into带来的异常,又避免每次使用游标的麻烦。

效率和可行性测试:

①临时表

CREATE TABLE EDU.TEST

(

ID NUMBER NULL

)

TABLESPACE EDUCATION

NOLOGGING

PCTFREE 10

PCTUSED 0

INITRANS 1

MAXTRANS 255

STORAGE(BUFFER_POOL DEFAULT)

NOPARALLEL

NOCACHE

② 用PL/SQL块测试

A、create or replace procedure proc_max(id varchar2)

as

var dba_tables.table_name%type:=null;

v_err_code number(10);

v_err_txt varchar2(400);

begin

select max(d.table_name)

into var

from dba_tables d

where d.OWNER='JF'

and d.TABLE_NAME='ORGCONNECTION1012'||id;

if var is not null

then

insert into test values(id);

commit;

end if;

exception

when others then

v_err_code:=sqlcode;

v_err_txt:='测试:'||sqlerrm||DBMS_UTILITY.format_error_backtrace();

insert into proc_err_logs(code,message,info,occur_date)

values(v_err_code,v_err_txt,'EXCEPTION',SYSDATE);

commit;

end;

/

create or replace procedure proc_cur(id varchar2)

as

var dba_tables.table_name%type:=null;

v_err_code number(10);

v_err_txt varchar2(400);

type cursor_type is ref cursor;

cur cursor_type;

begin

open cur for

select d.table_name

from dba_tables d

where d.OWNER='JF'

and d.TABLE_NAME='ORGCONNECTION1012'||id;

fetch cur into var;

close cur;

if var is not null then

insert into test

values(id);

commit;

end if;

exception

when others then

v_err_code:=sqlcode;

v_err_txt:='测试:'||sqlerrm||DBMS_UTILITY.format_error_backtrace();

insert into proc_err_logs(code,message,info,occur_date)

values(v_err_code,v_err_txt,'EXCEPTION',SYSDATE);

commit;

end;

B、

create or replace procedure proc_test_max(var in number)

as

v_err_code number(10);

v_err_txt varchar2(400);

v_begin_time timestamp;

v_end_time timestamp;

begin

select current_timestamp into v_begin_time from dual;

for i in 1..var loop

proc_max(i);

end loop;

select current_timestamp into v_end_time from dual;

insert into proc_use_times(PROC_NAME,

PROC_DESC,

BEGIN_TIME,

END_TIME)

values('proc_test_max','测试'||var,v_begin_time,v_end_time);

commit;

exception

when others then

v_err_code:=sqlcode;

v_err_txt:='测试max:'||var||sqlerrm||DBMS_UTILITY.format_error_backtrace();

insert into proc_err_logs(code,message,info,occur_date)

values(v_err_code,v_err_txt,'EXCEPTION',SYSDATE);

end;

f68f2add0b68e4f9810432fce46917b7.png

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值