How to join tables from different databases (DBLink/DB connection )

Hello,
i have an issue and i hope you could help me to solve it. My problem is: I want to create native sql select which joins two tables from different DB (both of them are ORACLE, one of them internal, another one - external). I have found several notes and posts, but without any success. Db connection exists in dbcon table, so this part of my problem has been solved.
I would like something like that:
select * from table1@xxx inner join table2.
i can not split this select into two separate ones, because both tables store over 30 mln. entries and i do not want to create any copies of them.
Br,
dez

Hi,
you might need to create a DB-Link on DB level and use EXEC SQL.
Lots of stuff on google about this, like
Oracle DBLink ( external database )
Volker

Similar Messages

  • How to join tables on different databases

    In the company I work in, we've got some java applications working on two different instances which "hide" to each others (one on 10g and the other on 8i). Some decoding tables, which should common to both of them, are only present on 8i one.
    I've been told that java works 'cause it allows to connect to both of databases and then report the information on front end applications.
    The question is this: since we'll have to get reports on both of databases, is it possible to perform queries by using tools like oracle forms, oracle reports, sql developers, ... for joining the tables of the two different databases as java does? We have to get how to accede directly to the two instances for getting data from both of them for reporting activities. I remind you that we cannot use dblinks between the two databases for internal security reasons.
    Thanks in advance!

    Even java can't join between tables on two databases if the db links are not created.
    So it essentially works that it fetches the data from one db and then from another db ( using two different db connctions) and then you can utlize these data and perform some joining.
    Coming back to database world. It can be done like the usual dw approach.
    1. Connect to a third db:
    2. Get data from one database
    3. get data from other database.
    now do all the joins that you want to do

  • How to join  fields from different internal tables and display into one int

    hai i have one doubt...
    how to join  fields from different internal tables and display into one internal table..
    if anybody know the ans for this qus tell me......

    hii
    you can read data as per condition and then can join in one internal table using READ and APPEND statement..refer to following code.
    SELECT bwkey                         " Valuation Area
             bukrs                         " Company Code
        FROM t001k
        INTO TABLE i_t001k
       WHERE bukrs IN s_bukrs.
      IF sy-subrc EQ 0.
        SELECT bwkey                       " Valuation Area
               werks                       " Plant
          FROM t001w
          INTO TABLE i_t001w
           FOR ALL ENTRIES IN i_t001k
         WHERE bwkey = i_t001k-bwkey
           AND werks IN s_werks.
        IF sy-subrc EQ 0.
          LOOP AT i_output INTO wa_output.
            READ TABLE i_t001w INTO wa_t001w WITH KEY werks = wa_output-werks.
            READ TABLE i_t001k INTO wa_t001k WITH KEY bwkey = wa_t001w-bwkey.
            wa_output-bukrs = wa_t001k-bukrs.
            MODIFY i_output FROM wa_output.
            CLEAR wa_output.
          ENDLOOP.                         " LOOP AT i_output
        ENDIF.                             " IF sy-subrc EQ 0
    regards
    twinkal

  • Select query based on joining of tables from different database is taking too long

    Hi Team,
    Select query on table with millions of records is taking very long time. It took 50mins, the below query is joining on multiple table from two databases DB1.dbo.Table1 contains 100 million records and also Table3 and Table4 (of different database) might
    contain close to 1million records.
    Select T1.*
    From DB1.dbo.Table1 T1
    Join DB1.dbo.Table2 T2 on RTRIM(T1.Col3) = RTRIM(T2.Col3)
    Join Table4 CA on RTRIM(T1.Col1) + T2.Col2 = CA.Col1
    Join Table3 U on CA.Col2 = U.Col2 AND RTRIM(T2.Col2) = U.Col3
    Where U.Col4 NOT IN ('A1', 'A2', 'A3', 'A4', 'A5', 'A6','A7','A8','A9')
    And (T1.flg IS NULL OR T1.flg = 'N')
    And LTRIM(RTRIM(T2.Col2)) NOT IN ('B1','B2')
    How can i improve the performance of this query. Actual thing is update the data in Db1.dbo.table1 based on the conditions but if the select is taking close to 1hr then update will take hours together. Indexes already implemented on all the tables.
    Thanks,
    Eshwar.
    Please don't forget to Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful. It will helpful to other users.

    Thanks.
    Join Table4 CA on RTRIM(T1.Col1) + T2.Col2 = CA.Col1
    This join is not working with spaces if Rtrim is not used.
    Thanks! Eshwar.
    Please don't forget to Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful. It will helpful to other users.

  • Joining tables in different databases

    Hi,
    I know we can access multiple databases like Oracle, Informix etc. through a single toplink session using session broker. Also in toplink documentation it says there is a work around for joining tables that exists in different databases i.e. joining an Oracle table with an Informix Table. If anyone had tried this or if it is possible, please let me know how to do this.
    Thanks..

    If I could know, how to perform or some sample code, for the following two steps it would be great.
    Write descriptor ammendment code to bind together that go from (A) to (B) and (B) to (A).
    Be sure to map the ammendment descriptors in the mapping workbench.Or please point me to the right toplink documentation or examples.
    Thanks a lot for your help.

  • Dealing with tables from different databases?

    Hi. I'm a newbie to Visual Studio 2012 and stuck on how to interact with different datasets.
    I am building a report that is associated with with two tables, each from a different database. The
    master_flat table with the primary key matter_number is from the first database and it contains all the columns I need that should show up in the report layout I've built. However,
    billing_table with the primary key matter_number contains a flag that I go by which I must use to determine whether each matter should come through in the reporting or not. 
    I've set the master_flat as dataset1 and the billing_table as dataset2. Now, what is the best way in Visual studio 2012 to filter by the matters that has flag "N" in dataset2?
    Thanks

    We are way out of sync.  Lets synchronize.  I'm not sure which question you are refering to.  Is it the "C# or VBnet"  question or is it the "One or two database Question".  It seem like it would be the database question since you
    should know which programming language you are using.
    Open SQL Server Management Studio (SSMS).  After login, there is an explorer where you can browse the databases, tables, and fields in the tables.  You should be able to view how you build the database.  If you right click any tables and then
    "Script Table As : Select To : New Query Editor Window".  There is an execute button to run the query.  You can aslo edit the query.  I usually test all my qeuries in SSMS before actually using them in an application.  I would get a JOIN
    SQL working in SSMS.
    If you let me know if you are using VBnet or C# I will write a simple LINQ.  Even better if you supply me the names of the columns of the two tables.
    jdweng

  • How to migrate files from different databases to sharepoint 2013?

    Hello everyone,
    I need to migrate files of various formats from two databases to SharePoint 2013 ? How should I pursue? Please explain..
    Scenario : Two different databases on different systems have loads of files. I need to migrate them to SharePoint?
    Any suggestions/ Answers

    Hi,
    You need to copy the database into your network shared folder or SharePoint Server where you wanted to attach this content DB to your newly created web application.
    Hope and Afraid,
    Same Domain has been used. I mean if you move the content db from the server 1 which using the AD1 for authenticate the users,
    So your new server 2 and web application must have configured to authenticate the AD 1 users.Otherwise user not found exception will be thrown. 
    If not  still you can change the site collection administrator for the site which is migrated from the server 1.
    Murugesa Pandian., SharePoint 2010 | MCPD | MCTS |Configure

  • Can we join table from different schema?

    Hi
    All,
    I have a SYS schema and MED schema. Now, I want to join DBA_USERS tables from SYS schema to EMPLOYEE table from MED schema to get an username. i am using following query but it's not working.
    select username,empl_userid,empl_nm_lst,empl_nm_fst from sys.dba_users db, med.employee emp where db.username = emp.empl_userid;
    Thanks,
    vishal

    g8 it is working now I just modify my query to make user name in upper case and then compare..
    select username,empl_userid,empl_nm_lst,empl_nm_fst from sys.dba_users db, med.employee emp where db.username = upper(emp.empl_userid);
    before that it was returning nothing..
    thanks for your help ... awesome..
    vishal
    Edited by: vishal patel on Sep 29, 2008 2:39 PM
    Edited by: vishal patel on Sep 29, 2008 2:40 PM

  • How to "join" data from different SyncBO's within MAM?

    Hi,
    Have anyone tried "joining" the data from different SyncBO's into one in a custom MAM application?  For example, the SyncBO MAM30_30 (Functional Location) has references to MAM30_016 (Catalog + Code Groups).  Is there an easy way to display all of the related information together, instead of first looping through objects from MAM30_030, then for each individual object, loop through a list of MAM30_016? 
    Basically, the application that we're working with has 3000+ Functional Locations, so we are looking for a way to join the data and display them as one object to improve performance.
    Many thanks!
    Jeffrey

    Thanks Norbert.  Unfortunately, we cannot create new Syncbo's, as we have limited access to that R/3 backend.
    Basically, what we want to do is customize the MAM bit so that it can display the Tech Obj List with all its codes and children item syncbo's, instead of having the user click on the link to see more info.  We would like to do this without having to loop through the child sync bo's.
    Many thanks!

  • How to load data from different database

    Hi,
    My problem is how to load Foxpro 2.6/clipper data into oracle 8 with all its structure and data with SQL loader or other utility if any.
    And also how can i integrate existing forpro system into Oracle. i.e client will work on Foxpro application and we will only take its output(data files) on daily basis and convert it into Oracle 8.
    Please find any solution.
    Regards
    null

    You can also try to make up an ODBC connection to Foxpro and convert the data from foxpro to oracle using the COPY command (see docs on PL/SQL & OCA). I remember that foxpro/clipper are running on MS-DOS, so I don't know if you can establish an ODBC connection to oracle which can be used from the foxpro/clipper application to use it as a frontend for an oracle database.
    Regards, Kai
    null

  • How to compare tables from different schema.

    Edited by: Adi's on 24-Jan-2010 03:30

    i am done with this report...
    sorry for editing it like that
    Edited by: Adi's on 24-Jan-2010 03:31

  • How to find tables from database having no partition

    Hello Sir,
    How to find tables from oracle database having no partitions?
    Thank you.
    -Mal

    @SB,
    SQL> SELECT OWNER, TABLE_NAME FROM DBA_TABLES
      2  MINUS
      3  SELECT OWNER, TABLE_NAME FROM DBA_TAB_PARTITIONS;
    SELECT OWNER, TABLE_NAME FROM DBA_TAB_PARTITIONS
    ERROR at line 3:
    ORA-00904: "OWNER": invalid identifier@OP,
    select table_name,partitioned from dba_tables where partitioned='YES';
    select table_name,partitioned from dba_tables where partitioned='NO';
    Regards
    Girish Sharma
    Edited by: Girish Sharma on Jul 1, 2011 9:27 AM

  • Select data from different database

    hi,
    may I know how to select data from different database?
    for example,
    I've 2 databases, OracleDB and OracleAR
    Connect with OracleAR in SQL*Plus
    select * from OracleDB.TableName
    does Oracle support this kind of query?
    how can I retrieve data from other database while im connecting with
    other database?

    Hi,
    Yes, it's possible. No, your syntax won't work.
    First of all you have to define a DATABASE LINK inside the DB where you are already connected (in this case OracleAR). Read docs how to do that.
    Second thing is the query. It will look like
    SELECT * from TableName@<NameOfDatabaseLink>Greetings,
    Guido

  • How to create a view consisting of data from tables in2 different databases

    Using Oracle 10.2g
    I have 2 databases Gus and haggis on Comqdhb schema.
    glink indicates a databse link between Haggis and Gus
    In Gus there are tables student,subject,grade,school containing columns like upn...
    STUDENT
    upn
    academicYear
    SUBJECT
    subject
    GRADE
    examlevel
    grade
    SCHOOL
    sn
    In HAGGIS there are tables student,grade,teacher containing columns upn...desc below.
    STUDENT
    upn
    GRADE
    grade
    upn
    academicyear
    level
    Create view in your HAGGIS database which will join all of the exam grades together. You should have one view which will produce the following relation :
    examGrade(upn, subject, examlevel, sn, grade,academicYear)
    so I need to create a view which gets the data from both the tables in both the databases.
    create view as examGrade(upn, subject, examlevel, sn, grade,academicYear) as select s.upn
    But i am not getting how to select a column from 2 tables in different databases
    I mean if i said
    select upn from comqdhb.student@glink,comqdhb.student;
    select upn from comqdhb.student@glink,comqdhb.student
    ERROR at line 1:
    ORA-00918: column ambiguously defined
    help me out,Thank you.

    Thank you for the reply will follow up the code format
    Create views in your HAGGIS schema database which will join all of the exam grades together. You should have one view which will produce the following relation :
    examGrade(upn, subject, examlevel, sn, grade,academicYear)
    I understand that there wont be duplication when we use conditions
    If i query
    select count(upn)
    from   comqdhb.student@glink I get 9000
    but after the union
    create view examGrade(upn, subject, examlevel, sn, grade,academicYear)
    as
    select distinct s.upn as upn
    ,                  g.subject as subject
    ,                  g."LEVEL" as examlevel
    ,                  g.grade as grades
    ,                  '9364097'
    ,                  to_number(g.academicyear) as academicyear
    from             comqdhb.student s
    ,                   comqdhb.grade g
    where           s.upn=g.upn
    union
    select            s.upn
    ,                   sb.subject
    ,                   g.elevel
    ,                   g.grade
    ,                   s.acyr
    ,                   sc.sn
    from              comqdhb.subject@glink sb
    ,                   comqdhb.student@glink s
    ,                    comqdhb.gradevalues@glink g
    ,                    comqdhb.school@glink sc,
    ,                    comqdhb.studentingroup@glink sg
    ,                    comqdhb.teachinggroup@glink tg
    where            sb.sid=tg.sid
    and                tg.gid=sg.gid
    and                sg.upn=s.upn
    and                g."LEVEL"=tg.elevel
    and                s.school=sc.id
    and                sc.id=tg.id; returns
    count(upn) from exam gradeIt gets stuck actually sometimes it returns
    932002 some results.
    2:
    Another problem i am having which i am trying to solve and written up my ideas but haven't been getting the expected results.Hope you can help.Thank you.
    Information:
    =======
    All children take exams at the age of 16 called a General Certificate of SecondaryEducation (GCSE).
    They have to study and take exams in Mathematics, English and Science, and can take other subjects such as History, French, Art etc. Most students will study between 5 and 10 different subjects before taking their GCSEs.
    For each exam, a student is awarded a grade from A*, A, B,C,D,E,F,G,U,X An A* grade is the best grade achievable and an X is the worst grade.
    In order to analyze how students have performed, each grade is mapped to a numeric value as follows:
    Grade Numerical score
    A* 8
    A 7
    B 6
    C 5
    D 4
    E 3
    F 2
    G 1
    U 0
    X 0
    Now why i need this avgGCSE is because i have to create a view containing avgGCSE of the students it is used in the next question where a condition is avgGCSE is between 6.5 and 7
    In order to calculate the avgGCSE the idea is to calculate the grades of the students and map the grades to their corresponding scores/values
    add them all up and div by the total no of grades to get the avg.
    desc comqdhb.STUDENT@glink;
    STUDENT
    =======
    UPN
    FNAME
    CNAME
    DOB
    GENDER
    PREVIOUSSCHOOL
    XGCSE
    SCHOOL
    ACYR
    STUDENTINGROUP
    =============
    UPN
    GID
    STARTDATE
    ENDDATE
    GRADE
    GRADEVALUES
    ===========
    GRADE
    LEVEL
    VALUE
    I have a opinion that xgcse in STUDENT table refers to the avgGCSE which i want to calculate as when i asked my professor as to what xgcse he said that he forgot to take it out of the table and it is not necessary while creating avggcse.
    select *
    from comqdhb.student@glink
    where xgcse<6.5; Displaying a result
    returns:
    UPN FAMILYNAME COMMONNAME DATEOFBIR GENDER PREVIOUSSCHOOL XGCSE SCHOOL ACYR
    ===========================================================================
    1011 KIMBERLY ABBOT 07-JUL-79 f none 3.93500948 2 2
    select *
    from comqdhb.student@glink
    where xgcse between 6.5 and 7 and upn = 1386; Displaying a result
    returns:
    UPN FAMILYNAME COMMONNAME DATEOFBIR GENDER PREVIOUSSCHOOL XGCSE SCHOOL ACYR
    ===========================================================================
    1386 STEPHANIE AANNESSON 15-JAN-79 f none 6.88873 2 2 so if xgcse is the avgGCSE then upn 1011 has avggcse<6.5 and 1386 has avggcse >6.5
    my idea was backward strategy like so now if we find out upn 1368 has suppose xgcse(avggcse)>6.5 how to extract the avggcse for the particular upn We need to map grades from GRADEVALUES to grade in STUDENTINGROUP and map upn from studentingroup to upn in student to output the values for the corresponding grades from GRADEVALUES
    select grade
    from comqdhb.studentingroup@glink
    where upn = 1011;
    Result:
    GRADE
    =====
    D
    F
    B
    E
    C
    E
    E
    B
    8 rows selected. Mapping each grade to the corresponding value and calculating we get
    32/8=4 total(values to corresponding grades)/no of grades.
    But the xgcse for upn 1011 is 3.935 and i am getting 4!! maybe xgcse isn't avggrade but ? is the procedure by me correct for calculating avggcse
    select grade
    from comqdhb.studentingroup@glink
    where upn = 1386;
    Result:
    GRADE
    ======
    A*
    A*
    A*
    A*
    B
    A*
    A*
    A
    B
    B
    B
    11 rows selected. grade to the corresponding value and calculating we get
    79/11=7.12 total(values to corresponding grades)/no of grades.
    But the xgcse for upn 1011 is 6.88... and i am getting 7.12!!
    But another problem
    when i say
    select   g.value,g.grade
    from     comqdhb.gradevalues@glink g
    ,        comqdhb.studentingroup@glink sg
    where    g.grade=sg.grade
    and      sg.upn=1011;
    result:
    ======
    VALUE GRADE
    ===========
      100 B
      100 B
       80 C
       60 D
       40 E
       40 E
       40 E
       20 F
        6 B
        6 B
        5 C
    VALUE GRADE
    =============
        4 D
        3 E
        3 E
        3 E
        2 F
    16 rows selected.
    select   distinct g.value,g.grade
    from     comqdhb.gradevalues@glink g
    ,        comqdhb.studentingroup@glink sg
    where    g.grade=sg.grade
    and      sg.upn=1011;
    result:
    ======
    VALUE GRADE
    ============
         2 F
       100 B
         6 B
         3 E
        60 D
         5 C
         4 D
        80 C
        40 E
        20 F
    10 rows selected. I am getting only 8 for the query
    select grade
    from comqdhb.studentingroup@glink
    where upn = 1386; here its becomming 10 and also its displaying values as 100 and ...
    select distinct *
    from   comqdhb.gradevalues@glink;
    GRADEVALUES
    ===========
    LEVEL      GRADE           VALUE
    ================================
    a          A                 120
    a          B                 100
    a          C                  80
    a          D                  60
    a          E                  40
    a          F                  20
    a          U                   0
    a          X                   0
    g          A                   7
    g          A*                  8
    g          B                   6
    LEVEL      GRADE           VALUE
    ================================
    g          C                   5
    g          D                   4
    g          E                   3
    g          F                   2
    g          G                   1
    g          U                   0
    g          X                   0
    18 rows selected. I was hoping if i could map the grades and get the values and calculate avggrade by total(values)/count(values)that would be it but here there are values like 100...
    select  sum(g.value)/count(g.grade) as avggrade
    from    comqdhb.gradevalues@glink g
    ,         comqdhb.studentingroup@glink sg
    where  g.grade=sg.grade
    and     sg.upn=1386;
    avggrade
    ========
    37.4375 the avggrade cant be this big and when i map each grade i obtained for 1368 like a to 7+b to 6 so on i get avggrade 7.12
    kindly help.
    Edited by: Trooper on Dec 15, 2008 4:49 AM

  • How do you join two tables from different Oracle schemas using a subquery

    I am trying to join two tables from different Oracle schemas using a subquery. I can extract data from each of the tables without a problem. However, when I combine the select statements using a subquery I get the Oracle error *'ORA-00936: missing expression'*. Since each SELECT statement executes on its own without error I don't understand what is missing. The result set I am trying to get is to match up the LINE_ID from PDTABLE_12_1 in schema DD_12809 with the MAT_DESCRIPTION from table PDTABLE_201 in schema RA_12809.
    The query is as follows:
    sql = "SELECT [DD_12809].[PDTABLE_12_1].LINE_ID FROM [DD_12809].[PDTABLE_12_1] JOIN " _
    + "(SELECT [RA_12809].[PDTABLE_201].MAT_DESCRIPTION " _
    + "FROM [RA_12809].[PDTABLE_201]) AS FAB " _
    + "ON [DD_12809].[PDTABLE_12_1].PIPING_MATER_CLASS = FAB.PIPING_MATER_CLASS"
    The format of the query is copied from a SQL programming manual.
    I also tried executing the query using a straight JOIN on the two tables but got the same results. Any insight would be helpful. Thanks!
    Edited by: user11338343 on Oct 19, 2009 6:55 AM

    I believe you are receiving the error because you are trying to JOIN on a column that doesn't exist. For example you are trying to join on FAB.PIPING_MATER_CLASS but that column does not exist in the subquery.
    If you want to do a straight join without a subquery you could do the following
    SELECT  DD_12809.PDTABLE_12_1.LINE_ID
    ,       FAB.MAT_DESCRIPTION
    FROM    DD_12809.PDTABLE_12_1
    JOIN    RA_12809.PDTABLE_201    AS FAB ON DD_12809.PDTABLE_12_1.PIPING_MATER_CLASS = FAB.PIPING_MATER_CLASS  HTH!

Maybe you are looking for

  • How to use group by in tabular form

    Hi all i have a tabular form and i need to issue the goods not more then five and in 1 row i will issue only 1 qty so i use only five rows . but by mistake i will use 6 rows then it is wrong how to restrict it please guide Thanks and Regards vikas

  • Library not opening in iPhoto '11

    I recently "upgraded" to iPhoto '11, but when I tried to open my library, it gave me an error message.  Sorry I don't have the quote of the exact message, but it was something to the effect of "I can't read this old library, but I can upgrade it for

  • Can I put the latest software on this iBook?

    I have a IBook and I want to install the latest mac software. Is this possible?!

  • Getting error for classpath setting during compilation

    Hi, I tried sampel code of SchematronValidation bpel sample code from oracle site.But while compiling the code,I am getting following error: Failed to compile bpel generated classes. failure to compile the generated BPEL classes for BPEL process "Sch

  • Download ios 5.0.1 upgrade and now ipad2 wont connect to itunes

    I downloaded the upgrade.  iTunes said it was backing up my ipad-2.  Some error happened and now all my iPad shows is the start-up screen telling me to hook the usb up to iTunes.  iTunes doesnt recognize the iPad though.  Tried the normal cycling of