prompt
prompt 创建表eoda.error_log 
declare 
    num number;
begin
    select count(1) into num from user_tables where table_name = upper( 'error_log' );
    if num = 1 then 
        execute immediate 'drop table eoda.error_log';
    end if;
    execute immediate '
        create table eoda.error_log
        (
            ts     timestamp,
            err1   clob,
            err2   clob
        )
    ';
end;
/

prompt
prompt 创建存储过程eoda.log_error
create or replace procedure eoda.log_error
(
    p_err1   in   varchar2 ,
    p_err2   in   varchar2
)
as 
    pragma   autonomous_transaction;
begin
    insert into eoda.error_log ( ts,err1,err2 )values ( systimestamp,p_err1,p_err2 );
    commit;
end;
/

prompt
prompt 创建表eoda.t
declare 
    num number;
begin
    select count(1) into num from user_tables where table_name = upper ( 't' );
    if num = 1 then
        execute immediate 'drop table eoda.t';
    end if;
    execute immediate '
        create table eoda.t ( x int check( x>0 ) )
    ';
end;
/

prompt
prompt 创建存储过程eoda.p1
create or replace procedure eoda.p1 ( p_n in number )
as 
begin
    -- some code here 
    insert into eoda.t values ( p_n );
end;
/

prompt
prompt 创建存储过程eoda.p2
create or replace procedure eoda.p2 ( p_n in number )
as 
begin
    -- code 
    -- code 
    eoda.p1( p_n );
end;
/

prompt
prompt 执行eoda.p1和eoda.p2
begin
    eoda.p2 (1);
    eoda.p2 (2);
    eoda.p2 (-1);
    rollback;
exception 
    when others then 
        eoda.log_error( sqlerrm,dbms_utility.format_error_backtrace );
        RAISE;
        --  使用RAISE会报错，故意为之
end;
/

select * from eoda.error_log;
