Oracle DB links

Source: Internet
Author: User

We know that different schemas on the same database server can search for a table or other objects, as long as the permissions are granted to the corresponding schema. But how can we read data between different database servers?

This requires dB link. There are two ways to create dB link.

1. Local services have been configured:

1. Create a database link like creating other database objects.

Create database link linknametest
Connect to userarwen identified by pswarwenusing 'tnsnamearwen ';

 

Meanings of parameters:

Linknametest: name of the DB link, which is the same as the name of the database table.

Userarwen: username of the database to be connected

Pswarwen: password of the database to be connected.

'Tnsnamearwen': there is a local file named tnsnames. ora. The content in the configured TNS name. tnsnames. ora is as follows:

Tnsnamearwen =
(Description =
(Address = (Protocol = TCP) (host = 10.30.40.50) (Port = 1521 ))
(CONNECT_DATA =
(Server = dedicated)
(SERVICE_NAME = Arwen)
)
)

Note: The host in it can only use an IP address, but cannot use a machine name. It will not be a problem to connect to the database in other cases, but I don't know why there is a problem in dB link.

2. Use it after creation:

For example, you need to find the table EMP in the connected database. (Note: if the table has a long field such as blob, an error is returned when you use dB link for query. I don't know why)

Select * from EMP @ linknametest where empno = 7788;

The usage is similar to that of common queries. You only need to add the database connection name after the table name.

The same applies to other objects, such as views, functions, and stored procedures. You only need to add a @ suffix.

 

2. The local service is not configured.

In fact, just like the first method, you can replace the TNS name after using with the content in the tnsnames. ora file.

Create database link linknametest
Connect to userarwen identified by pswarwenusing

'(Description =
(Address = (Protocol = TCP) (host = 10.30.40.50) (Port = 1521 ))
(CONNECT_DATA =
(Server = dedicated)
(SERVICE_NAME = Arwen)
)
)';

 

Supplement: No matter which connection method, if you want to create a global link dB, all the schemas created can be used.

You must use the system or sys user to log in. Then create the DB link as above. You only need to add public before the database.

Example: Create public database link linknametestconnect touserarwen
Identified by pswarwen
Using 'tnsnamearwen ';

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.