Edit D:\app\Administrator\product\11.2.0\dbhome_1\oc4j\j2ee\oc4j_applications\applications\em\em\online_help\tdpii\tdpii_distdbs007.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=us-ascii" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <title>Tutorial: Querying Multiple Oracle Databases</title> <meta name="generator" content="Oracle DARB XHTML Converter (Mode = ohj/ohw) - Version 5.1.1 Build 005" /> <meta name="date" content="2009-06-04T17:1:1Z" /> <meta name="robots" content="noarchive" /> <meta name="doctitle" content="Tutorial: Querying Multiple Oracle Databases" /> <meta name="relnum" content="11g Release 2 (11.2)" /> <meta name="partnum" content="E10703-01" /> <link rel="copyright" href="./dcommon/html/cpyr.htm" title="Copyright" type="text/html" /> <link rel="stylesheet" href="./dcommon/css/blafdoc.css" title="Oracle BLAFDoc" type="text/css" /> <link rel="contents" href="toc.htm" title="Contents" type="text/html" /> <link rel="prev" href="tdpii_distdbs006.htm" title="Previous" type="text/html" /> <link rel="next" href="tdpii_distdbs008.htm" title="Next" type="text/html" /> <script src="./callback.js" type="text/javascript"></script> <noscript>Your browser does not support JavaScript. This help page requires JavaScript to render correctly.</noscript> </head> <body> <div class="zz-skip-header"><a href="#BEGIN">Skip Headers</a></div> <table class="simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100%"> <col width="86%" /> <col width="*" /> <tr valign="bottom"> <td align="left"></td> <td align="center"><a href="tdpii_distdbs006.htm"><img src="./dcommon/gifs/leftnav.gif" alt="Previous" /><br /> <span class="icon">Previous</span></a> </td> <td align="center"><a href="tdpii_distdbs008.htm"><img src="./dcommon/gifs/rightnav.gif" alt="Next" /><br /> <span class="icon">Next</span></a></td> </tr> </table> <p><a id="BABFJGFG" name="BABFJGFG"></a><a id="TDPII020" name="TDPII020"></a></p> <div class="sect1"><!-- infolevel="all" infotype="General" --> <h1>Tutorial: Querying Multiple Oracle Databases<a id="sthref56" name="sthref56"></a><a id="sthref57" name="sthref57"></a><a id="sthref58" name="sthref58"></a></h1> <a name="BEGIN" id="BEGIN"></a> <p>A <span class="bold">distributed query</span> accesses information in two or more databases. In a synonym or in a <code>SELECT</code> statement, you can identify a remote table, view, or materialized view by appending <code>@</code><code><span class="codeinlineitalic">dblink</span></code> to the end of its name. The <code><span class="codeinlineitalic">dblink</span></code> is a database link to the database that contains the remote database object.</p> <p>Meet the following conditions before running the distributed query in this topic:</p> <ul> <li> <p>Satisfy the prerequisites described in <a href="tdpii_distdbs006.htm#BABJDEED">"Preparing to Access and Modify Information in Multiple Oracle Databases"</a>.</p> </li> <li> <p>Create a database link from the local database to any remote database that contains a database object involved in the query. In the example in this topic, the <code>SYSTEM</code> user at the <code>ii1.example.com</code> database uses a database link that connects to the <code>SYSTEM</code> user at the <code>ii2.example.com</code> database. See <a href="tdpii_common_ii006.htm#BGBGIACD">"Tutorial: Creating a Database Link"</a> for information about creating such a database link.</p> </li> <li> <p>Ensure that the <code>hr</code> sample schema is installed on the local database, and the <code>oe</code> sample schema is installed on the remote database. These sample schemas are installed by default with Oracle Database.</p> </li> </ul> <p>This topic uses <code>ii1.example.com</code> and <code>ii2.example.com</code> as sample databases. You can substitute any two databases in your environment that meet these conditions.</p> <p>For this example, assume the following:</p> <ul> <li> <p>A company keeps its human resources information in the <code>hr</code> schema at the <code>ii1.example.com</code> database and its order entry information in the <code>ii2.example.com</code> database.</p> </li> <li> <p>The <code>employee_id</code> in the <code>hr.employees</code> table corresponds with the <code>sales_rep_id</code> in the <code>oe.orders</code> table.</p> </li> <li> <p>A manager has a question about an order and wants to contact the sales representative for the order.</p> </li> </ul> <p>In this case, the contact information for the sales representative is in the <code>hr.employees</code> table in the <code>ii1.example.com</code> database, and the order information is in the <code>oe.orders</code> table in the <code>ii2.example.com</code> database.</p> <p class="orderedlisttitle">To run a distributed query that combines the information at the ii1.example.com and ii2.example.com databases to show the contact information for the sales representative: </p> <ol> <li><a id="CIHCJDGB" name="CIHCJDGB"></a> <p><a id="sthref60" name="sthref60"></a>Create a synonym for the remote database object. In this example, create a synonym called <code>ord</code> in the <code>hr</code> schema that points to the <code>oe.orders</code> table at the <code>ii2.example.com</code> database:</p> <ol> <li> <p>Log in to Enterprise Manager as <code>SYSTEM</code> user.</p> </li> <li> <p>Go to the Database Home page for the <code>ii1.example.com</code> database instance.</p> </li> <li> <p>Click <img src="shortcut.png" alt="callback" border="0" /><a href="javascript:void(0);" onclick="redirectEMpage('SCHEMA');"><span class="bold">Schema</span></a> to open the Schema subpage.</p> </li> <li> <p>Click <span class="bold">Synonyms</span> in the Database Objects section.</p> </li> <li> <p>On the Synonyms page, click <span class="bold">Create</span>.</p> </li> <li> <p>On the Create Synonym page, enter <code>ord</code> in the Name field in the General section.</p> </li> <li> <p>With <code>Schema</code> selected for the Type, enter <code>hr</code> in the Schema field or click the flashlight icon to select the <code>hr</code> schema.</p> </li> <li> <p>In the Database section, select <span class="bold">Remote</span>.</p> </li> <li> <p>Click the flashlight icon for the Service Name field to select the <code>ii2.example.com</code> database link for the <code>SYSTEM</code> user.</p> </li> <li> <p>In the As Alias For section, enter <code>oe.orders</code>.</p> </li> <li> <p>Click <span class="bold">OK</span> to create the synonym.</p> </li> </ol> <div class="helpinfonote"> <p><span class="bold">Note: </span>You can also use the <a href="javascript:open('http://www.oracle.com/pls/db112/lookup?id=SQLRF01401','newWindow').focus()"><code>CREATE</code> <code>SYNONYM</code></a> SQL statement to create a synonym.</p> </div> </li> <li> <p>On a command line, open SQL*Plus and connect to the <code>ii1.example.com</code> database as the <code>SYSTEM</code> user.</p> <p>See <a href="topicid:ADMQS0361">Starting SQL*Plus and Connecting to the Database</a> for more information about starting SQL*Plus.</p> </li> <li> <p>Run the following query:</p> <pre xml:space="preserve" class="oac_no_warn"> COLUMN FIRST_NAME HEADING 'First Name' FORMAT A20 COLUMN LAST_NAME HEADING 'Last Name' FORMAT A20 COLUMN PHONE_NUMBER HEADING 'Phone Number' FORMAT A20 SELECT e.first_name, e.last_name, e.phone_number FROM hr.employees e, hr.ord o WHERE o.order_id = 2456 AND e.employee_id = o.sales_rep_id; </pre> <p>The output will be similar to the following:</p> <pre xml:space="preserve" class="oac_no_warn"> <span class="bold">First Name Last Name Phone Number</span> <span class="bold">-------------------- -------------------- --------------------</span> <span class="bold">Danielle Greene 011.44.1346.229268</span> </pre></li> </ol> <div class="helpinfonotealso"> <h2>Related Topics</h2> <p><a href="tdpii_intro2ii003.htm#CFHHAIGB">When to Access and Modify Information in Multiple Databases</a></p> <p><a href="tdpii_distdbs.htm#BABEFFBB">Accessing and Modifying Information in Multiple Databases</a></p> <p><a href="tdpii_distdbs008.htm#BABCCCGB">Tutorial: Modifying Data in Multiple Oracle Databases</a></p> <p><a href="tdpii_distdbs009.htm#BABFCFJJ">Tutorial: Running a Stored Procedure in a Remote Oracle Database</a></p> </div> </div> <!-- class="sect1" --> <!-- Start Footer --> <div class="footer"> <table class="simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100%"> <col width="86%" /> <col width="*" /> <tr> <td align="left"><span class="copyrightlogo">Copyright © 2007, 2009, Oracle and/or its affiliates. All rights reserved.</span><br /> <a href="./dcommon/html/cpyr.htm"><span class="copyrightlogo">Legal Notices</span></a></td> <td align="center"><a href="tdpii_distdbs006.htm"><img src="./dcommon/gifs/leftnav.gif" alt="Previous" /><br /> <span class="icon">Previous</span></a> </td> <td align="center"><a href="tdpii_distdbs008.htm"><img src="./dcommon/gifs/rightnav.gif" alt="Next" /><br /> <span class="icon">Next</span></a></td> </tr> </table> </div> <!-- class="footer" --> </body> </html>
Ms-Dos/Windows
Unix
Write backup
jsp File Browser version 1.2 by
www.vonloesch.de