Getting error due to variable When i execute stored procedure which dynamic PLSQL inside was there in the stored procedure [duplicate]

孤街醉人 提交于 2019-12-18 05:24:05

问题


When i execute stored procedure which contain EXECUTE IMMEDIATE along with create table statement inside the stored procedure then getting error while execute this Stored Proc. Here is the Stored proc-

create or replace sp_exec
 as
 .......
 v_mth date;
 .......
begin
 select TO_DATE('01-' || to_char(add_months(sysdate, -1), 'MON-YY'), 'DD-MON-YY')
  INTO v_mth FROM dual;
  execute immediate 'create table tbl_mon_ '||v_mth||' as select ............... from '|| v_mth ||' ..... ';
end;

When I try to execute this Stored proc then getting error "Insufficient Privilege" at 2nd last line using this code to execute Stored Proc.

 begin
  sp_exec;
 end;

then getting error which mentioned below:-

 ORA-01031: Insufficient privilege
 ORA-06512: at sp_exec line 11  --here line 11 mention for Execute immediate
 ORA-06512: at line 2         -- here mention for sp_exec in the PLSQL block

I am working in the user schema itself so I've all types of privileges even CREATE TABLE statement also. When i run outside the stored procedure (PL/SQL block) then dynamic table have been created.

来源:https://stackoverflow.com/questions/57070212/getting-error-due-to-variable-when-i-execute-stored-procedure-which-dynamic-plsq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!