问题
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