PL / SQL全局临时表没有返回记录

时间:2012-07-04 14:54:15

标签: oracle plsql

在Oracle PL / SQL中,我有这段代码来学习全局临时表。我将临时表定义为此

CREATE GLOBAL TEMPORARY TABLE "TEST"."WORKTABLE"
         ( "VAL" VARCHAR2(2000 BYTE) ) 
      ON COMMIT PRESERVE ROWS ;

当我选择它时,它没有显示任何记录。

请帮忙。

declare
    r_countries countries%rowtype;
    v_country_id countries.country_id%type;
begin
     ----------- clean temp table ---------
    execute immediate 'truncate table worktable';

    select * into r_countries from countries r where r.country_id = 'AU';

    select country_id into v_country_id from countries where country_id = 'AU';

    insert into worktable
    select country_id from countries where country_id = 'AU';

    --dbms_output.put_line(r_countries.country_id);

    --dump_table('worktable');

     execute immediate 'select * from worktable'; -- no return

    ----------- clean temp table ---------
    execute immediate 'truncate table worktable';    
end;
/

1 个答案:

答案 0 :(得分:1)

我认为问题不在临时表中,而在脚本中 试试这样:

declare
    r_countries countries%rowtype;
    v_country_id countries.country_id%type;

    r_worktable worktable%ROWTYPE;
begin
     ----------- clean temp table ---------
    execute immediate 'truncate table worktable';

    select * into r_countries from countries r where r.country_id = 'AU';

    select country_id into v_country_id from countries where country_id = 'AU';

    insert into worktable
    select country_id from countries where country_id = 'AU';

    --dbms_output.put_line(r_countries.country_id);

    --dump_table('worktable');

     select * INTO r_worktable from worktable; 

     dbms_output.put_line(r_worktable.VAL);

    ----------- clean temp table ---------
    execute immediate 'truncate table worktable';    
end;
/

详细了解SELECT INTO here