Forum Stats

  • 3,855,178 Users
  • 2,264,465 Discussions
  • 7,905,912 Comments

Discussions

ORA-01031: insufficient privileges when looping through all PDBs as SYSDBA

TheLonelyDBA
TheLonelyDBA Member Posts: 153 Blue Ribbon
edited Apr 9, 2019 5:01AM in Multitenant

Hi,

I have this short PLSQL code to loop through all PDBs:

set serveroutput on

declare

cursor rec

is

select name, open_mode

        from v$pdbs

        where name not in ('PDB$SEED');

begin

for x in rec

loop

execute immediate 'alter session set container= "' || x.name || '"';

DBMS_OUTPUT.put_line(x.name);

end loop;

end;

/  2    3    4    5    6    7    8    9   10   11   12   13   14   15

declare

*

ERROR at line 1:

ORA-01031: insufficient privileges

ORA-06512: at line 11

ORA-06512: at line 11

I run this as SYSDBA. After the script terminates I have changed PDB to the first one. Is there a way to loop through PDBs and do the same stuff in all of them?

Regards

TheLonelyDBA

Best Answer

Answers