ストレージ中にEXECUTE IMMEDIATEを呼び出す「権限不足」の問題

2051 ワード

plsqlを使用してテーブルを動的に作成する場合、ユーザーはcreate any table権限を持つ必要があります.
例:
create or replace procedure create_table_test is

tmpstr varchar2(500);

v_cursor number;

j number;

begin

  for i in 10..120 loop

  begin

  tmpstr:= 'create table DPC_TEST'|| i ||' as select * from DPC_TEST WHERE 1=2';

  dbms_output.put_line(tmpstr);

  --v_cursor := dbms_sql.open_cursor;

  --dbms_sql.parse(v_cursor,tmpstr,dbms_sql.native);

  --j:=dbms_sql.execute(v_cursor);

  execute immediate tmpstr;

  exception

  when others then

  dbms_output.put_line('error create table!');

      DBMS_OUTPUT.put_line('sqlcode : ' ||sqlcode); 

      DBMS_OUTPUT.put_line('sqlerrm : ' ||sqlerrm); 

  end;

  end loop;

end create_table_test;

コマンドラインでexec createを実行します.table_testの場合、権限不足のエラーに遭遇します!sysユーザーを使用してログイン後、grant create any table to USERを実行する必要がある.