prompt
prompt 创建表eoda.t2 
declare 
    num number;
begin
    select count(1) into num from all_tables where table_name = upper( 't2' ) and owner = upper( 'eoda' );
    if num = 1 then
        execute immediate 'drop table eoda.t2';
    end if;
    execute immediate '
        create table eoda.t2 
        (
            cnt int 
        )
    ';
end;
/

prompt
prompt 插入数据到eoda.t2
declare 
    num number;
begin
    select count(1) into num from all_tables where table_name = upper( 't2' ) and owner = upper( 'eoda' );
    if num = 1 then
        insert into eoda.t2 values (0);
        commit;
    end if;
end;
/

prompt
prompt 创建表eoda.t
declare
    num number;
begin
    select count(1) into num from all_tables where table_name = upper( 't' ) and owner = upper( 'eoda' );
    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.t_trigger
declare
    num number;
begin
    select count(1) into num from user_triggers where trigger_name = upper( 't_trigger' ) and table_owner = upper( 'eoda' );
    if num = 1 then 
        execute immediate 'drop tigger eoda.t_trigger';
    end if;
    execute immediate '
        create trigger eoda.t_trigger
        before insert or delete on eoda.t for each row 
        begin
            if ( inserting ) then 
                update eoda.t2 set cnt = cnt + 1;
            else
                update eoda.t2 set cnt = cnt - 1;
            end if;
            dbms_output.put_line( ''I fired and updated'' || sql%rowcount || '' rows'' );
        end;
    ';
end;
/

prompt 
prompt 插入数据到eoda.t
declare 
    num number;
begin
    select count(1) into num from all_tables where table_name = upper ( 't' ) and owner = upper ( 'eoda' );
    if num = 1 then 
        insert into eoda.t values (1);
        commit;
    end if;
end;
/
