-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 に答える