
prompt 
prompt 创建临时表eoda.temp_table_session
declare 
    num number;
begin 
    select count(1) into num from user_tables where table_name =upper( 'temp_table_session') and TEMPORARY = 'Y';
    if num = 1 then 
        execute immediate 'drop table eoda.temp_table_session';
    end if;
    execute immediate '
        create global temporary table eoda.temp_table_session
        on commit preserve rows 
        as 
        select * from scott.emp where 1=0
    ';
end;
/

prompt 
prompt 创建临时表eoda.temp_table_transaction
declare 
    num number;
begin 
    select count(1) into num from user_tables where table_name = upper( 'temp_table_transaction' ) and TEMPORARY = 'Y';
    if num = 1 then 
        execute immediate 'drop table eoda.temp_table_transaction';
    end if;
    execute immediate '
        create global temporary table temp_table_transaction
        on commit delete rows 
        as 
        select * from scott.emp where 1=0
    ';
end;
/

prompt
prompt 插入数据到eoda.temp_table_session、eoda.temp_table_transaction
declare 
    session_cnt number;
    transaction_cnt number;
begin
    execute immediate 'truncate table eoda.temp_table_session';
    execute immediate 'truncate table eoda.temp_table_transaction';
    insert into eoda.temp_table_session select * from scott.emp;
    insert into eoda.temp_table_transaction select * from scott.emp;
    select session_cnt,transaction_cnt into  session_cnt,transaction_cnt 
      from ( select count(*) session_cnt from eoda.temp_table_session ),
           ( select count(*) transaction_cnt from eoda.temp_table_transaction );
    dbms_output.put_line( 'session_cnt = ' || to_char( session_cnt ) || ',transaction_cnt = ' || to_char( transaction_cnt ));
    commit;
    select session_cnt,transaction_cnt into  session_cnt,transaction_cnt 
      from ( select count(*) session_cnt from eoda.temp_table_session ),
           ( select count(*) transaction_cnt from eoda.temp_table_transaction );
    dbms_output.put_line( 'session_cnt = ' || to_char( session_cnt ) || ',transaction_cnt = ' || to_char( transaction_cnt ));
end;
/

connect eoda/foo

prompt 
prompt 重新连接、查看临时表中的数据
declare 
    session_cnt number;
    transaction_cnt number;
begin
    select session_cnt,transaction_cnt into  session_cnt,transaction_cnt 
      from ( select count(*) session_cnt from eoda.temp_table_session ),
           ( select count(*) transaction_cnt from eoda.temp_table_transaction );
    dbms_output.put_line( 'session_cnt = ' || to_char( session_cnt ) || ',transaction_cnt = ' || to_char( transaction_cnt ));
end;
/
