-2

在 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;
/
4

1 回答 1

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 这里

于 2012-07-04T15:19:58.137 回答