Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

getting ORA-00922 by PL/SQL block but didn't find the reason

3498001Oct 17 2018 — edited Oct 17 2018

Hi everybody,

for a script which should create a database user for monitoring database structures over Grafana I will create a script which I can use everytime when I rollout the user on a new server or I change the grants.

In case of that I'm trying to create a PL/SL block, which looks if the user is available or not. I user isn't there it should be created, if user is already there the password has to be changed so that all databases has the same login for the grafana database user. Actually I'm at this point:

declare

userexist integer;

begin

select count(*) into userexist from dba_users where username='GRAFANA';

if userexist = 0 then execute immediate 'CREATE USER GRAFANA IDENTIFIED BY "grafana" DEFAULT TABLESPACE USERS TEMPORARY TABLESPACE TEMP;';

else execute immediate 'ALTER USER GRAFANA IDENTIFIED BY "grafana";';

end if;

end;

/

But each time, when I execute my code I get this:

declare

userexist integer;

begin

select count(*) into userexist from dba_users where username='GRAFANA';

if userexist = 0 then execute immediate 'CREATE USER GRAFANA IDENTIFIED BY "grafana" DEFAULT TABLESPACE USERS TEMPORARY TABLESPACE TEMP;';

else execute immediate 'ALTER USER GRAFANA IDENTIFIED BY "grafana" ;';

end if;

end;

  9  /

declare

*

ERROR at line 1:

ORA-00922: missing or invalid option

ORA-06512: at line 6

But I didn't get why? I've read out the docu again and again but where is the problem with the "else" part? The error should be in the "else" part because when I comment the else part the block is working w.o. any problems...

So am I blind?

Thanks and regards,
David

This post has been answered by AndrewSayer on Oct 17 2018
Jump to Answer
Comments
Post Details
Added on Oct 17 2018
4 comments
1,031 views