1

@?/rdbms/admin/utlrp.sql How to create procedure code to run the utlrp.sql in each pluggable database of oracle. I have created the below one but it has failed. please advise. I have created the below one but it has failed. it should run in all PDB and exit once done. please advise.

DECLARE
   v_pdb_name VARCHAR2(30);
   v_pdb_status VARCHAR2(30);
   v_sql      VARCHAR2(200);
BEGIN
   -- Loop through all PDBs in the container database (CDB)
   FOR c IN (select Name , OPEN_MODE from v$pdbs where OPEN_MODE='READ WRITE';) LOOP
      v_pdb_name := c.Name;
      v_pdb_status := c.OPEN_MODE;
      
      -- Check if the PDB is in READ WRITE mode
      IF v_pdb_status = 'READ WRITE' THEN
         -- Generate and execute the script for each READ WRITE PDB
         v_sql := 'ALTER SESSION SET CONTAINER=' || v_pdb_name;
         EXECUTE IMMEDIATE v_sql;
         
         -- Run utlrp.sql script in the current PDB
         @?/rdbms/admin/utlrp.sql;

         -- Switch back to the CDB root container
         EXECUTE IMMEDIATE 'ALTER SESSION SET CONTAINER=CDB$ROOT';
      ELSE
         DBMS_OUTPUT.PUT_LINE('Skipped PDB ' || v_pdb_name || ' (Status: ' || v_pdb_status || ')');
      END IF;
   END LOOP;
END;
/
Jon Heller
  • 34,999
  • 6
  • 74
  • 132
Learner
  • 13
  • 4
  • Does it have to be done in an Oracle PL/SQL procedure? If a shell script is acceptable, there's a good solution using [catcon.pl](https://oracle-base.com/articles/12c/multitenant-running-scripts-cdb-and-pdb-12cr1#catcon-pl). – Jon Heller Aug 23 '23 at 04:56
  • Actually, as per requirement I need to prepare PL/SQL procedure only. – Learner Aug 24 '23 at 09:26
  • Seems no-one is aware of this. I have asked very much tricky and hard question? :) – Learner Aug 28 '23 at 10:25
  • Running the script precisely as you want may be difficult or impossible. The documentation in the scripts warns, "Rem \* This script must be run using SQL\*PLUS. Rem \* You must be connected AS SYSDBA to run this script. Rem \* There should be no other DDL on the database while running the Rem script. Not following this recommendation may lead to deadlocks." Does the requirement *really* need this exact script to run as a procedure? Or does it just want a procedure to compile all invalid objects? The later option can be done. – Jon Heller Aug 28 '23 at 23:54

0 Answers0