--create table error_logging(ecode varchar2(20), e_msg varchar2(200));
---implicit Cursor example with goto
--www.dba-oracle.com/t_autonomous_transaction.htm
set serveroutput on;
declare
ename varchar2(30);
emp_details emp%rowtype;
ecode varchar2(20);
e_msg varchar2(100);
begin
select a.ename into ename from emp a where empno=38722;
--select a.* into emp_details from emp a where empno=38737;
dbms_output.put_line(emp_details.ename||' '||emp_details.empno);
if SQL%found
then
--dbms_output.put_line('The values :'||emp_details.ename);
dbms_output.put_line('The values :'||ename);
insert into emp
select a.* from emp a where empno=3872;
else goto this;
<<this>>
dbms_output.put_line('The values is null');
--NULL; --use NULL if there are no executable statement
end if;
exception
when too_many_rows
then
dbms_output.put_line('Multiple records returned in output');
when no_data_found
then
dbms_output.put_line('No records exists in table for given value');
dbms_output.put_line(SQLCODE||' :'||SQLERRM);
PRAGMA AUTONOMOUS_TRANSACTION;
ecode:=SQLCODE;
e_msg:=SQLERRM;
begin
insert into error_logging values(ecode||'qwqwqwqewqqeqqeqeqeeeqeqeeeeeee',e_msg); --Extra string added to test exception with in exception condition
exception
when others
then
--null;
dbms_output.put_line(SQLCODE||SQLERRM);
end;
commit;
/*when others
then
dbms_output.put_line(SQLCODE||SQLERRM);
PRAGMA AUTONOMOUS_TRANSACTION;
ecode:=SQLCODE;
e_msg:=SQLERRM;
insert into error_logging values(ecode,e_msg);
commit;*/
end;
/
No comments:
Post a Comment