{"id":5451,"date":"2021-06-15T08:47:25","date_gmt":"2021-06-15T08:47:25","guid":{"rendered":"https:\/\/swiv.com.br\/querying-data-owned-by-local-users-across-all-pdbs\/"},"modified":"2026-05-27T20:02:31","modified_gmt":"2026-05-27T19:02:31","slug":"querying-data-owned-by-local-users-across-all-pdbs","status":"publish","type":"post","link":"https:\/\/swiv.com.br\/index.php\/2021\/06\/15\/querying-data-owned-by-local-users-across-all-pdbs\/","title":{"rendered":"Querying data owned by Local users Across All PDBs"},"content":{"rendered":"\n<p>Temos um recurso nativo na arquitetura Multitenant de podermos consultar os dados de tabelas\/views de common users de m\u00faltiplos PDBs ao mesmo tempo. Por\u00e9m, qual seria a nossa op\u00e7\u00e3o caso esses objetos tivessem como owner Local Users, em vez de Common Users? Este artigo tentar\u00e1 explorar uma alternativa para esta situa\u00e7\u00e3o.<\/p>\n\n\n\n<p>Validando PDBs existentes em meu laborat\u00f3rio:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&#x5B;oracle@quiasma ~]$ sqlplus \/ as sysdba\n \nSQL*Plus: Release 18.0.0.0.0 - Production on Tue Jun 15 05:31:12 2021\nVersion 18.13.0.0.0\n \nCopyright (c) 1982, 2018, Oracle.  All rights reserved.\n \n \nConnected to:\nOracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production\nVersion 18.13.0.0.0\n \nSQL&gt; SELECT NAME,OPEN_MODE,CDB FROM V$DATABASE;\n \nNAME      OPEN_MODE            CDB\n--------- -------------------- ---\nASWAN     READ WRITE           YES\n \nSQL&gt; SHOW PDBS;\n \n    CON_ID CON_NAME                       OPEN MODE  RESTRICTED\n---------- ------------------------------ ---------- ----------\n         2 PDB$SEED                       READ ONLY  NO\n         3 HIPOFISE2                      READ WRITE NO\n         4 HIPOFISE1                      READ WRITE NO\n<\/pre><\/div>\n\n\n<p>Validando Local User chamado BSS1, no PDB HIPOFISE1, e a tabela que usaremos como refer\u00eancia de teste:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; ALTER SESSION SET CONTAINER=HIPOFISE1;\n \nSession altered.\n \nSQL&gt; SELECT USERNAME,COMMON FROM DBA_USERS WHERE USERNAME=&#039;BSS1&#039;;\n \nUSERNAME\n--------------------------------------------------------------------------------\nCOM\n---\nBSS1\nNO\n \n \nSQL&gt; DESC BSS1.TESTE1;\n Name                                      Null?    Type\n ----------------------------------------- -------- ----------------------------\n DESCRICAO                                          VARCHAR2(20)\n \nSQL&gt; SELECT * FROM BSS1.TESTE1;\n \nDESCRICAO\n--------------------\nPDB HIPOFISE1\n<\/pre><\/div>\n\n\n<p> Validando Local User chamado BSS, no PDB HIPOFISE2, e a tabela que usaremos como refer\u00eancia de teste: <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; ALTER SESSION SET CONTAINER=HIPOFISE2;\n \nSession altered.\n \nSQL&gt; SELECT USERNAME,COMMON FROM DBA_USERS WHERE USERNAME=&#039;BSS&#039;;\n \nUSERNAME\n--------------------------------------------------------------------------------\nCOM\n---\nBSS\nNO\n \n \nSQL&gt; DESC BSS.TESTE;\n Name                                      Null?    Type\n ----------------------------------------- -------- ----------------------------\n DESCRICAO                                          VARCHAR2(20)\n \nSQL&gt; SELECT * FROM BSS.TESTE;\n \nDESCRICAO\n--------------------\nPDB HIPOFISE2\n<\/pre><\/div>\n\n\n<p>Uma alternativa para este cen\u00e1rio seria: conectarmos em cada PDB com um Common User, e criarmos uma view consultando as tabelas referidas. Vamos realizar essa etapa no primeiro PDB:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; conn C##LUXOR\/oracle\nConnected.\nSQL&gt; ALTER SESSION SET CONTAINER=HIPOFISE1;\n \nSession altered.\n \nSQL&gt; CREATE VIEW C##LUXOR.VIEW_DO_BRUNO AS SELECT * FROM BSS1.TESTE1;\n \nView created.\n \nSQL&gt; SELECT * FROM C##LUXOR.VIEW_DO_BRUNO;\n \nDESCRICAO\n--------------------\nPDB HIPOFISE1\n<\/pre><\/div>\n\n\n<p>Criando View no segundo PDB:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; conn C##LUXOR\/oracle\nConnected.\nSQL&gt; ALTER SESSION SET CONTAINER=HIPOFISE2;\n \nSession altered.\n \nSQL&gt; CREATE VIEW C##LUXOR.VIEW_DO_BRUNO AS SELECT * FROM BSS.TESTE;\n \nView created.\n \nSQL&gt; SELECT * FROM C##LUXOR.VIEW_DO_BRUNO;\n \nDESCRICAO\n--------------------\nPDB HIPOFISE2\n<\/pre><\/div>\n\n\n<p>Agora podemos uma tabela no CDB$ROOT com a mesma estrutura das views:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; conn C##LUXOR\/oracle\nConnected.\nSQL&gt; CREATE TABLE C##LUXOR.VIEW_DO_BRUNO (DESCRICAO VARCHAR2(20));\n \nTable created.\n<\/pre><\/div>\n\n\n<p>Realizando consulta em todos os PDBs a partir do CDB$ROOT:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; SELECT * FROM CONTAINERS(VIEW_DO_BRUNO);\n \nDESCRICAO                CON_ID\n-------------------- ----------\nPDB HIPOFISE2                 3\nPDB HIPOFISE1                 4\n<\/pre><\/div>\n\n\n<p>Obs: Este procedimento foi criado pelo senhor Ahmed Baraka (www.ahmedbaraka.com) e foi apenas reproduzido por mim em um laborat\u00f3rio pessoal para fins de aprendizado.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Temos um recurso nativo na arquitetura Multitenant de podermos consultar os dados de tabelas\/views de common users de m\u00faltiplos PDBs ao mesmo tempo. Por\u00e9m, qual seria a nossa op\u00e7\u00e3o caso esses objetos tivessem como owner Local Users, em vez de Common Users? Este artigo tentar\u00e1 explorar uma alternativa para esta situa\u00e7\u00e3o. Validando PDBs existentes em [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-5451","post","type-post","status-publish","format-standard","hentry","category-multitenant"],"_links":{"self":[{"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/posts\/5451","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/comments?post=5451"}],"version-history":[{"count":1,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/posts\/5451\/revisions"}],"predecessor-version":[{"id":9102,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/posts\/5451\/revisions\/9102"}],"wp:attachment":[{"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/media?parent=5451"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/categories?post=5451"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/tags?post=5451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}