JOIN two databases

I'm trying to join two tables which seems like it should be simple. However, I'm struggling to find the solution.
I have a table in my order entry database with the following schema:
OrderID, TaskID, HoursBilled
I have another table in my time and attendance system with the following schema:
OrderID, TaskID, HoursCompleted
I want to Join these tables together so I can compare the hours billed for an order by task to the hours completed. However, there are instances when there are hours billed for a task for an order that do not have any hours completed in the time and attendance
system and there are also hours completed for an order in the time and attendance system for tasks that have not been billed on a job. The results I'm looking for are something like this:
OrderID, TaskID, HoursBilled, HoursCompleted
1, 2, 10, NULL
1, 3, NULL, 4
1, 5, 6, 2
1, 4, 5, 9
Currently I'm using LEFT OUTER JOIN on OrderID and TaskID but this excludes the hours completed for tasks that were not billed for the job.
What's the best way to handle this scenario? I could do a separate query and UNION the results, but I'm hoping there's a better solution then that.

I think I solved my own problem as I was writing the sample code. Does this make sense?
If OBJECT_ID('tempdb..#ORDER') is not null Drop Table #ORDER
If OBJECT_ID('tempdb..#TIME') is not null Drop Table #TIME
CREATE TABLE #ORDER
(OrderID int
,TaskID int
,HoursBilled decimal(18,4))
CREATE TABLE #TIME
(OrderID int
,TaskID int
,HoursCompleted decimal(18,4))
INSERT INTO #ORDER
VALUES (1, 2, 10)
INSERT INTO #ORDER
VALUES (1, 5, 6)
INSERT INTO #ORDER
VALUES (1, 4, 5)
INSERT INTO #TIME
VALUES (1, 3, 4)
INSERT INTO #TIME
VALUES (1, 5, 2)
INSERT INTO #TIME
VALUES (1, 4, 9)
SELECT ISNULL(o.OrderID, t.OrderID) AS 'OrderID'
--, t.OrderID
, ISNULL(o.TaskID, t.TaskID) As 'TaskID'
--, t.TaskID
, HoursBilled
, HoursCompleted
FROM #ORDER o
FULL OUTER JOIN #TIME t
ON o.OrderID = t.OrderID
AND o.TaskID = t.TaskID

