Stored procedure

Database
Enthusiast

Stored procedure

Hi All,

Need to create a user using stored procedure. I am using the below code and getting an error

CREATE PROCEDURE abc.MyFirstProc(

   IN user_name VARCHAR(12),

    IN owner1 VARCHAR(12),

    IN password1 VARCHAR(12))

    BEGIN

        CREATE USER user_name FROM owner1 AS PERMANENT = 0 PASSWORD = password1

END;

Any help pls

Thanks,

Praveen.

1 REPLY
Enthusiast

Re: Stored procedure

Did you try with these within your proc begin and end(Please double check the syntax and space)?

CALL DBC.SysExecSQL('CREATE USER '||user_name|| ' FROM '|| owner1 || ' AS PERMANENT = 0 PASSWORD = '||password1);

 

or EXECUTE IMMEDIATE example

 

DECLARE sqlstr VARCHAR(300);

SET sqlstring  like .... 'CREATE USER '||user_name|| ' FROM '|| owner1 || ' AS PERMANENT = 0 PASSWORD = '||password1 ;

EXECUTE IMMEDIATE sqlstring;