| Create User using stored procedure [message #550330] |
Sun, 08 April 2012 14:19  |
 |
aubyn19ja
Messages: 42 Registered: January 2012
|
Member |
|
|
I'm trying to create a store procedure that will accept a username from a flat file but i don't know how to do read file into store procedure. Can someone help please?
Below is a sample store procedure by itself i created to add user which created okay but when i execute I got the error displayed below. Can I also get some help in fixing this too please?
create or replace procedure addUsers(userNam in varchar2)
is
begin
EXECUTE IMMEDIATE 'CREATE USER'||userNam||'IDENTIFIED BY "pass1234" DEFAULT TABLESPACE USERS'||'QUOTA "1M" ON USERS'||
'PASSWORD EXPIRE';
end addUsers;
/
SQL> create or replace procedure addUsers(userNam in varchar2)
2 is
3 begin
4
5 EXECUTE IMMEDIATE 'CREATE USER'||userNam||'IDENTIFIED BY "pass1234" DEFAULT
TABLESPACE USERS'||'QUOTA "1M" ON USERS'||
6 'PASSWORD EXPIRE';
7
8 end addUsers;
9 /
Procedure created.
SQL> execute addUsers test;
BEGIN addUsers test; END;
*
ERROR at line 1:
ORA-06550: line 1, column 16:
PLS-00103: Encountered the symbol "TEST" when expecting one of the following:
:= . ( @ % ;
The symbol ":=" was substituted for "TEST" to continue.
|
|
|
|
|
|
|
|
| Re: Create User using stored procedure [message #550334 is a reply to message #550332] |
Sun, 08 April 2012 14:55   |
 |
aubyn19ja
Messages: 42 Registered: January 2012
|
Member |
|
|
Thanks for all the guidlelines Michel and Ved...I'm a beginner at Oracle.
CREATE OR REPLACE PROCEDURE addUsers(userNam in varchar2)
IS
BEGIN
EXECUTE IMMEDIATE 'CREATE USER'||userNam||'IDENTIFIED BY "pass1234" DEFAULT TABLESPACE USERS'||'QUOTA "1M" ON USERS'||
'PASSWORD EXPIRE';
END addUsers;
/
Is this how it is to be done? What do you mean by some spaces are missing Michel?
[mod-edit: ending code tag fixed by bb]
[Updated on: Mon, 09 April 2012 01:02] by Moderator Report message to a moderator
|
|
|
|
|
|
| Re: Create User using stored procedure [message #550340 is a reply to message #550334] |
Sun, 08 April 2012 16:09   |
 |
Barbara Boehmer
Messages: 9106 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
aubyn19ja wrote on Sun, 08 April 2012 12:55
...What do you mean by some spaces are missing..?
A standard method for debugging dynamic SQL is to store the string to be executed dynamically to a variable, then output it using dbms_output to see what it looks like. You can also take that output and copy and paste it and try to run it from SQL*Plus to see what error it raises. Please see the example below that modifies your code to do that, making it easy to see where the missing spaces are.
SCOTT@orcl_11gR2> CREATE OR REPLACE PROCEDURE addUsers(userNam in varchar2)
2 IS
3 v_sql VARCHAR2 (32767);
4 BEGIN
5 v_sql :=
6 'CREATE USER'||userNam||'IDENTIFIED BY "pass1234" DEFAULT TABLESPACE USERS'
7 ||'QUOTA "1M" ON USERS'||'PASSWORD EXPIRE';
8 DBMS_OUTPUT.PUT_LINE (v_sql);
9 EXECUTE IMMEDIATE v_sql;
10 END addUsers;
11 /
Procedure created.
SCOTT@orcl_11gR2> SHOW ERRORS
No errors.
SCOTT@orcl_11gR2> EXEC addusers ('test')
CREATE USERtestIDENTIFIED BY "pass1234" DEFAULT TABLESPACE USERSQUOTA "1M" ON
USERSPASSWORD EXPIRE
BEGIN addusers ('test'); END;
*
ERROR at line 1:
ORA-00901: invalid CREATE command
ORA-06512: at "SCOTT.ADDUSERS", line 9
ORA-06512: at line 1
SCOTT@orcl_11gR2>
Do you see that there are spaces missing in the following?
CREATE USERtestIDENTIFIED BY "pass1234" DEFAULT TABLESPACE USERSQUOTA "1M" ON
USERSPASSWORD EXPIRE
[Updated on: Sun, 08 April 2012 16:40] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|