Is it possible to give PDB name to a procedure and select from it?
-
14-03-2021 - |
Pergunta
The following example is not working, I just trying to show what I'm trying to do.
Given table:
-- this table is located at the CDB
create table t1 (tab_name varchar2(35))
/
-- this proc is located at the CDB
Create or replace procedure FindTables(vPdb in varchar2, vOwner in varchar2)
BEGIN
insert into t1(tab_name) select TABLE_NAME from ALL_TABLES@vPdb where OWNER=vOwner;
END;
/
Is there a way to create a temporary DB link or something like that? or any other way?
EDIT
I need also a solution for user tables.
Solução
Sorry, but this is just wrong. A dblink can not be provided as a parameter like that. And a dblink is not required at all for this.
You can access information about all tables in all PDBs using the CDB_TABLES
view.
For every DBA_* view, a CDB_* view is defined. In the root of a multitenant container database (CDB), CDB_* views can be used to obtain information about tables, tablespaces, users, privileges, parameters, and so on contained in the root and in pluggable databases (PDBs).
SQL> show con_name;
CON_NAME
------------------------------
CDB$ROOT
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB1 READ WRITE NO
4 PDB2 READ WRITE NO
SQL> select table_name from cdb_tables t join v$containers c on t.con_id = c.con_id
where c.name = 'PDB1' and t.owner = 'BP';
no rows selected
SQL> select table_name from cdb_tables t join v$containers c on t.con_id = c.con_id
where c.name = 'PDB2' and t.owner = 'BP';
TABLE_NAME
--------------------------------------------------------------------------------
T1
SQL>
You can easily provide the PDB name and table owner as parameters to a query like above.