存储过程中调用EXECUTE IMMEDIATE的“权限不足”问题

使用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.

 

posted @ 2015-03-18 16:36  vv2013  阅读(2297)  评论(0编辑  收藏  举报