Help with dynamic PL/SQL using dbms_sql
Date: 1995/06/10
Message-ID: <D9xqI0.FvK_at_cuug.ab.ca>#1/1
Hello,
Is there anyone out there that has some experience with dynamic PL/SQL using the dbms_sql package? I just installed Oracle 7.1 and notice this quite powerful addition to PL/SQL.
So as a test, I'm trying to create a procedure that will create a user and then grant all the desired roles to that user.
CREATE PROCEDURE create_devel_user(username IN varchar2) IS
csr integer; dflt_ts varchar2(30); temp_ts varchar2(30); BEGIN select default_tablespace, temporary_tablespace into dflt_ts, temp_ts from user_users where username = user; csr := dbms_sql.open_cursor; dbms_sql.parse(csr,
'create user '||username||
' identified by '||username||
' default tablespace '||dflt_ts||
' temporary tablespace '||temp_ts||
' quota unlimited on '||dflt_ts ,dbms_sql.v7);
dbms_sql.parse(csr,
'grant developer TO '||username,dbms_sql.v7);
dbms_sql.close_cursor(csr); return;
END create_devel_user;
This procedure is created fine but when it is ran, I get the following error:
SQL> EXECUTE CREATE_DEVEL_USER('TEST_USER'); begin CREATE_DEVEL_USER('TEST_USER'); end;
*
ERROR at line 1:
ORA-01031: insufficient privileges ORA-06512: at "SYS.DBMS_SYS_SQL", line 239 ORA-06512: at "SYS.DBMS_SQL", line 25 ORA-06512: at "SYSTEM.CREATE_DEVEL_USER", line 11 ORA-06512: at line 1
The user that created the procedure and executed it has been granted the DBA role so there shouldn't be a problem with privileges. Can anyone see what I'm doing wrong?
PS: At first, I wanted to make this procedure a function
because I thought it would be great to be able to say:
SQL> select CREATE_DEVEL_USER('NEW_USER') from dual;
and have a new user created. However, when I created the function and did the above query, I kept getting the following Oracle error: ORA-6571 function is not guarenteed to not update the database.
Any thoughts or suggestions would be greatly appreciated.
Thanks in advance,
Tom
-- |\ +---------------------+ | ) ----------------- | Tommy Hui | The views expressed / / Energy | Programmer/Analyst | here are my own and ( ( Management |_____________________| in no way reflect \ \ Solutions Corp. | huih_at_cuug.ab.ca | the views of my | ) ----------------- +---------------------+ employer. |/Received on Sat Jun 10 1995 - 00:00:00 CEST