I cannot run a procedure within a package with a user that also defined it unless I specify "authid current_user" for some reason. Here is my original code that produces insufficient privileges error
create or replace package hr.table_pkg
is
procedure make ( p_table_name varchar2, p_col_specs varchar2);
end table_pkg;
create or replace package body hr.table_pkg is
procedure make ( p_table_name varchar2, p_col_specs varchar2) is
sql_stmt varchar2(32767);
begin
sql_stmt := 'Create table '|| p_table_name||' ('||p_col_specs||')';
dbms_output.put_line(sql_stmt);
execute immediate sql_stmt ;
end make ;
end table_pkg;
/
So the user that defines the package is HR. when I query view USER_OBJECTS I can see the package and the body aswell
but when I, as the HR user try to run
execute table_pkg.make('my_contacts','id number(4), name varchar2(40)');
I'm gonna get an error that I cannot create the table. It also does not work when I change the procedure in the body to create the table in a specific schema HR:
sql_stmt := 'Create table hr.'|| p_table_name||' ('||p_col_specs||')';
the call to the procedure only works when I recompile the header of the package to
create or replace package hr.table_pkg
authid current_user
is
Can please anyone explain to me what am I missing, I do not get why the definer ( HR user) cannot run the procedure with definer rights
Thanks a lot!