Oracle 12c. Accessing tables in PDB from CDB or another PDB.
If you are reading this, you should know that Oracle 12c introduced the new big feature – Pluggable Data Bases. Finally Oracle has made the thing that was available in other RDBMSs for years – now you can have multiple databases run by one instance. This is available from very beginning in RDBMSs such as Sybase, DB2, MSSQL, MySQL… you name it.
In these RDBMSs a user being currently in one database can access tables in another database. For example, in MSSQL you can be in DB01 and select data from DB02 (given that you have permissions):
use DB01
select * from DB02.dbo.ATABLE
It is not that simple in Oracle 12c! You cannot specify PDB before schema. You have to switch or to connect to a PDB to access data in that.
ALTER SESSION SET CONTAINER=PDB02;
select * from ASCHEMA.ATABLE;
Or
CONNECT ASCHEMA@PDB02
select * from ATABLE;
But what if you need to select data from a PDB while you are in CDB or in another PDB?
Oracle documentation states: “The common user cannot query tables or views in a PDB.” 1
“Wait a second! How to query/join data from different PDBs for reports or comparisons?” you may ask.
Relax, it is still possible. The answer is – DATABASE LINK.
To make it possible you should first modify tnsnames.ora file on database server, in Oracle Home of the instance.
Add there TNS entries for PDBs you would like to access.
pdb01 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pdb01)
)
)
Second, create DB link.
connect system/password
create public database link PDB01 using 'PDB01';
select * from ASCHEMA.ATABLE@PDB01;
Done!
In this case the DB link was created in CDB, so common users can access data in PDB01.
If you need to allow a local user to access another PDB you should create DB link in the PDB of the local user.
You can play with public or user’s DB links to build security you need, main idea is to access PDBs via DB links.
References:
1. Oracle® Database Administrator's Guide 12c Release 1 (12.1) , Chapter 40 Administering a CDB with SQL*Plus http://docs.oracle.com/cd/E16655_01/server.121/e17636/cdb_admin.htm#ADMIN13616 )
In these RDBMSs a user being currently in one database can access tables in another database. For example, in MSSQL you can be in DB01 and select data from DB02 (given that you have permissions):
use DB01
select * from DB02.dbo.ATABLE
It is not that simple in Oracle 12c! You cannot specify PDB before schema. You have to switch or to connect to a PDB to access data in that.
ALTER SESSION SET CONTAINER=PDB02;
select * from ASCHEMA.ATABLE;
Or
CONNECT ASCHEMA@PDB02
select * from ATABLE;
But what if you need to select data from a PDB while you are in CDB or in another PDB?
Oracle documentation states: “The common user cannot query tables or views in a PDB.” 1
“Wait a second! How to query/join data from different PDBs for reports or comparisons?” you may ask.
Relax, it is still possible. The answer is – DATABASE LINK.
To make it possible you should first modify tnsnames.ora file on database server, in Oracle Home of the instance.
Add there TNS entries for PDBs you would like to access.
pdb01 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pdb01)
)
)
Second, create DB link.
connect system/password
create public database link PDB01 using 'PDB01';
select * from ASCHEMA.ATABLE@PDB01;
Done!
In this case the DB link was created in CDB, so common users can access data in PDB01.
If you need to allow a local user to access another PDB you should create DB link in the PDB of the local user.
You can play with public or user’s DB links to build security you need, main idea is to access PDBs via DB links.
References:
1. Oracle® Database Administrator's Guide 12c Release 1 (12.1) , Chapter 40 Administering a CDB with SQL*Plus http://docs.oracle.com/cd/E16655_01/server.121/e17636/cdb_admin.htm#ADMIN13616 )
17 Comments:
Really awesome blog!!! I finally found a great post here.I really enjoyed reading this article. It's really a nice experience to read your post. Thanks for sharing your innovative ideas. Excellent work! I will get back here.
Data Science Course
Data Science Course in Marathahalli
I finally found great post here.I will get back here. I just added your blog to my bookmark sites. thanks.Quality posts is the crucial to invite the visitors to visit the web page, that's what this web page is providing.
Data Science Course
I read this post two times, I like it so much, please try to keep posting & Let me introduce other material that may be good for our community.
I read this post two times, I like it so much, please try to keep posting & Let me introduce other material that may be good for our community. data science courses
Glad to chat your blog,I seem to be forward to more reliable articles and i think we all wish to thank so many good articles,blog to share with us.data scientist courses
Here is the site(bcomexamresult.in) where you get all Bcom Exam Results. This site helps to clear your all query.
CSJMU BCOM 3rd Year Result 2020
BA 3rd year Result 2019-20
Sdsuv University B.COM 3rd/HONOURS Sem Exam Result 2018-2021
Nice article and thanks for sharing with us. Its very informative
Machine Learning Training in Hyderabad
Thanks for sharing good content
php for right career growth
I wanted to thank you for this great read!! I definitely enjoy every little bit of it. I have you bookmarked to check out new stuff you post.
data scientist course in hyderabad
I would like to thank you for the efforts you have made in writing this article. I am hoping for the same best work from you in the future as well..
data scientist training and placement in hyderabad
Hi, their colleagues, nice paragraph and nice arguments commented here, I am really enjoying by these.
BCom 1st Year Admit Card 2022
BCom 2nd Year Admit Card 2022
BCom 3rd Year Admit Card 2022
Medfemme Fertility is the best Fertility Specialist, Infertility Specialist, High Risk Pregnancy Specialist in Delhi. For more information in details visit our website.
High Risk Pregnancy Specialist in Delhi
Visit Pawfolic for Pet Grooming Services, Best Dog Grooming Services in Delhi NCR, and Dog training Services in Delhi NCR. For more information visit our website.
Dog training Services in Delhi NCR
Amazing Blog. Visit AAR Fragrance for Perfumes for Men Online at Best Prices in India, Buy Perfumes for Women Online in India, Davidoff Cool Water For Men EDT 125ml, and Versace Pour Homme Dylan Blue EDT 100ml.
Perfumes for Men Online at Best Prices in India
Get the best deals on honda acura engines for sale, toyota transmission for sale and jdm lexus engines online at JDM of Washington. For more information in detail visit our website.
Honda Acura Engines for Sale
Visit Orange Pill Clinic for leading Nursing and Doctor Consultation Services at Home, Home Nursing Services in Delhi NCR, and Nursing Services for Suturing Removal at Home. For more information visit our website.
Nursing Services for Suturing Removal at Home
Nice information, thank you so much sharing with us. Visit Amfez for Thakur ji ke vastra, kanha ji poshak, and krishna dress at an affordable price.
krishna dress
Post a Comment
<< Home