<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Oracle Database Tips blog &#187; db link usage syntax</title>
	<atom:link href="http://oracle-database-tips.com/wp/tag/db-link-usage-syntax/feed" rel="self" type="application/rss+xml" />
	<link>http://oracle-database-tips.com/wp</link>
	<description>News for Oracle professionals</description>
	<lastBuildDate>Fri, 03 Feb 2012 10:37:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Use database links</title>
		<link>http://oracle-database-tips.com/wp/dblinks/use-database-links</link>
		<comments>http://oracle-database-tips.com/wp/dblinks/use-database-links#comments</comments>
		<pubDate>Fri, 23 Oct 2009 12:04:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[DB Links]]></category>
		<category><![CDATA[boise]]></category>
		<category><![CDATA[db link]]></category>
		<category><![CDATA[db link usage syntax]]></category>
		<category><![CDATA[dml statements]]></category>
		<category><![CDATA[dname]]></category>
		<category><![CDATA[duration]]></category>
		<category><![CDATA[loc]]></category>
		<category><![CDATA[lt]]></category>

		<guid isPermaLink="false">http://oracle-database-tips.com/wp/?p=113</guid>
		<description><![CDATA[Syntax to use an Oracle database link]]></description>
			<content:encoded><![CDATA[<p>Once a database link has been created<br />
you are now ready to select your data from the remote database referenced by   the db link.</p>
<p>The syntax is :</p>
<p>select &lt;column list&gt; from &lt;table&gt;@&lt;dblink name&gt;;</p>
<p>For example:<br />
<!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">SQL&gt; select * from dept@remotedb;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   -->The database link is opened during the select (or other DML transaction)        and remains open for the duration of the session.<br />
After you close a session, the links that were active in the session are        automatically closed.</p>
<h3><a id="Close" name="Close"></a>Close a db link</h3>
<p>To explicitly close the database link , use the command below:<br />
<!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">SQL&gt; alter session close database link remotedb;

Session altered.</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3>Using db links in other DML statements</h3>
<p>You can use insert/update/delete statements just as easily with database          links<br />
<!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">SQL&gt; select * from dept@remotedb;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON

SQL&gt; insert into dept@remotedb (deptno,dname,loc)
  2  values (50,'MARKETING','BOISE');

1 row created.

SQL&gt; commit;

Commit complete.

SQL&gt; select * from dept@remotedb;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON
        50 MARKETING      BOISE

SQL&gt; update dept@remotedb set loc = 'LONDON'
     where deptno = 50;

1 row updated.

SQL&gt; commit;

Commit complete.

SQL&gt; select * from dept@remotedb;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON
        50 MARKETING      LONDON

SQL&gt; delete from dept@remotedb
     where dname = 'MARKETING';

1 row deleted.

SQL&gt; commit;

Commit complete.

SQL&gt; select * from dept@remotedb;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   -->Note that DDL operations are not allowed through a database link:<br />
<!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">SQL&gt; alter table dept@remotedb
     add column (manager varchar2(30));

alter table dept@remotedb add column
(manager varchar2(30))
                 *
ERROR at line 1:
ORA-02021: DDL operations are not allowed
           on a remote database</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3>Recommended reading:</h3>
<div id="content">
<li><a title="opens new window" onclick="window.open('http://www.oracle-database-tips.com/cgi-bin/counter.pl?url=http%3A%2F%2Fdownload.oracle.com%2Fdocs%2Fcd%2FB19306_01%2Fserver.102%2Fb14231%2Fds_admin.htm%23i1007820&amp;referrer=http%3A%2F%2Fwww.oracle-database-tips.com%2Fuse_oracle_database_link.html'); return false;" href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14231/ds_admin.htm#i1007820" target="_blank">Oracle Online Documentation : Administrator&#8217;s Guide, Creating Database Links</a></li>
<li><a title="opens new window" onclick="window.open('http://www.oracle-database-tips.com/cgi-bin/counter.pl?url=http%3A%2F%2Fdownload.oracle.com%2Fdocs%2Fcd%2FB19306_01%2Fserver.102%2Fb14200%2Fstatements_5005.htm%23SQLRF01205&amp;referrer=http%3A%2F%2Fwww.oracle-database-tips.com%2Fuse_oracle_database_link.html'); return false;" href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_5005.htm#SQLRF01205" target="_blank">Oracle Online Documentation : SQL Reference, Create Datatabase Link syntax</a></li>
<li><a title="opens new window" onclick="window.open('http://www.oracle-database-tips.com/cgi-bin/counter.pl?url=http%3A%2F%2Fasktom.oracle.com%2Fpls%2Fasktom%2Ff%3Fp%3D100%3A11%3A0%3A%3A%3A%3AP11_QUESTION_ID%3A393468893370&amp;referrer=http%3A%2F%2Fwww.oracle-database-tips.com%2Fuse_oracle_database_link.html'); return false;" href="http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:393468893370" target="_blank">AskTom page with interesting troubleshooting tips for when you use oracle database links.</a></li>
</div>
]]></content:encoded>
			<wfw:commentRss>http://oracle-database-tips.com/wp/dblinks/use-database-links/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