Similar Messages

  • SELECT data from two databases

    I have two databases that I need to select data from in a
    single SELECT. Using DWs Advanced window for creating the select I
    don't see any way to select more than 1 Connection. Both databases
    have unique user and passwords but reside on the same server. Any
    idea how I can write a single SELECT to get data from both dbs. I
    assumed it would be similar to selecting data from multiple tables
    within the same db but the connection part is stumping me. Any
    ideas would be greatly appreciated.

    TouchstonePress wrote:
    > Page 48, Developing a Web Database Application . . .
    speaks about making a
    > database with two related TABLES each with the same
    PRIMARY KEY column with
    > which to identify a customer using their unique number.
    That's the basic technique for joining two tables in the same
    database.
    The original poster has tables in different databases that
    have
    different user accounts and passwords.
    Although it's possible to join two databases, you cannot do
    it unless
    you have one user account with the same privileges on both
    databases.
    David Powers, Adobe Community Expert
    Author, "The Essential Guide to Dreamweaver CS3" (friends of
    ED)
    Author, "PHP Solutions" (friends of ED)
    http://foundationphp.com/

  • How do I join two tables in the same database and load the result into a destination table in a SSIS package

    Hi,
    I have a query that joins two tables in the same database, the result needs to be loaded in a destination DB table.  How do I do this in SSIS package?
    thank you !
    Thank You Warmest Fanny Pied

    Please take a look at these links related to your query.
    http://stackoverflow.com/questions/5145637/querying-data-by-joining-two-tables-in-two-database-on-different-servers
    http://stackoverflow.com/questions/7037228/joining-two-tables-together-in-one-database

  • A dimension table outer join across two databases

    I have two databases of the same schema but may have different data that I would like to do comparisons on. For this discussion, each has two tables, Dimension and Fact. I created a common dimension which would show dimension data that exists on both databases. However, I want a common dimension which is a full outer join of the two Dimension tables that can be used to view data on the Fact tables on the two databases; this seems to be a little difference than a fact which may having missing value, isn't it? should this outer join occurs at the physical or logical? Can I even do it at physical if the data are from two different source? Any recommendation on what is the best way to do so? Thanks

    It depends on how you are defining your BM. Always, BM is for creating joins on folders within BM, in the sense that each folder can contain data from within multiple databases. So, create it in Physical layer and also create new joins for your defined facts dimensions in BM. But remember, cross database joins are not recommended. If both your schemas reside on 2 different oracle databases, you would be better off creating a single view (by creating a dblink between these 2 databases). So, create a single view and include that in the physical layer.
    Thanks,
    Venkat
    http://oraclebizint.wordpress.com

  • Join two tables which stored in difference database

    Hi, i have a problem how to join two tables which are stored in difference databases. I'm using MS access and need to use Jsp to solve it. is anyone have idea to solve it. thxx

    Hi,
    I think you cannot join the tables which are in two diff databases. You have to connect to each database ,get the result and manipulate in your program. Use a bean.
    cheers,
    Narayana

  • Trigger in a join table between two database

    Hi an Happy new year
    I have two database, one is dedicated to security and the second for my multitenancy application
    In this two databases one have tables USER, USER_JOIN_USER_ROLE and USER_ROLE
    the second, USER (where fields are differents), USER_JOIN_USER_ROLE and USER_ROLE
    the two join table must be the same and USER_ROLE are the same in the two databases.
    I plan to use a trigger to replicate from the  application database to the security one, I already use triggers to Replicate USER and set the differents fields.
    I'm new in triggers using.
    My user replication trigger seems like that
    CREATE TRIGGER [dbo].[USER_REPLICATION]
    ON [dbo].[DM_USER]
    AFTER INSERT
    AS
    BEGIN
    DECLARE @EmployeeId int = (SELECT FKEmployee FROM inserted)
    DECLARE @Login nvarchar(50) = (SELECT LoginUser FROM Inserted)
    DECLARE @Password nvarchar(50) = (SELECT PasswordUser FROM Inserted)
    DECLARE @Tenant int = (SELECT IdCompany FROM TEST_MULTI.dbo.DM_COMPANY WHERE IsTenant = ''Y'')
    DECLARE @CompanyId int = (SELECT ExtIdCompany FROM TEST_MULTI.dbo.DM_COMPANY WHERE IsTenant = ''Y'')
    DECLARE @LegalEntityId int = (SELECT FKLegalEntity FROM TEST_MULTI.dbo.DM_EMPLOYEE WHERE IdEmployee = @EmployeeId)
    DECLARE @LastName nvarchar(255) = (SELECT LastNameEmployee FROM TEST_MULTI.dbo.DM_EMPLOYEE WHERE IdEmployee = @EmployeeId)
    DECLARE @FirstName nvarchar(255) = (SELECT FirstNameEmployee FROM TEST_MULTI.dbo.DM_EMPLOYEE WHERE IdEmployee = @EmployeeId)
    DECLARE @EMail nvarchar(255) = (SELECT EMail FROM inserted)
    SET NOCOUNT ON;
    INSERT INTO DM_SECURITY_MASTER.dbo.DM_USER(LoginUser, PasswordUser, FKCompany, TenantId, LegalEntityId, LastName, FirstName, Email)
    VALUES (@Login, @Password, @CompanyId, @Tenant, @LegalEntityId, @LastName, @FirstName, @EMail)
    UPDATE [TEST_MULTI].[dbo].[DM_USER] SET ExtIdUser = (SELECT IdUser FROM [DM_SECURITY_MASTER].[dbo].[DM_USER]
    WHERE LoginUser = @Login
    AND PasswordUser = @Password
    AND FKCompany = @CompanyId
    AND TenantId = @Tenant
    AND LegalEntityId = @LegalEntityId
    AND LastName = @LastName
    AND FirstName = @FirstName
    AND EMail = @EMail)
    WHERE IdUser = (SELECT IdUser FROM Inserted)
    END
    but I cannot figure how to use a trigger to update a collection and not find anything on it, any help welcome
    I use Windows Identity Foundation in my code and update or insert can set multiple rows

    Hello and thanks for help.
    The trigger i give as example already works fine but Fanny Liu is for sure better than mine and I will try it. Users insertions are not multiple, only one user can be inserted at the same time
    My question was most on using triggers to update a collection via a Join table between my user and users roles
    I wrote it Yesterday for INSERT
    USE [TEST_MULTI]
    GO
    /****** Object: Trigger [dbo].[USER_ROLE_INSERT_REPLICATION] Script Date: 01/03/2014 10:56:36 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author:
    -- Create date: 2014/02/01
    -- Description: Replication INSERT on MASTER DATABASE
    -- =============================================
    ALTER TRIGGER [dbo].[USER_ROLE_INSERT_REPLICATION]
    ON [TEST_MULTI].[dbo].[DM_USER_JOIN_USER_ROLE]
    AFTER INSERT
    AS
    DECLARE InsertCursor CURSOR FOR (SELECT FKUser, FKUserRole FROM inserted)
    DECLARE @UserId int, @UserRoleId int
    OPEN InsertCursor
    FETCH NEXT FROM InsertCursor INTO @UserId, @UserRoleId
    WHILE @@FETCH_STATUS = 0
    BEGIN
    DECLARE @UserMasterId int = (SELECT ExtIdUser FROM TEST_MULTI.dbo.DM_USER WHERE IdUser = @UserId)
    IF NOT EXISTS(SELECT * FROM DM_SECURITY_MASTER.dbo.DM_USER_JOIN_USER_ROLE WHERE FKUser = @UserMasterId
    AND FKUserRole = @UserRoleId)
    INSERT INTO DM_SECURITY_MASTER.dbo.DM_USER_JOIN_USER_ROLE (FKUser, FKUserRole) VALUES (@UserMasterId, @UserRoleId)
    FETCH NEXT FROM InsertCursor INTO @UserId, @UserRoleId
    END
    CLOSE InsertCursor;
    DEALLOCATE InsertCursor;
    And for DELETE
    USE [TEST_MULTI]
    GO
    /****** Object: Trigger [dbo].[USER_ROLE_DELETE_REPLICATION] Script Date: 01/03/2014 10:57:58 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author:
    -- Create date: 2014/02/01
    -- Description: Replicate DELETE on MASTER DATABASE
    -- =============================================
    ALTER TRIGGER [dbo].[USER_ROLE_DELETE_REPLICATION]
    ON [TEST_MULTI].[dbo].[DM_USER_JOIN_USER_ROLE]
    AFTER DELETE
    AS
    DECLARE DeleteCursor CURSOR FOR (SELECT FKUser, FKUserRole FROM deleted)
    DECLARE @UserId int, @UserRoleId int
    OPEN DeleteCursor
    FETCH NEXT FROM DeleteCursor INTO @UserId, @UserRoleId
    WHILE @@FETCH_STATUS = 0
    BEGIN
    DECLARE @UserMasterId int = (SELECT ExtIdUser FROM TEST_MULTI.dbo.DM_USER WHERE IdUser = @UserId)
    DELETE FROM DM_SECURITY_MASTER.dbo.DM_USER_JOIN_USER_ROLE WHERE FKUser = @UserMasterId AND FKUserRole = @UserRoleId
    FETCH NEXT FROM DeleteCursor INTO @UserId, @UserRoleId
    END
    CLOSE DeleteCursor;
    DEALLOCATE DeleteCursor;
    It works fine
    Thanks for help, I will mark it as answered

  • Joining Two Tables by Database View

    HI There,
    I'm trying to join two tables BNKA and LFBK to get the Bank details according to the requirement.
    Now, I wanted to go head and create a Generic datasource and bring the fields from these two tables by Vew.
    Can someone please explain me step by step to create the database view?
    One more thing, do we need to have anything in common between two tables BNKA and LFBK ?
    I really appreciate if someone can guide me through step by step method to create Database Table view?
    Thanks
    Madhuri

    Hi Madhuri,
    With out having common fields, we can not create data base view based on two tables.
    1) goto SE11
    2) select data base view and give the name and create.
    3) in left side give the tables names
    4)  In left side define the relation
    check the below article
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/10a89c00-7dd7-2d10-6f83-cd24ee6d517c?QuickLink=index&overridelayout=true
    Regards,
    Venkatesh

  • Can you join two DSO's?

    We have tried joining two DSO's and are getting the warning that "more than one datasource has been used in this report". It appears that the DSO driver does not support joins. The report runs but it is VERY slow, the same sort of performance you get when you try to join data from two datasources that are actually different (like two different SQL Server databases or an Oracle table joined to a SQL Server table). It appears that this is not a supported function with the DSO driver. Any thoughts?

    Yes, we have created the joins between the two DSOs. We are looking into using the Open SQL driver to go against the base tables to see if that will work.  This is how the original ODS driver used to work.
    Update: After changing the join type to a left outer join the performance improved signficantly. Although not ideal it looks like it will be fine for our requirements. This particular report will be run monthly and scheduled to run overnight.
    Edited by: Mike Garrett on Oct 27, 2009 4:28 PM

  • How can i compare two databases and their tables

    i have a text.txt file then
    i will insert it into db_header and db_details
    db_header has tbl_pcountheader with fld_Rack_No(char) PK and fld_DateAdded(date) PK
    db_details has tbl_pcountdetails with fld_Rack_No(char) PK, fld_Barcode(char) PK and fld_Quantity(int)
    then i will lookup in db_products
    db_products has tbl_products and tbl_barcodes
    tbl_products has fld_ItemCode
    tbl_barcodes has fld_Barcode and fld_ItemCode
    now i want to make a prompt contains
    Rack No: Date:
    Counter No:
    Barcode | Item Code | Item Description | Quantity
    how can i fill up this by comparing db_details and db_products?
    Private Sub bt_upload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_upload.Click
    If saveCheckBox.Checked = False Then
    MsgBox("Please click the box to continue.")
    Return
    End If
    If lb_file.SelectedItem Is Nothing Then
    MessageBox.Show("Please select a file.")
    Exit Sub
    End If
    ' Obtain the file path from the list box selection.
    Dim filePath = lb_file.SelectedItem.ToString
    ' Verify that the file was not removed since the Browse button was clicked.
    If System.IO.File.Exists(filePath) = False Then
    MessageBox.Show("File Not Found: " & filePath)
    Exit Sub
    End If
    ' Obtain file information in a string.
    Dim fileInfoText As String = GetTextForOutput(filePath)
    'LookUP db_header, db_details and db_products
    Dim cs As String = "Database=;Data Source=localhost;" _
    & "User Id=root;Password=1234"
    Dim conn As New MySqlConnection(cs)
    Dim ds As New DataSet
    Dim da As New MySqlDataAdapter
    Dim cmd As New MySqlCommand
    Dim dt As New DataTable
    Dim stm As String = "SELECT tbl_pcountheader.fld_Rack_No, tbl_pcountheader.fld_DateAdded, tbl_pcountdetails.fld_Barcode, tbl_products.fld_ItemCode, tbl_products.fld_ItemDesc, tbl_pcountdetails.fld_Quantity FROM db_header.tbl_pcountheader INNER JOIN db_details.tbl_pcountdetails ON db_details.tbl_pcountdetails.fld_Rack_No = db_header.tbl_pcountheader.fld_Rack_No INNER JOIN db_products.tbl_barcodes ON db_details.tbl_pcountdetails.fld_Barcode = db_products.tbl_barcodes.fld_Barcode INNER JOIN db_products.tbl_products ON db_products.tbl_barcodes.fld_ItemCode_fk = db_products.tbl_products.fld_ItemCode GROUP BY tbl_pcountheader.fld_Rack_No, tbl_pcountheader.fld_DateAdded ORDER BY tbl_pcountheader.fld_Rack_No"
    ds = New DataSet
    Try
    conn.Open()
    da = New MySqlDataAdapter(stm, conn)
    da.Fill(ds, "tbl_pcountheader")
    DataGridView1.DataSource = ds.Tables("tbl_pcountheader")
    Dim headers = (From header As DataGridViewColumn In DataGridView1.Columns.Cast(Of DataGridViewColumn)() _
    Select header.HeaderText).ToArray
    Dim rows = From row As DataGridViewRow In DataGridView1.Rows.Cast(Of DataGridViewRow)() _
    Where Not row.IsNewRow _
    Select Array.ConvertAll(row.Cells.Cast(Of DataGridViewCell).ToArray, Function(c) If(c.Value IsNot Nothing, c.Value.ToString, ""))
    Using sw As New IO.StreamWriter("c:\report.txt", append:=True)
    sw.WriteLine(String.Join(",", headers))
    For Each r In rows
    sw.WriteLine(String.Join(",", r))
    Next
    End Using
    ds.WriteXmlSchema("Sample.xml")
    Dim cr As New CrystalReport1()
    cr.SetDataSource(ds)
    CrystalReportviewer1.ReportSource = cr
    CrystalReportviewer1.Refresh()
    Catch ex As MySqlException
    MsgBox("Error: " & ex.ToString())
    Finally
    conn.Close()
    End Try
    ' Show the file information.
    Dim PrintPrompt As String
    PrintPrompt = MsgBox(fileInfoText, MsgBoxStyle.YesNo, "ProofList")
    If PrintPrompt = vbYes Then
    'fileInfoText.print()
    If saveCheckBox.Checked = True Then
    ' Place the log file in the same folder as the examined file.
    Dim bakFolder As String = System.IO.Path.GetDirectoryName(filePath)
    Dim bakFilePath = System.IO.Path.Combine(bakFolder, "back-up.bak")
    Dim bakText As String = "Backed-Up: " & Date.Now.ToString & vbCrLf & fileInfoText & vbCrLf & vbCrLf
    ' Append text to the log file.
    'System.IO.File.AppendAllText(bakFilePath, bakText)
    My.Computer.FileSystem.WriteAllText(bakFilePath, bakText, append:=True)
    'My.Computer.Network.UploadFile(bakFilePath, "C:\Documents and Settings\SAPC-TECH\My Documents\back-up file.bak", "", "", False, 1000)
    'My.Computer.FileSystem.DeleteFile(bakFilePath)
    'Form2.Show()
    End If
    'Note: This message box shows that you've uploaded a file and back up it.
    MessageBox.Show("Already backed-up to ")
    Else
    'Me.Close()
    'Application.Exit()
    'End
    End If
    'Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
    'Form2.Close()
    'Me.Close()
    End Sub
    here's my final code that solves my problem.
    i just make the environment of vb into mysql console
    so that i can call all the database that i wanted.

    Private Sub bt_upload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_upload.Click
    If saveCheckBox.Checked = False Then
    MsgBox("Please click the box to continue.")
    Return
    End If
    If lb_file.SelectedItem Is Nothing Then
    MessageBox.Show("Please select a file.")
    Exit Sub
    End If
    ' Obtain the file path from the list box selection.
    Dim filePath = lb_file.SelectedItem.ToString
    ' Verify that the file was not removed since the Browse button was clicked.
    If System.IO.File.Exists(filePath) = False Then
    MessageBox.Show("File Not Found: " & filePath)
    Exit Sub
    End If
    ' Obtain file information in a string.
    Dim fileInfoText As String = GetTextForOutput(filePath)
    'LookUP comparison db_details to db_products
    'Dim connString As String = "Database=db_products;Data Source=localhost;" & "User Id=root;Password=1234"
    'Dim conn As New MySqlConnection(connString)
    'Dim cmd As New MySqlCommand()
    'Try
    ' conn.Open()
    ' cmd.Connection = conn
    ' cmd.CommandText = "SELECT Database1.dbo.TableName.ColumnName, Database2TableName.Name, 'The reason why Database 2 isnt defined is the fact that it has been defined in the connection" _
    ' FROM Database2TableName INNER JOIN _
    ' Database2TableName2 INNER JOIN _
    ' WHERE (Database1.dbo.TableName.ColumnName = '')"
    ' cmd.Prepare()
    ' cmd.ExecuteNonQuery()
    ' conn.Close()
    'Catch ex As Exception
    'End Try
    ' Show the file information.
    Dim PrintPrompt As String
    PrintPrompt = MsgBox(fileInfoText, MsgBoxStyle.YesNo, "ProofList")
    If PrintPrompt = vbYes Then
    'fileInfoText.print()
    If saveCheckBox.Checked = True Then
    ' Place the log file in the same folder as the examined file.
    Dim bakFolder As String = System.IO.Path.GetDirectoryName(filePath)
    Dim bakFilePath = System.IO.Path.Combine(bakFolder, "back-up.bak")
    Dim bakText As String = "Backed-Up: " & Date.Now.ToString & vbCrLf & fileInfoText & vbCrLf & vbCrLf
    ' Append text to the log file.
    'System.IO.File.AppendAllText(bakFilePath, bakText)
    My.Computer.FileSystem.WriteAllText(bakFilePath, bakText, append:=True)
    'My.Computer.Network.UploadFile(bakFilePath, "C:\Documents and Settings\SAPC-TECH\My Documents\back-up file.bak", "", "", False, 1000)
    'My.Computer.FileSystem.DeleteFile(bakFilePath)
    Form2.Show()
    End If
    'Note: This message box shows that you've uploaded a file and back up it.
    MessageBox.Show("Already backed-up to ")
    Else
    Me.Close()
    Application.Exit()
    End
    End If
    Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
    Form2.Close()
    Me.Close()
    End Sub
    here's my code wherein i have to compare the two database and save it into .txt file
    i just have to get this items
    Rack No:
    Date:
    Counter No:
    Barcode:
    Item Code:
    Item Description:
    Quantity:
    as a prooflist to be print out.

  • Hyperion- Can it Connect to two database at a time

    Hi All,
    I am new to Hyperion Reporting and Analysis. Kindly help me in the following Scenario.
    Consider two database 'A' and 'B'
    I want to create a report from tables from Database "A" and "B"
    How to do that.
    Kindly Help me out
    Thanks in advance
    Regards
    Gatha

    For Interactive Reporting there are a couple options.
    1. Us the OBIEE BI Server and model your semantic layer with the connections. The Product is designed for Federated Queries.
    2. Build within Client
    - Query 1 for Database A
    - Query 2 for Database B
    - Qyery 3 using local results build the data model from Query Results A and B - Joined appropriately
    3. Depending on the Database - SQLServer, Oracle, DB2 etc you could connect to multiple DB within one OCE - You will need to look at Mark Ostroff's tips and tricks guide from previous Hyperion Conference for how to do it.
    Hope this is Helpful
    Wayne Van Sluys
    TopDown Consulting

  • How to prevent Oracle from using an index when joining two tables ...

    How to prevent Oracle from using an index when joining two tables to get an inline view which is used in an update statement?
    O.K. I think I have to explain what I mean:
    When joining two tables which have many entries sometimes it es better not to use an index on the column used as join criteria.
    I have two tables: table A and table B.
    Table A has 4.000.000 entries and table B has 700.000 entries.
    I have a join of both tables with a numeric column as join criteria.
    There is an index on this column in table A.
    So I instead of
      where (A.col = B.col)I want to use
      where (A.col+0 = B.col)in order to prevent Oracle from using the index.
    When I use the join in a select statement it works.
    But when I use the join as inline view in an update statement I get the error ORA-01779.
    When I remove the "+0" the update statement works. (The column col is unique in table B).
    Any ideas why this happens?
    Thank you very much in advance for any help.
    Regards Hartmut

    I think you should post an properly formatted explain plan output using DBMS_XPLAN.DISPLAY including the "Predicate Information" section below the plan to provide more details regarding your query resp. update statement. Please use the \[code\] and \[code\] tags to enhance readability of the output provided:
    In SQL*Plus:
    SET LINESIZE 130
    EXPLAIN PLAN FOR <your statement>;
    SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);Usually if you're using the CBO (cost based optimizer) and have reasonable statistics gathered on the database objects used the optimizer should be able to determine if it is better to use the existing index or not.
    Things look different if you don't have statistics, you have outdated/wrong statistics or deliberately still use the RBO (rule based optimizer). In this case you would have to use other means to prevent the index usage, the most obvious would be the already mentioned NO_INDEX or FULL hint.
    But I strongly recommend to check in first place why the optimizer apparently seems to choose an inappropriate index access path.
    Regards,
    Randolf
    Oracle related stuff:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle:
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Join two table in different instance

    Hi,
    I have two table in different instance .
    IMEI in instance A
    RCA_SMART_CARD in instance B
    Below is the desc table :
    SQL> desc RCA_SMART_CARD;
    Name Null? Type
    N_CARD_ID NOT NULL NUMBER(10)
    C_CARD_SERIAL_NUMBER NOT NULL VARCHAR2(20)
    C_SIM_MSISDN VARCHAR2(20)
    C_SIM_IMSI VARCHAR2(20)
    C_LINKED_CARD VARCHAR2(20)
    N_PRO_IDENTIFIER NOT NULL NUMBER(4)
    C_CARD_TYPE VARCHAR2(1)
    N_SIM_STATE NUMBER(1)
    N_EEPROM_SPACE_LEFT NUMBER(9)
    N_VOLATILE_SPACE_LEFT NUMBER(9)
    N_NONVOLATILE_SPACE_LEFT NUMBER(9)
    N_CARD_OPTI NOT NULL NUMBER(15)
    N_PRODUCT_ID NUMBER(10)
    D_CREATION_DATE DATE
    D_MODIFICATION_DATE DATE
    D_STATUS_MODIFICATION_DATE DATE
    SQL> desc IMEI;
    Name Null? Type
    MSISDN NOT NULL VARCHAR2(20)
    IMEI NOT NULL VARCHAR2(16)
    DATE_MOD NUMBER(13)
    IMSI VARCHAR2(18)
    ICCID VARCHAR2(20)
    T_PROF RAW(20)
    EXTRA_DATA VARCHAR2(100)
    If I want to join two table together .
    I want to search the number of record in IMEI that have N_SIM_STATE =1 in RCA_SMART_CARD .
    The MSISDN in IMEI is equal to C_SIM_MSISDN in RCA_SMART_CARD .
    How can I do and what is the sql statment ??
    Please advice .

    First you need to decide, from where you want to execute the query.
    Let us assume it is instance A(as per your example).
    Then what you need to do is:
    1.     Create database link to instance B
    *[url http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_5005.htm]Here* is the semantics.
    2.     After creating the database link to instance B, you can achieve the result set by running the below query:
            SQL> select count(*) from IMEI t1 join RCA_SMART_CARD@<db_link_name> t2 on t1.MSISDN = t2.C_SIM_MSISDN where t2.N_SIM_STATE = 1
            Hope it helps!
    Cheers,
    AA

  • Join two sites together

    Hi, i have two dynamic websites each connecting to two
    separate databases via separate connections. I have tried merging
    the two sites into one, but i get a problem because the database
    connection for one of the sites dont work after i join them. Can
    anyone please tell me the best way to join two dynamic sites
    together, so that both their databases work.
    thank you

    the best way to do it is to create a DSN connection but you
    have to make
    sure that they are on the same server
    if both the websites are on the same server that it can be
    easily done using
    DSN connection

  • Join two xmltype table using Xquery

    I am wondering how to join two xmltype tables in xml db database. both tables are schema based object-relational tables.
    these are the examples:
    academicProgram table contain batch of academicprogram.xml entries
    <academicProgram>
    <listOfCourse>
    <course><id>1</id></course>
    <course><id>2</id></course>
    </listOfCourse>
    </academicProgram>
    course table contain all the course entries, each of them is an xml file based on the the course schema. for example,
    course1.xml
    <course>
    <id>1</id>
    <title>xxxxxxx</title>
    <description>xxxxxxxxxxxxxx</description>
    </course>
    I used the following xquery code to merge the detailed course information from course table to the academic program information
    select *
    from XMLTable(
    for $program in ora:view("HTU", "ACADEMICPROGRAM")
    return <academicProgram xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog"
         for $node in $program/academicProgram/node()
         return if (name($node) eq "listOfCourse")
              then (
                   <listOfCourse>{
                   for $i in $node/course
                   for $j in ora:view("HTU", "COURSE")/course
                   where $i/id eq $j/id
                   return $j
                   }</listOfCourse>
              else $node
         </academicProgram>
    it did return what I want, but the problem is it take more than 5 minutes to finish. is there someway to make it run faster? I have been struggling for a week, please help.
    thanks in advance.
    Haili

    Does this work...
    SQL> var schemaURL varchar2(256)
    SQL> var schemaPath varchar2(256)
    SQL> --
    SQL> set autotrace on explain
    SQL> set lines 150 pages 0 long 10000
    SQL> --
    SQL> begin
      2    :schemaURL := 'http://aahmb10-147:7575/public/www.mdanderson.org/schema/APEP/custom.xsd';
      3    :schemaPath := '/public/custom.xsd';
      4  end;
      5  /
    PL/SQL procedure successfully completed.
    SQL> call dbms_xmlSchema.deleteSchema(:schemaURL,4)
      2  /
    Call completed.
    SQL> declare
      2    res boolean;
      3    xmlSchema xmlType := xmlType(
      4  '<xs:schema xmlns:apcustom="http://www.mdanderson.org/schema/APEP/custom" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="
    http://www.mdanderson.org/schema/APEP/custom" elementFormDefault="qualified" attributeFormDefault="unqualified">
      5    <xs:element name="CourseCatalogCustomDataType">
      6    <xs:annotation>
      7      <xs:documentation>Comment describing your root element</xs:documentation>
      8     </xs:annotation>
      9    </xs:element>
    10   </xs:schema>');
    11  begin
    12    if (dbms_xdb.existsResource(:schemaPath)) then
    13      dbms_xdb.deleteResource(:schemaPath);
    14    end if;
    15    res := dbms_xdb.createResource(:schemaPath,xmlSchema);
    16  end;
    17  /
    PL/SQL procedure successfully completed.
    SQL> begin
      2    dbms_xmlschema.registerSchema
      3    (
      4      :schemaURL,
      5      xdbURIType(:schemaPath).getClob(),
      6      TRUE,TRUE,FALSE,TRUE
      7    );
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    SQL> begin
      2    :schemaURL := 'http://aahmb10-147:7575/public/www.mdanderson.org/schema/APEP/courseCatalog.xsd';
      3    :schemaPath := '/public/courseCatalog.xsd';
      4  end;
      5  /
    PL/SQL procedure successfully completed.
    SQL> call dbms_xmlSchema.deleteSchema(:schemaURL,4)
      2  /
    Call completed.
    SQL> declare
      2    res boolean;
      3    xmlSchema xmlType := xmlType(
      4  '<?xml version="1.0" encoding="UTF-8"?>
      5  <!--  edited with XMLSpy v2006 rel. 3 U (http://www.altova.com) by John Grossman (UT MD Anderson Cancer Center)
      6    -->
      7  <xs:schema xmlns:xdb="http://xmlns.oracle.com/xdb" xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog" xmlns:xs="http://www.w3.
    org/2001/XMLSchema" xmlns:ns1="http://www.mdanderson.org/schema/APEP/custom" targetNamespace="http://www.mdanderson.org/schema/APEP/courseCa
    talog" elementFormDefault="qualified" attributeFormDefault="unqualified" xdb:storeVarrayAsTable="true">
      8     <xs:import namespace="http://www.mdanderson.org/schema/APEP/custom" schemaLocation="http://aahmb10-147:7575/public/www.mdanderson.or
    g/schema/APEP/custom.xsd"/>
      9     <!-- ########################################  -->
    10     <!-- GLOBAL ELEMENTS  -->
    11     <!-- ########################################  -->
    12     <xs:element name="course" type="CourseType" xdb:defaultTable="COURSE">
    13             <xs:annotation>
    14                     <xs:documentation>Comment describing your root element</xs:documentation>
    15             </xs:annotation>
    16     </xs:element>
    17     <xs:element name="listOfCourse" type="ListOfCourseType" xdb:defaultTable="COURSELIST"/>
    18     <xs:element name="courseCatalog" type="CourseCatalogType" xdb:defaultTable="COURSECATALOG"/>
    19     <!-- ########################################  -->
    20     <!-- GLOBAL TYPES  -->
    21     <!-- ########################################  -->
    22     <xs:complexType name="CompositeIDType" xdb:SQLType="COURSE_COMPOSITEID_T">
    23             <xs:sequence>
    24                     <xs:element name="prefix" xdb:SQLName="PREFIX">
    25                             <xs:simpleType>
    26                                     <xs:restriction base="xs:string">
    27                                             <xs:length value="2"/>
    28                                     </xs:restriction>
    29                             </xs:simpleType>
    30                     </xs:element>
    31                     <xs:element name="level" type="xs:positiveInteger" xdb:SQLName="COURSELEVEL"/>
    32                     <xs:element name="creditHours" type="xs:positiveInteger" xdb:SQLName="CREDITHOURS"/>
    33                     <xs:element name="identNumber" xdb:SQLName="IDENTNUMBER">
    34                             <xs:simpleType>
    35                                     <xs:restriction base="xs:string">
    36                                             <xs:length value="2"/>
    37                                     </xs:restriction>
    38                             </xs:simpleType>
    39                     </xs:element>
    40             </xs:sequence>
    41     </xs:complexType>
    42     <xs:complexType name="CourseType" xdb:SQLType="COURSE_T">
    43             <xs:sequence>
    44                     <xs:element name="id" type="xs:integer" minOccurs="0" xdb:SQLName="ID"/>
    45                     <xs:element name="compositeID" type="CompositeIDType" minOccurs="0" xdb:SQLName="COMPOSITEID"/>
    46                     <xs:element name="title" type="xs:string" minOccurs="0" xdb:SQLName="TITLE"/>
    47                     <xs:element name="description" type="xs:string" minOccurs="0" xdb:SQLName="DESCRIPTION"/>
    48                     <xs:element name="corequisite" type="CompositeIDType" minOccurs="0" maxOccurs="unbounded" xdb:SQLName="COREQUISITE"
    xdb:defaultTable=""/>
    49                     <xs:element name="prerequisite" type="CompositeIDType" minOccurs="0" maxOccurs="unbounded" xdb:SQLName="PREREQUISITE
    " xdb:defaultTable=""/>
    50                     <xs:element name="availability" minOccurs="0" xdb:SQLName="AVAILABILITY">
    51                             <xs:complexType>
    52                                     <xs:sequence>
    53                                             <xs:element name="startDate" type="xs:date" minOccurs="0" xdb:SQLName="STARTDATE"/>
    54                                             <xs:element name="endDate" type="xs:date" minOccurs="0" xdb:SQLName="ENDDATE"/>
    55                                     </xs:sequence>
    56                             </xs:complexType>
    57                     </xs:element>
    58             </xs:sequence>
    59     </xs:complexType>
    60     <xs:complexType name="ListOfCourseType" xdb:SQLType="COURSE_LIST_T">
    61             <xs:sequence minOccurs="0" maxOccurs="unbounded">
    62                     <xs:element name="id" type="xs:positiveInteger" minOccurs="0" xdb:SQLName="ID"/>
    63                     <xs:element ref="course" minOccurs="0"/>
    64             </xs:sequence>
    65     </xs:complexType>
    66     <xs:complexType name="CourseCatalogType" xdb:SQLType="COURSE_CATALOG_T">
    67             <xs:sequence minOccurs="0">
    68                     <xs:element name="id" type="xs:positiveInteger" minOccurs="0" xdb:SQLName="ID"/>
    69                     <xs:element ref="listOfCourse" minOccurs="0"/>
    70             </xs:sequence>
    71     </xs:complexType>
    72  </xs:schema>');
    73  begin
    74    if (dbms_xdb.existsResource(:schemaPath)) then
    75      dbms_xdb.deleteResource(:schemaPath);
    76    end if;
    77    res := dbms_xdb.createResource(:schemaPath,xmlSchema);
    78  end;
    79  /
    PL/SQL procedure successfully completed.
    SQL> begin
      2    dbms_xmlschema.registerSchema
      3    (
      4      :schemaURL,
      5      xdbURIType(:schemaPath).getClob(),
      6      TRUE,TRUE,FALSE,TRUE
      7    );
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    SQL> begin
      2    :schemaURL := 'http://aahmb10-147:7575/public/www.mdanderson.org/schema/APEP/academicProgram.xsd';
      3    :schemaPath := '/public/academicProgram.xsd';
      4  end;
      5  /
    PL/SQL procedure successfully completed.
    SQL> call dbms_xmlSchema.deleteSchema(:schemaURL,4)
      2  /
    Call completed.
    SQL> declare
      2    res boolean;
      3    xmlSchema xmlType := xmlType(
      4  '<?xml version="1.0" encoding="WINDOWS-1252"?>
      5  <!--  edited with XMLSpy v2006 rel. 3 U (http://www.altova.com) by John Grossman (UT MD Anderson Cancer Center)  -->
      6  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xdb="http://xmlns.oracle.com/xdb" xmlns:ap="http://www.mdanderson.org/sche
    ma/APEP/courseCatalog" targetNamespace="http://www.mdanderson.org/schema/APEP/courseCatalog" elementFormDefault="qualified" attributeFormDef
    ault="unqualified" xdb:storeVarrayAsTable="true">
      7   <xs:include schemaLocation="http://aahmb10-147:7575/public/www.mdanderson.org/schema/APEP/courseCatalog.xsd" />
      8   <!-- ########################################  -->
      9   <!-- GLOBAL ELEMENTS  -->
    10   <!-- ########################################  -->
    11   <xs:element name="academicProgram" type="ap:AcademicProgramType" xdb:defaultTable="ACADEMICPROGRAM">
    12   <xs:annotation>
    13                     <xs:documentation>Comment describing your root element</xs:documentation>
    14             </xs:annotation>
    15     </xs:element>
    16   <!-- ########################################  -->
    17   <!-- GLOBAL Types  -->
    18   <!-- ########################################  -->
    19     <xs:complexType name="ListOfAcademicCredentialType" xdb:SQLType="ACADEMICCREDENTIAL_LIST_T">
    20             <xs:sequence minOccurs="0" maxOccurs="unbounded">
    21                     <xs:element name="credential" type="ap:AcademicCredentialType" minOccurs="0" xdb:SQLName="CREDENTIAL"/>
    22             </xs:sequence>
    23     </xs:complexType>
    24     <xs:complexType name="AcademicCredentialType" xdb:SQLType="ACADEMICCREDENTIAL_T">
    25             <xs:sequence minOccurs="0">
    26                     <xs:element name="id" type="xs:integer" minOccurs="0" xdb:SQLName="ID"/>
    27                     <xs:element name="field" type="xs:string" minOccurs="0" xdb:SQLName="FIELD">
    28                             <xs:annotation>
    29                                     <xs:documentation>Academic or professional field for which the credential is granted. Example: Clini
    ical Laboratory Science</xs:documentation>
    30                             </xs:annotation>
    31                     </xs:element>
    32                     <xs:element name="typeCode" minOccurs="0" xdb:SQLName="TYPECODE">
    33                             <xs:annotation>
    34                                     <xs:documentation>The type of credential. Example: Bachelor of Science</xs:documentation>
    35                             </xs:annotation>
    36                             <xs:simpleType>
    37                                     <xs:restriction base="xs:string">
    38                                             <xs:enumeration value="Bachelor of Science Degree"/>
    39                                             <xs:enumeration value="Certificate"/>
    40                                     </xs:restriction>
    41                             </xs:simpleType>
    42                     </xs:element>
    43             </xs:sequence>
    44     </xs:complexType>
    45     <xs:complexType name="RequirementType" xdb:SQLType="ACADEMICPROGRAM_REQ_T">
    46             <xs:sequence minOccurs="0">
    47                     <xs:element name="typeCode" type="xs:string" minOccurs="0" xdb:SQLName="TYPECODE"/>
    48                     <xs:element name="description" type="xs:string" minOccurs="0" xdb:SQLName="DESCRIPTION"/>
    49                     <xs:element name="scope" type="xs:string" minOccurs="0" xdb:SQLName="SCOPE"/>
    50             </xs:sequence>
    51     </xs:complexType>
    52     <xs:complexType name="ListOfRequirementType" xdb:SQLType="ACADEMICPROGRAM_REQ_L_T">
    53             <xs:sequence minOccurs="0">
    54                     <xs:element name="requirement" type="ap:RequirementType" minOccurs="0" xdb:SQLName="REQUIREMENT"/>
    55             </xs:sequence>
    56     </xs:complexType>
    57     <xs:complexType name="AcademicProgramType" xdb:SQLType="ACADEMICPROGRAM_T">
    58             <xs:sequence>
    59                     <xs:element name="name" type="xs:string" minOccurs="0" xdb:SQLName="NAME"/>
    60                     <xs:element name="description" type="xs:string" minOccurs="0" xdb:SQLName="DESCRIPTION"/>
    61                     <xs:element name="listOfAcademicCredential" type="ap:ListOfAcademicCredentialType" minOccurs="0"/>
    62                     <xs:element name="listOfRelatedParty" minOccurs="0" xdb:SQLName="LISTOFRELATEDPARTY"/>
    63                     <xs:element name="mission" type="xs:string" minOccurs="0" xdb:SQLName="MISSION"/>
    64                     <xs:element name="goals" type="xs:string" minOccurs="0" xdb:SQLName="GOAL"/>
    65                     <xs:element name="objectives" type="xs:string" minOccurs="0" xdb:SQLName="OBJECTIVES"/>
    66                     <xs:element name="competencies" minOccurs="0" xdb:SQLName="COMPETENCIES"/>
    67                     <xs:element name="selectionProcess" minOccurs="0" xdb:SQLName="SELECTIONPROCESS"/>
    68                     <xs:element name="listOfRequirement" type="ap:ListOfRequirementType" minOccurs="0"/>
    69                     <xs:element name="evaluationCriteria" minOccurs="0" xdb:SQLName="EVALUATIONCRITERIA"/>
    70                     <xs:element name="postBaccDegreeInfo" minOccurs="0" xdb:SQLName="POSTBACCDEGREEINFO"/>
    71                     <xs:element name="postBaccCertificateInfo" minOccurs="0" xdb:SQLName="POSTBACCCERTIFICATEINFO"/>
    72                     <xs:element name="advancedPlacement" minOccurs="0" xdb:SQLName="ADVANCEDPLACEMENT"/>
    73                     <xs:element name="graduation" minOccurs="0" xdb:SQLName="GRADUATION"/>
    74                     <xs:element name="curriculum" minOccurs="0" xdb:SQLName="CURRICULUM"/>
    75                     <xs:element name="listOfCourse" type="ap:ListOfCourseType" minOccurs="0" xdb:SQLName="LISTOFCOURSE"/>
    76             </xs:sequence>
    77     </xs:complexType>
    78  </xs:schema>
    79  ');
    80  begin
    81    if (dbms_xdb.existsResource(:schemaPath)) then
    82      dbms_xdb.deleteResource(:schemaPath);
    83    end if;
    84    res := dbms_xdb.createResource(:schemaPath,xmlSchema);
    85  end;
    86  /
    PL/SQL procedure successfully completed.
    SQL> begin
      2    dbms_xmlschema.registerSchema
      3    (
      4      :schemaURL,
      5      xdbURIType(:schemaPath).getClob(),
      6      TRUE,TRUE,FALSE,TRUE
      7    );
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    SQL> insert into COURSE values ( xmltype(
      2  '<?xml version="1.0" encoding="WINDOWS-1252"?>
      3  <?altova_sps http://aahmb10-147:7575/public/www.mdanderson.org/template/APEP/courseInput.sps?>
      4  <course xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog" xmlns:ns1="http://www.mdanderson.org/schema/APEP/custom" xmlns:xdb=
    "http://xmlns.oracle.com/xdb" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mdanderson.org/schema/APE
    P/courseCatalog http://aahmb10-147:7575/public/www.mdanderson.org/schema/APEP/courseCatalog.xsd">
      5  <id>53</id>
      6  <compositeID>
      7  <prefix>CL</prefix>
      8  <level>4</level>
      9  <creditHours>1</creditHours>
    10  <identNumber>05</identNumber>
    11  </compositeID>
    12  <title>Urinalysis </title>
    13  <description>A review of the anatomy and physiology of the kidney and the formation, elimination, and composition of urine and body flu
    ids. Interpretation of urinary elements, chemical assays, and the correlation with normal and abnormal physiology.</description>
    14  </course>'))
    15  /
    1 row created.
    Execution Plan
    | Id  | Operation        | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | INSERT STATEMENT |      |     1 |   100 |     1   (0)| 00:00:01 |
    SQL> insert into COURSE values ( xmltype(
      2  '<?xml version="1.0" encoding="WINDOWS-1252"?>
      3  <?altova_sps http://aahmb10-147:7575/public/www.mdanderson.org/template/APEP/courseInput.sps?>
      4  <course xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog" xmlns:ns1="http://www.mdanderson.org/schema/APEP/custom" xmlns:xdb=
    "http://xmlns.oracle.com/xdb" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mdanderson.org/schema/APE
    P/courseCatalog http://aahmb10-147:7575/public/www.mdanderson.org/schema/APEP/courseCatalog.xsd">
      5  <id>54</id>
      6  <compositeID>
      7  <prefix>CL</prefix>
      8  <level>4</level>
      9  <creditHours>1</creditHours>
    10  <identNumber>05</identNumber>
    11  </compositeID>
    12  <title>Course 54</title>
    13  <description>A review of the anatomy and physiology of the kidney and the formation, elimination, and composition of urine and body flu
    ids. Interpretation of urinary elements, chemical assays, and the correlation with normal and abnormal physiology.</description>
    14  </course>'))
    15  /
    1 row created.
    Execution Plan
    | Id  | Operation        | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | INSERT STATEMENT |      |     1 |   100 |     1   (0)| 00:00:01 |
    SQL> insert into COURSE values ( xmltype(
      2  '<?xml version="1.0" encoding="WINDOWS-1252"?>
      3  <?altova_sps http://aahmb10-147:7575/public/www.mdanderson.org/template/APEP/courseInput.sps?>
      4  <course xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog" xmlns:ns1="http://www.mdanderson.org/schema/APEP/custom" xmlns:xdb=
    "http://xmlns.oracle.com/xdb" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mdanderson.org/schema/APE
    P/courseCatalog http://aahmb10-147:7575/public/www.mdanderson.org/schema/APEP/courseCatalog.xsd">
      5  <id>55</id>
      6  <compositeID>
      7  <prefix>CL</prefix>
      8  <level>4</level>
      9  <creditHours>1</creditHours>
    10  <identNumber>05</identNumber>
    11  </compositeID>
    12  <title>Course 55</title>
    13  <description>A review of the anatomy and physiology of the kidney and the formation, elimination, and composition of urine and body flu
    ids. Interpretation of urinary elements, chemical assays, and the correlation with normal and abnormal physiology.</description>
    14  </course>'))
    15  /
    1 row created.
    Execution Plan
    | Id  | Operation        | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | INSERT STATEMENT |      |     1 |   100 |     1   (0)| 00:00:01 |
    SQL> insert into ACADEMICPROGRAM values ( xmltype (
      2  '<?xml version="1.0" encoding="WINDOWS-1252"?>
      3  <!--Sample XML file generated by XMLSpy v2006 rel. 3 U (http://www.altova.com)-->
      4  <academicProgram xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog" xmlns:ns1="http://www.mdanderson.org/schema/APEP/custom" x
    mlns:xdb="http://xmlns.oracle.com/xdb" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mdanderson.org/s
    chema/APEP/courseCatalog http://aahmb10-147:7575/public/www.mdanderson.org/schema/APEP/academicProgram.xsd">
      5    <name>Clinical Laboratory Science</name>
      6    <description>The clinical laboratory scientist is an essential member of the health care team, performing a myriad of laboratory proc
    edures aimed at the diagnosis and treatment of disease.</description>
      7    <listOfAcademicCredential>
      8      <credential>
      9        <id>0</id>
    10        <field>String</field>
    11        <typeCode>Bachelor of Science Degree</typeCode>
    12      </credential>
    13      <credential>
    14        <id>0</id>
    15        <field>String</field>
    16        <typeCode>Bachelor of Science Degree</typeCode>
    17      </credential>
    18      <credential>
    19        <id>0</id>
    20        <field>String</field>
    21        <typeCode>Bachelor of Science Degree</typeCode>
    22      </credential>
    23    </listOfAcademicCredential>
    24    <listOfRelatedParty xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog"/>
    25    <mission>String</mission>
    26    <goals>String</goals>
    27    <objectives>String</objectives>
    28    <competencies xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog"/>
    29    <selectionProcess xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog"/>
    30    <listOfRequirement>
    31      <requirement>
    32        <typeCode>String</typeCode>
    33        <description>String</description>
    34        <scope>String</scope>
    35      </requirement>
    36    </listOfRequirement>
    37    <evaluationCriteria xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog"/>
    38    <postBaccDegreeInfo xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog"/>
    39    <postBaccCertificateInfo xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog"/>
    40    <advancedPlacement xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog"/>
    41    <graduation xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog"/>
    42    <curriculum xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog"/>
    43    <listOfCourse>
    44      <id>53</id>
    45      <course>
    46        <id>53</id>
    47        <compositeID>
    48          <prefix>CL</prefix>
    49          <level>4</level>
    50          <creditHours>1</creditHours>
    51          <identNumber>05</identNumber>
    52        </compositeID>
    53        <title>Biochemistry</title>
    54        <description>this is a test for the course biochemistry</description>
    55      </course>
    56      <course>
    57        <id>55</id>
    58        <compositeID>
    59          <prefix>CL</prefix>
    60          <level>4</level>
    61          <creditHours>1</creditHours>
    62          <identNumber>05</identNumber>
    63        </compositeID>
    64        <title>Something Else</title>
    65        <description>this is a test for the course biochemistry</description>
    66      </course>
    67    </listOfCourse>
    68  </academicProgram>'))
    69  /
    1 row created.
    Execution Plan
    | Id  | Operation        | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | INSERT STATEMENT |      |     1 |   100 |     1   (0)| 00:00:01 |
    SQL> select extractValue(value(c),'/course/id')
      2    from ACADEMICPROGRAM ap,
      3   table (xmlsequence(extract(value(ap),'/academicProgram/listOfCourse/course','xmlns="http://www.mdanderson.org/schema/APEP/courseCatalo
    g"'))) c
      4  /
                                     53
                                     55
    Execution Plan
    Plan hash value: 3351541143
    | Id  | Operation                    | Name               | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT             |                    |     2 |   126 |   804   (0)| 00:00:10 |
    |   1 |  NESTED LOOPS                |                    |     2 |   126 |   804   (0)| 00:00:10 |
    |*  2 |   INDEX FAST FULL SCAN       | SYS_IOT_TOP_177341 |     2 |    66 |   802   (0)| 00:00:10 |
    |*  3 |   TABLE ACCESS BY INDEX ROWID| ACADEMICPROGRAM    |     1 |    30 |     1   (0)| 00:00:01 |
    |*  4 |    INDEX UNIQUE SCAN         | SYS_C0022632       |     1 |       |     0   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - filter("SYS_NC_TYPEID$" IS NOT NULL)
       3 - filter(SYS_CHECKACL("ACLOID","OWNERID",xmltype('<privilege
                  xmlns="http://xmlns.oracle.com/xdb/acl.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-ins
                  tance" xsi:schemaLocation="http://xmlns.oracle.com/xdb/acl.xsd
                  http://xmlns.oracle.com/xdb/acl.xsd DAV:http://xmlns.oracle.com/xdb/dav.xsd"><read-properti
                  es/><read-contents/></privilege>'))=1)
       4 - access("NESTED_TABLE_ID"="ACADEMICPROGRAM"."SYS_NC0004200043$")
    Note
       - dynamic sampling used for this statement
    SQL> select updateXML
      2         (
      3            ap.object_value,
      4            '/academicProgram/listOfCourse',
      5            ( select xmlelement
      6                     (
      7                       "listOfCourse",
      8                       xmlattributes('http://www.mdanderson.org/schema/APEP/courseCatalog' as "xmlns"),
      9                       ( select xmlagg ( xmlconcat(extract(object_value,'/course/id'), extract(object_value,'/course'))  )
    10                             from course c,
    11                            table (xmlsequence(extract(ap.object_value,'/academicProgram/listOfCourse/course','xmlns="http://www.mdanders
    on.org/schema/APEP/courseCatalog"'))) api
    12                            where extractValue(c.object_value,'/course/id') = extractValue(value(api),'/course/id')
    13                       )
    14                     ) from dual
    15            ),
    16            'xmlns:="http://www.mdanderson.org/schema/APEP/courseCatalog"'
    17          )
    18     from ACADEMICPROGRAM ap
    19  /
    <?xml version="1.0" encoding="WINDOWS-1252"?>
    <!--Sample XML file generated by XMLSpy v2006 rel. 3 U (http://www.altova.com)--><academicProgram xmlns="http://www.mdanderson.org/schema/AP
    EP/courseC
    atalog" xmlns:ns1="http://www.mdanderson.org/schema/APEP/custom" xmlns:xdb="http://xmlns.oracle.com/xdb" xmlns:xsi="http://www.w3.org/2001/X
    MLSchema-i
    nstance" xsi:schemaLocation="http://www.mdanderson.org/schema/APEP/courseCatalog http://aahmb10-147:7575/public/www.mdanderson.org/schema/AP
    EP/academi
    cProgram.xsd">
      <name>Clinical Laboratory Science</name>
      <description>The clinical laboratory scientist is an essential member of the health care team, performing a myriad of laboratory procedure
    s aimed at
    the diagnosis and treatment of disease.</description>
      <listOfAcademicCredential>
        <credential>
          <id>0</id>
          <field>String</field>
          <typeCode>Bachelor of Science Degree</typeCode>
        </credential>
        <credential>
          <id>0</id>
          <field>String</field>
          <typeCode>Bachelor of Science Degree</typeCode>
        </credential>
        <credential>
          <id>0</id>
          <field>String</field>
          <typeCode>Bachelor of Science Degree</typeCode>
        </credential>
      </listOfAcademicCredential>
      <listOfRelatedParty xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog"/>
      <mission>String</mission>
      <goals>String</goals>
      <objectives>String</objectives>
      <competencies xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog"/>
      <selectionProcess xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog"/>
      <listOfRequirement>
        <requirement>
          <typeCode>String</typeCode>
          <description>String</description>
          <scope>String</scope>
        </requirement>
      </listOfRequirement>
      <evaluationCriteria xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog"/>
      <postBaccDegreeInfo xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog"/>
      <postBaccCertificateInfo xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog"/>
      <advancedPlacement xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog"/>
      <graduation xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog"/>
      <curriculum xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog"/>
      <listOfCourse xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog">
        <id xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog">53</id>
        <course xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog" xmlns:ns1="http://www.mdanderson.org/schema/APEP/custom" xmlns:xdb="
    http://xml
    ns.oracle.com/xdb" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mdanderson.org/schema/APEP/courseCat
    alog http:
    //aahmb10-147:7575/public/www.mdanderson.org/schema/APEP/courseCatalog.xsd">
          <id>53</id>
          <compositeID>
            <prefix>CL</prefix>
            <level>4</level>
            <creditHours>1</creditHours>
            <identNumber>05</identNumber>
          </compositeID>
          <title>Urinalysis </title>
          <description>A review of the anatomy and physiology of the kidney and the formation, elimination, and composition of urine and body fl
    uids. Inte
    rpretation of urinary elements, chemical assays, and the correlation with normal and abnormal physiology.</description>
        </course>
        <id xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog">55</id>
        <course xmlns="http://www.mdanderson.org/schema/APEP/courseCatalog" xmlns:ns1="http://www.mdanderson.org/schema/APEP/custom" xmlns:xdb="
    http://xml
    ns.oracle.com/xdb" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mdanderson.org/schema/APEP/courseCat
    alog http:
    //aahmb10-147:7575/public/www.mdanderson.org/schema/APEP/courseCatalog.xsd">
          <id>55</id>
          <compositeID>
            <prefix>CL</prefix>
            <level>4</level>
            <creditHours>1</creditHours>
            <identNumber>05</identNumber>
          </compositeID>
          <title>Course 55</title>
          <description>A review of the anatomy and physiology of the kidney and the formation, elimination, and composition of urine and body fl
    uids. Inte
    rpretation of urinary elements, chemical assays, and the correlation with normal and abnormal physiology.</description>
        </course>
      </listOfCourse>
    </academicProgram>
    Execution Plan
    Plan hash value: 1698158615
    | Id  | Operation           | Name               | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT    |                    |     1 | 47932 |     3   (0)| 00:00:01 |
    |   1 |  SORT AGGREGATE     |                    |     1 | 13818 |            |          |
    |*  2 |   HASH JOIN         |                    |     1 | 13818 |     5  (20)| 00:00:01 |
    |*  3 |    INDEX RANGE SCAN | SYS_IOT_TOP_177341 |     1 |    33 |     2   (0)| 00:00:01 |
    |*  4 |    TABLE ACCESS FULL| COURSE             |     3 | 41355 |     3   (0)| 00:00:01 |
    |   5 |  FAST DUAL          |                    |     1 |       |     2   (0)| 00:00:01 |
    |*  6 |  TABLE ACCESS FULL  | ACADEMICPROGRAM    |     1 | 47932 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("COURSE"."SYS_NC00009$"="ID")
       3 - access("NESTED_TABLE_ID"=:B1)
           filter("SYS_NC_TYPEID$" IS NOT NULL)
       4 - filter(SYS_CHECKACL("ACLOID","OWNERID",xmltype('<privilege
                  xmlns="http://xmlns.oracle.com/xdb/acl.xsd"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://xmlns.oracle.com/xdb/acl.xsd
                  http://xmlns.oracle.com/xdb/acl.xsd DAV:http://xmlns.oracle.com/xdb/dav.xsd"><read
                  -properties/><read-contents/></privilege>'))=1)
       6 - filter(SYS_CHECKACL("ACLOID","OWNERID",xmltype('<privilege
                  xmlns="http://xmlns.oracle.com/xdb/acl.xsd"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://xmlns.oracle.com/xdb/acl.xsd
                  http://xmlns.oracle.com/xdb/acl.xsd DAV:http://xmlns.oracle.com/xdb/dav.xsd"><read
                  -properties/><read-contents/></privilege>'))=1)
    Note
       - dynamic sampling used for this statement
    SQL>

  • OBIEE - table join across databases

    Hi,
    I want to join two tables that are in different databases. I want to join these tables on some condition and then be able to see data from both of them in the reports.
    Table 1 - columns A1, B1, C1
    Table 2 - columns A2, B2, D2
    Currently what we tried is
    1. create foreign key constraint between the two tables in the physical layer. Map A1 to A2, B1 to B2.
    2. create a join of two tables in BMM layer and then port that to presentation layer and then make report using these columns.
    OR
    try the approach as described on link http://oraclebizint.wordpress.com/2008/03/19/oracle-bi-ee-101332-cross-database-joins/
    in both the above mentioned ways, we are not able to see join of two tables. The link mentioned above doesn't work as we tried it multiple times already.
    We are able to see individual data from each table, but when we try to see data from them together, we get error.
    Can someone help us with this problem.
    Please email me on [email protected] if you need more info as i cant paste the confidential data here on the forum.
    Thanks in advance,
    Amit

    We made sure that the datatypes are the same in both tables.
    I will explain a bit how we did it.
    We have table T1 in database d1, table t2 in database d2. Since datatypes are different there, we actually had to create tables in physical layer and used select query to extract data from databases and get that into those tables in proper format. For example we had to do mapping to make the values of some parameters consistent (like BABY in T1 and CHILD in T2, so we used 'case when T1.parameter1='BABY' then 'CHILD' and so on for other columns).
    After that we defined forgein key constraints between these tables, then ported them to BMM layer, then to presentation layer.
    We are not getting error in terms on data types. Is there a step by step guide we can follow to get this cross database join.
    Regards,
    Amit

Maybe you are looking for

  • SRM-MDM Catalog image mapping

    Dear All, I am trying to map image field but the field does not appears on the web dynpro user interface, can anyone advise me how to map image field in order to display the images in SRM. And I am using standard Repository SRM-MDM. Regards, Aklilu

  • Batch Derivation in 4.6C

    Dear Gurus, Please guide if any one has implemented the functionality of Batch Derivation in 4.6c version. SAP provides this as a hidden fuctinality for this version. I have referred the related notes regarding it but would like to know more about ho

  • Send and Retrieve POP3 Email

    Hi, I want to send and retrieve emails using POP3. I tried searching for the same on the forum, but the download links are not working. Kindly help in this regard. Regards Gagan

  • My iPhone 4 lost all apps after iOS 6 update, and can't reinstall them!

    After updating to iOS 6, I can't install apps I've bought before.. I can only open them through App Store.. Stupid!! And safari can't ever find any web pages when on wifi... Seems like iOS 6 is having some bugs after reading this forum and by my own

  • I cannot get the photoshop download to start from the order page - any ideas?

    i cannot get the photoshop download to start from the order page - any ideas?