Query across multiple databases

Hi,
One shot question: is it possible in Oracle to write a query joining two tables from different databases ?
I used MS SQL, and it was duable there, but I have to port app to Oracle, and I did not manage to do this on oracle.
I use oracle 9
Thanks.
pesq

1. Create an account on the remote database with permissions to select from the relevent tables.
2. Create a database link in the local database to connect to the account (step 1.) in the remote database.
3. Now execute you query in the local database connecting to the tables in the remote database.
SELECT local_a.col1, local_a.col2, rmt_a.col5
FROM local_table local_a, remote_table@<name of link> rmt_a
WHERE local_a.key = rmt_a.key;

Similar Messages

  • Outer joins across multiple databases

    I'm trying to join three tables: 2 from data warehouse and 1 from Siebel database in OBIEE. I create the physical and logical joins (no errors or warnings). The model looks like this: Account Address (table 1) -> Account (table 2) -> Siebel Customer Data (table 3)
    I create two queries in Answers:
    (1) Account.Number and Siebel.Address (the query works)
    (2) Account Address.Zip, Account.Number, and Siebel.Address (the query gets the following error):
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 42019] Join condition, D901.c3 <> 0, contains predicates that are currently not supported for outer joins across multiple databases. (HY000)
    Can someone help me understand why the join between the two databases works for the first query but when I add a second table it fails?
    thanks...

    Either you can link the Oracle DB into Access (by using File/Get External Data/Link Tables)
    or you have to simulate the join in Java by doing two separate queries and looping through the results.

  • How to execute sql scripts from Powershell across multiple databases

    Re: How to execute sql scripts from Powershell across multiple databases
    I have an tsql script that I want to run across a list of databases. How is the best way to do this in Powershell? Thanks.

    My example below, using just the SMO and not breaking up the batches, the ExecuteWithResults give the following error when the .sql file contains a GO. My script files are as simple as a DECLARE and then a GO.
    WARNING: SQL Script Failed
    The object of type "Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" is not valid or not in the correct sequence. This is likely caused by a user-specified "format-list" comm
    and which is conflicting with the default formatting.
        + CategoryInfo          : InvalidData: (:) [out-lineoutput], InvalidOperationException
        + FullyQualifiedErrorId : ConsoleLineOutputOutOfSequencePacket,Microsoft.PowerShell.Commands.OutLineOutputCommand
    Also, when executing from the ISE, is there a way to force the ISE to release the files. I am having to close the ISE and reopen my script every time I want to make a testing change to the .sql file.
    [reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")
    $scriptspath = "C:\temp\psExecuteSQLScripts\scripts"
    $SQLServer = "fidevc10"
    $SQLDB = "Bank03"
    # Create SMO Server Object
    $Server = New-Object ('Microsoft.SQLServer.Management.Smo.Server') $SQLServer
    # Get SMO DB Object
    $db = $Server.Databases[$SQLDB]
    # Load All SQL Scripts in Directory
    $scripts = Get-ChildItem -Path (Join-Path $scriptspath "*") -Include "*.sql" -Recurse
    # Loop through each script and execute
    foreach ($SQLScript in $scripts)
    $fullpath = $SQLScript.FullName
    # Read the Script File into Powershell Memory
    $reader = New-Object System.IO.StreamReader($fullpath)
    $script = $reader.ReadToEnd()
    # Execute SQL
    Write-Host "Executing $SQLScript on $SQLDB...."
    try
    $ds = $db.ExecuteWithResults($script)
    Foreach ($t in $ds.Tables)
    Foreach ($r in $t.Rows)
    Foreach ($c in $t.Columns)
    Write-Host $c.ColumnName "=" $r.Item($c)
    Write-Host "Complete"
    catch [Exception]
    Write-Warning "SQL Script Failed"
    echo $_.Exception|format-list -force
    Write-Host " " -BackgroundColor DarkCyan

  • Running sql query across multiple (remote) databases

    I'd like to run a query that pulls information from multiple databases which are not on the same machine. Is this possible using SQL Developer?

    If you are still interested, there is a tool that can query multiple databases and save results in a single text file that you can then modify as necessary - see www.bsutils.com/MuSQL.html

  • Credit Approval across multiple databases

    Hi,
    We are trying to create a credit approval across two databases i.e. set my limit in the one database but would like to have an approval fire in my other database if the combined customer balances + new transaction amount is greater than the limit set.
    We get an cannot commit ADOC error.
    Please have a look at the query and let us know what needs to be changed.
    Thanks
    Jacques
    SELECT 'TRUE' FROM SBODemoUK.dbo.OCRD a, SBODemoUS.dbo.OCRD b WHERE $[a.cardcode]=$[$4.0.0] and $[b.CreditLine]< (($[a.Balance]$[b.Balance])$[$29.0.0])) and $[a.cardcode]=$[b.cardcode}

    The $ before a.cardcode is not the right syntax.  Also when you are referencing the DocTotal I changed the syntax to
    $[$29.0.Number]
    so that we can get the value without the currency symbol
    Could you please try this
    SELECT DISTINCT 'TRUE' FROM SBODemoUK.dbo.OCRD a, SBODemoUS.dbo.OCRD b WHERE a.cardcode=$[$4.0.0] and b.CreditLine< ((a.Balance+b.Balance)+$[$29.0.Number]) and a.cardcode=b.cardcode

  • SELECT query from multiple databases

    Hi,
    Is it possible to run a SELECT query using multiple DBs' tables, like outer joining them. One of the DBs is Sybase.
    Thanks in advance

    A TopLink session can span multiple databases if they can be accessed through a single connection. A single select would require the database to handle the aggregation as mentioned in the other post.
    Alternatively TopLink's session broker will support making a single session present persistent types from multiple independent databases. This approach will not support a single SELECT spanning the databases though.
    Doug

  • Transaction across multiple databases in the same BDB environment

    Hi,
    I have multiple databases and one metadata database all in the same BDB environment. At runtime I want to create an additional database, update this database and update the metadata database in the same environment under one transaction. Are there any issues in having transactions that span multiple databases in the same environment?
    Thanks,
    Pooja

    There is virtually no difference between using multiple databases and a single database in a transaction. Concurrency is determined by other factors such as whether multiple threads access the same records. See the Writing Transactional Applications for more information:
    http://www.oracle.com/technology/documentation/berkeley-db/je/TransactionGettingStarted/index.html
    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Full text query across multiple columns

    In the SQL Server, when you do the full text query, you can specify multiple columns, e.g.
    FREETEXT ( { column_name | [b](column_list) | * } , 'freetext_string' [ , LANGUAGE language_term ] )
    CONTAINS ( { column_name | [b](column_list) | * } , '< contains_search_condition>' [ , LANGUAGE language_term ])
    Where,
    column_list Indicates that several columns, separated by a comma, can be specified...
    * Specifies that all columns in the table registered for full-text searching should be used to search for the given contains search condition. The columns in the CONTAINS clause must come from a single table...
    That makes full text query cross multiple columns very convenient. Are there any mechnisms in Oracle to do the same thing?
    Thanks in advance.

    Thanks for your reply.
    I knew that you could build full text index for the multiple columns using Oracle Text. But that does not solve my problem, which is how to build the query to search multiple columns at once. Say, I have columns firstname, lastname, address, and email in the table customers. I want to get the results that ANY column contains 'bob'. In SQL Server, I can do
    select * from customers where contains(*, 'bob')
    that is. But for Oracle, I have to do
    select * from customers where contains('firstname', 'bob') or contains('lastname', 'bob') or contains('address', 'bob') or contains('email', 'bob')
    Can you imagine if I have many columns in many tables and I have to do the query against all columns in all tables? I have to dynamically get all the columns and then build the query string.
    So, any better solutions?

  • Sql query across multiple tables ina database

    I have 3 MS Access tables in database that are linked by keyed fields in the table.  Is there a way to fetch only certain records that match a criteria across all three of these tables using the database connectivity toolset VIs?

    Thanks.  I am trying to mechanize/run an SQL query like this 
    SELECT Code_Type.Code_NUM, Code_Type.Code_Word, Word_Type.Parm_Label, Word_Type.Word_Sequence, Word_Type.Num_Words, Parameter_Label.Parm_Label, Parameter_Label.Parm_Name, Parameter_Label.Num_Bits, Parameter_Label.Num_Bits
    FROM (Code_Type INNER JOIN Word_Type ON Code_Type.Code_Word = Word_Type.Code_Word) INNER JOIN Parameter_Label ON Word_Type.Parm_Label = Parameter_Label.Parm_Label;
    while using the VIs in the database connectivity toolset.  How do I code this using these VIs?  I dont see an example of a straight SQL string like this being able to be put into the VIs.

  • Using one user account table across multiple databases but account used as a foreign key

    I want to use one user account table from one database and use it across a couple other databases. The problem is that I want some tables to use the primary key from the user account table as a foreign key to access the data when the user logs in. Is this
    the right way of going about it? Do I have to create a user account table in all my databases? What is the best practice to handle this problem? Thanks in advance.

    You can use Triggers or using replication. 
    more info: 
    Add Foreign Key relationship between two Databases
    SQL Server Replication
    Saeid Hasani [sqldevelop]

  • Preferred approach - Querying Across Multiple Schemas

    All,
    I am using two schemas within the same database as the source for my OBIEE repository/subject area. My question is whether anyone has a compelling argument or preference for setting up OBIEE to handle requests across the schemas as either:
    1. Set the connection pool property to 'Require Fully Qualified Table Names'
    2. Setup synonyms between the schemas for the tables that need to be exposed
    Just curious how others do it. I believe Synonyms may add on a small performance hit but I believe it would be negligible compared to qualifying the table with the schema name.
    Thanks,
    K

    There is no overhead in using synonyms to an object in another schema. In fact that's the best practice in my opinion. We have 3 DWHs in OBIEE each in its own schema. We also have a special OBIEE_RO account that has only select grants to all DWH objects and synonyms for all of them. We coded a script that generates all the grants and synonyms so we can re-run it when we add new objects. This assures we can use a single account for a OBIEE which is much more simpler to maintain. It also means we can share conformed dimensions between different DWHs.

  • Same sql query with multiple database links

    Hi All,
    i want to execute an sql query for a SELECT LIST Item. which should use database links in it's query.
    i'm having a list of database links in the region. say :LOC which is having 10 items each linking to different databases.
    i want to use following query for another item in same page.
    select customer_name from working_lines@:LOC where
    phone_no:phone_no
    can i do this.
    Thank you All.

    What we have done before is to create a report based on a PL/SQL procedure that returns a SQL statement.
    The PL/SQL code grabs the "selected" database link from :LOC and parses the SQL QUERY you want to execute replacing some token (like [LINK]) with '@DBNAME'.
    Lets say your SQL statement is coded like this:
    mySQL := 'SELECT cust_name FROM working_lines[LINK] where phone_no = :Phone;'
    Then all you would have to do to replace '[LINK]' with the proper DB alias would be:
    mySQL := REPLACE(mySQL, '[LINK]', '@'||:LOC);
    and then return the new SQL ...
    if :LOC has something like 'V10GPROD' your SQL would look like :
    SELECT cust_name FROM working_lines@V10GPROD where phone_no = :Phone;
    The beauty of this is that you can also include a "null" option that means the select statement will be executed on THIS database...
    Doug

  • How do you query across multiple datasources?

    I am trying to query data from an Oracle database and a DB2 database using bind variables. (10.1.3.2). I have created a data template as follows:
    <dataTemplate name="PMHUBS">
         <dataQuery>
              <sqlStatement name="Q1" datasourceref="PMDWTST">
                   <![CDATA[select      RGN.RGN_NAME,
             DSTRC.DSTRC_NAME,
          HUB_INFO.EXEL_HUB_TYPE,
          HUB_INFO.TOUCHPT_ID,
          HUB_INFO.EXEL_HUB_TYPE
    from      EXEL_DIRECT.DSTRC DSTRC,
          EXEL_DIRECT.RGN RGN,
          EXEL_DIRECT.HUB_INFO HUB_INFO
    where   DSTRC.DSTRC_ID(+) =HUB_INFO.DSTRC_ID
    and      RGN.RGN_ID(+) =DSTRC.RGN_ID
    Order by       HUB_INFO.TOUCHPT_ID,
    RGN.RGN_NAME,
    DSTRC.DSTRC_NAME,
    HUB_INFO.EXEL_HUB_TYPE]]>
         </sqlStatement>
         <sqlStatement name="Q2" datasourceref="EXBASETD DVLP1">
         <![CDATA[SELECT HBMHBCD FROM EXDBASETD.EMP012
    WHERE HBMHBCD=:TOUCHPT_ID]]>
              </sqlStatement>
         </dataQuery>
    </dataTemplate>
    I get the error message: ORA-00903: invalid table name. Each sql statement works separately. I can take the 2 sql statements and concatenate them and get the XML output, but I seem to be doing something wrong using a data template.
    Help?
    Thanks
    Phil Slater

    I was missing the GROUP part of the dataTemplate!
    I didn't find the manuals that helpful with this. You have to add the datasourceref to each SQL:, and then add a GROUP in a DataTemplate.
    <dataTemplate name="JOINS_TEST " dataSourceRef="EXDBASETD DVLP1">
    <dataQuery>
    <sqlStatement name="DB2 HUBS">
    <![CDATA[     SELECT HBMHBCD
                              FROM EMP012
                             WHERE HBMEXAG = 'E'
                         AND HBMSTAT = 'ACTV'
                    ORDER BY HBMHBCD
                    ]]>
    </sqlStatement>
    <sqlStatement name="ORACLE HUBS" dataSourceRef="PMDWTEST">
    <![CDATA[     
                    SELECT TOUCHPT_ID
                      FROM HUB_INFO
                     WHERE EXEL_HUB_TYPE='EXEL'
                 AND :HBMHBCD = TOUCHPT_ID
    ]]>
    </sqlStatement>
    </dataQuery>
    <dataStructure>
    <group name="G_HUBS" source="DB2 HUBS">
    <element name="HBMHBCD" value="HBMHBCD"/>
    <group name="G_ORACLE HUBS" source="ORACLE HUBS">
    <element name="TOUCHPT_ID" value="TOUCHPT_ID"/>
    <element name="REG_ID" value="REG_ID"/>
    </group> -- PMDWTEST
    </group> --- EXDBASETD
    </dataStructure>
    </dataTemplate>

  • How to use ServerApplicationContext to do a remote query across multiple entities

    Hello everybody,
    My data model is like this:
    "Case" -> one-to-many -> "Document"
    Document has  the fields:
    - "IsFinalised" (boolean)
    -  File (large binary)
    My business rule is: 'a Case is closed if all its documents are finalised'.
    I am trying to do a query which returns whether a case is closed using ServerApplicationContext, but I don't want the query to load the large binaries for each Document into memory for given case.
    Does this do the job?
    int IsCaseClosed(int caseId)
    using (var sac = ServerApplicationContext.CreateContext())
    var relevantCase = sac.DataWorkspaces.ApplicationData.Cases.FirstOrDefault(c => c.Id = caseId);
    return relevantCase.Documents.All(d => d.IsFinalised);

    I think what you have is pretty close.  I would probably write it like this:
    bool IsCaseClosed(int caseId)
    bool isClosed = false;
    if caseId > 0
    using (var sac = ServerApplicationContext.Current ?? ServerApplicationContext.CreateContext())
    isClosed = sac.DataWorkspace.ApplicationData.Cases_Single(caseId).Documents.All(d => d.IsFinalised);
    return isClosed;

  • Best workaround for querying across multiple Data Sets?!

    Hi folks
    Today I was migrating my older OEID 3.0 applications to 3.1, and I noticed some of my older version views are not working anymore in new version.
    We used to have multiple Bulk Add/Replace (without specifying Collection Keys) and we could use any attributes from any of these, in a certain View for example.
    My views were like SELECT SUM("an attribute/metric from Bulk Add_1") / SUM("an attribute/metric from Bulk Add_2")
    Now that you have to specify a FROM clause in your views, and it has to be from a certain Data Set, whats the best way to achieve above line goal?
    Bests,

    Patrick
    What I meant by Cross Join is Cartesian Product in situation that you have many-to-many relations between 2 Data Sets
    Lets say, I have to different data, coming from 2 totally different source, one from Sales Dept and the other one from Purchase Dept:
    Sales Table:
    Part Number
    Sales QTY
    Sales Date
    Part Type
    Manufacturer
    Country
    0001
    70
    10/5/2012
    TYPE1
    Manuf1
    US
    0001
    120
    10/6/2012
    TYPE1
    Manuf1
    US
    0001
    350
    10/7/2012
    TYPE1
    Manuf1
    US
    0002
    100
    10/8/2012
    TYPE2
    Manuf2
    US
    0002
    80
    10/9/2012
    TYPE2
    Manuf2
    CA
    0003
    2500
    10/10/2012
    TYPE3
    Manuf3
    CA
    0004
    180
    10/11/2012
    TYPE4
    Manuf4
    US
    Purchase Table:
    Part Number
    Purchase QTY
    Purchase Date
    Part Type
    Manufacturer
    Country
    0001
    50
    10/5/2012
    TYPE1
    Manuf1
    US
    0001
    60
    10/6/2012
    TYPE1
    Manuf1
    US
    0001
    100
    10/7/2012
    TYPE1
    Manuf1
    US
    0001
    200
    10/8/2012
    TYPE1
    Manuf1
    US
    0002
    1100
    10/9/2012
    TYPE2
    Manuf2
    US
    0003
    20
    10/10/2012
    TYPE3
    Manuf3
    US
    What is the preferred approach to ingest this data?

Maybe you are looking for

  • Power Mac G5 upgrade question.

    Does anybody know if the G5 can be transformed into an Intel system in order to upgrade to Lion? I really don't want to have to buy a new Mac.

  • JDI plug-in not showing in NWDS preference

    Hello I have installed NWDS 7.11 Latest NWDS release and post steps also done. Help -> Software updates -> Find and Install and Choose Search for updates of the additional installed features. But JDI (Development Infrastructure) plug-in not showing i

  • RFC User for satellite systems

    Hello Gurus, I just wanted to ask about one issue. We are a SAP partner and using Solution Manager in VARs scenario. There are many systems of our customers connected to our Solution Manager.. Now I want to ask about RFC user(s). As I see, in our Sol

  • Sending iOS camera stream to FMS

    I'm currently developing an app that requires video conferencing for iOS. I've used a fairly basic approach with Flex that streams the camera and microphone on H.264 with Speex to FMS. It does actually produce a stream but I pressume the quality is s

  • Document Set default content type

    When defining a document set, you can define what content types can be used in a document set.  If, after uploading a document, the user cancels the properties page, the default content type for the library is assigned to the document (even though th