Parent - child tables foreign key relation ship

Hi All,
we have 600 hundred tables ..i would like to print a hierarchial tree based on the foreigh key relathionship
i tried my best but i couldnt.
parent table
child table 1
childtable3
child table 2
and so
Can somebody help me out with a query?
Thanks,
kt

CREATE OR REPLACE FUNCTION get_child_tables (
ptable VARCHAR2,
powner VARCHAR2 DEFAULT 'SCOTT',
plevel NUMBER DEFAULT 10
RETURN stringarray
-- -- create this ON SQL*PLUS "CREATE OR REPLACE TYPE STRINGARRAY AS TABLE OF VARCHAR2(50);"
-- AUTHID CURRENT_USER
PIPELINED
AUTHOR DATE VERSION COMMENTS
======================================================================================
[email protected] 26-OCT-2009 1.0 Developed to ease developers effort to find Nth level of Referential integrity
======================================================================================
-- PURPOSE -> To find PARENT=> CHILD relational TABLE(S) in Oracle upto a depth max N Level.
--SYNTAX TO USE
SELECT * FROM TABLE( get_child_tables('DEPT','SCOTT',3)); Store this query in a file for your use
SELECT * FROM TABLE( get_child_tables('EMPLOYEE')); Store this query in a file for your use
-- RESULTS looks as below
--1 => DEPT
--2 => EMP
--2 => EMP2
--3 => EMP_CHILD
--3 => EMP2_CHILD
-- and so on
--This can be leveraged to use in any oracle database REGION 10g having and above.
--This FUNCTION gives formatted result of the Oracle 10g Hierarchical query result coded in the cursor
--to find MASTER => CHILD relational TABLE(S) upto a depth max 10 Level.
--The result of the PIPELINED function can be retrieved using Oracle new operator
--TABLE(array name) in SQL query.
--Due to the AUTHID CURRENT_USER compiler directive any user can use based on his/her access privileges on the database.
--GRANT EXECUTE ON SCOTT.get_child_tables TO PUBLIC;
--CREATE OR REPLACE PUBLIC SYNONYM get_child_tables FOR SCOTT.get_child_tables;
IS
atname stringarray := stringarray ();
-- create this ON SQL*PLUS CREATE OR REPLACE TYPE STRINGARRAY AS TABLE OF VARCHAR2(50);
vlevel NUMBER;
vtname VARCHAR2 (50);
nindex NUMBER := 0;
bprocessed BOOLEAN := FALSE;
CURSOR c1 (powner_in IN VARCHAR2, ptable_in VARCHAR2, plevel_in NUMBER)
IS
SELECT LEVEL, LPAD (' ', (LEVEL - 1) * 2, ' ') || pt AS "TNAME"
FROM (SELECT a.owner w1, a.table_name pt, a.constraint_name c1,
a.r_constraint_name r1, b.owner w2, b.table_name ct,
b.constraint_name c2, b.r_constraint_name r2
FROM all_constraints a, all_constraints b
WHERE a.constraint_name = b.r_constraint_name(+)
AND a.owner = b.owner(+)
AND a.owner =
UPPER (powner)
-- Change Owner here while testing
--AND A.r_constraint_name IS NULL
AND a.constraint_type IN ('P', 'R')) v1
START WITH pt =
UPPER
(ptable)
-- Change your master table here while testing the QUERY
CONNECT BY PRIOR ct = pt AND LEVEL <= plevel;
-- Change lavel here while testing
BEGIN
atname.EXTEND;
atname (1) := 'NOTHING';
OPEN c1 (powner, ptable, plevel);
LOOP
bprocessed := FALSE;
FETCH c1
INTO vlevel, vtname;
IF nindex > 1 AND atname (atname.LAST - 1) = vtname
THEN
--DBMS_OUTPUT.PUT_LINE('2 ==== vtname  ' ||vtname || '   '|| atname.count|| '   '||atname.last ||  '   '||atname( atname.last-1));
bprocessed := TRUE;
END IF;
IF NOT bprocessed
THEN
nindex := nindex + 1;
atname.EXTEND;
atname (nindex) := vtname;
PIPE ROW (vlevel || ' => ' || vtname);
DBMS_OUTPUT.put_line ( ' **** nindex - atname( nindex) '
|| nindex
|| ' - '
|| atname (nindex)
DLOG('ADDING ',vTname); A LOGGING ATONOMUS PROCEDURE FOR DEBUG PURPOSE
END IF;
EXIT WHEN c1%NOTFOUND;
END LOOP;
CLOSE c1;
FOR i IN 1 .. atname.COUNT
LOOP
DBMS_OUTPUT.PUT_LINE('atname (i) ' ||atname (i));
END LOOP;
RETURN;
EXCEPTION
WHEN no_data_needed
THEN -- THIS EXCEPTION HAS TO BE THERE TO GET THE FUCTION WORKABLE
DBMS_OUTPUT.put_line (SQLERRM);
RETURN;
END get_child_tables;
/

Similar Messages

  • How to find the level of each child table in a relational model?

    Earthlings,
    I need your help and I know that, 'yes, we can change'. Change this thread to a answered question.
    So: How to find the level of each child table in a relational model?
    I have a relacional database (9.2), all right?!
         O /* This is a child who makes N references to each of the follow N parent tables (here: three), and so on. */
        /↑\ Fks
       O"O O" <-- level 2 for first table (circle)
      /↑\ Fks
    "o"o"o" <-- level 1 for middle table (circle)
       ↑ Fk
      "º"Tips:
    - each circle represents a table;
    - red tables no have foreign key
    - the table in first line of tree, for example, has level 3, but when 3 becomes N? How much is N? This's the question.
    I started thinking about the following:
    First I have to know how to take the children:
    select distinct child.table_name child
      from all_cons_columns father
      join all_cons_columns child
    using (owner, position)
      join (select child.owner,
                   child.constraint_name fk,
                   child.table_name child,
                   child.r_constraint_name pk,
                   father.table_name father
              from all_constraints father, all_constraints child
             where child.r_owner = father.owner
               and child.r_constraint_name = father.constraint_name
               and father.constraint_type in ('P', 'U')
               and child.constraint_type = 'R'
               and child.owner = 'OWNER') aux
    using (owner)
    where child.constraint_name = aux.fk
       and child.table_name = aux.child
       and father.constraint_name = aux.pk
       and father.table_name = aux.father;Thinking...
    Let's Share!
    My thanks in advance,
    Philips
    Edited by: BluShadow on 01-Apr-2011 15:08
    formatted the code and the hierarchy for readbility

    Justin,
    Understood.
    Nocycle not work in 9.2 and, even that would work, would not be appropriate.
    With your help, I decided a much simpler way (but there is still a small problem, <font color=red>IN RED</font>):
    -- 1
    declare
      type udt_roles is table of varchar2(30) index by pls_integer;
      cRoles udt_roles;
    begin
      execute immediate 'create user philips
        identified by philips';
      select granted_role bulk collect
        into cRoles
        from user_role_privs
       where username = user;
      for i in cRoles.first .. cRoles.count loop
        execute immediate 'grant ' || cRoles(i) || ' to philips';
      end loop;
    end;
    -- 2
    create table philips.root1(root1_id number,
                               constraint root1_id_pk primary key(root1_id)
                               enable);
    grant all on philips.root1 to philips;
    create or replace trigger philips.tgr_root1
       before delete or insert or update on philips.root1
       begin
         null;
       end;
    create table philips.root2(root2_id number,
                               constraint root2_id_pk primary key(root2_id)
                               enable);
    grant all on philips.root2 to philips;
    create or replace trigger philips.tgr_root2
       before delete or insert or update on philips.root2
       begin
         null;
       end;
    create table philips.node1(node1_id number,
                               root1_id number,
                               node2_id number,
                               node4_id number,
                               constraint node1_id_pk primary key(node1_id)
                               enable,
                               constraint n1_r1_id_fk foreign key(root1_id)
                               references philips.root1(root1_id) enable,
                               constraint n1_n2_id_fk foreign key(node2_id)
                               references philips.node2(node2_id) enable,
                               constraint n1_n4_id_fk foreign key(node4_id)
                               references philips.node4(node4_id) enable);
    grant all on philips.node1 to philips;
    create or replace trigger philips.tgr_node1
       before delete or insert or update on philips.node1
       begin
         null;
       end;
    create table philips.node2(node2_id number,
                               root1_id number,
                               node3_id number,
                               constraint node2_id_pk primary key(node2_id)
                               enable,
                               constraint n2_r1_id_fk foreign key(root1_id)
                               references philips.root1(root1_id) enable,
                               constraint n2_n3_id_fk foreign key(node3_id)
                               references philips.node3(node3_id) enable);
    grant all on philips.node2 to philips;
    create or replace trigger philips.tgr_node2
       before delete or insert or update on philips.node2
       begin
         null;
       end;                          
    create table philips.node3(node3_id number,
                               root2_id number,
                               constraint node3_id_pk primary key(node3_id)
                               enable,
                               constraint n3_r2_id_fk foreign key(root2_id)
                               references philips.root2(root2_id) enable);
    grant all on philips.node3 to philips;
    create or replace trigger philips.tgr_node3
       before delete or insert or update on philips.node3
       begin
         null;
       end;                          
    create table philips.node4(node4_id number,
                               node2_id number,
                               constraint node4_id_pk primary key(node4_id)
                               enable,
                               constraint n4_n2_id_fk foreign key(node2_id)
                               references philips.node2(node2_id) enable);
    grant all on philips.node4 to philips;
    create or replace trigger philips.tgr_node4
       before delete or insert or update on philips.node4
       begin
         null;
       end;                          
    -- out of the relational model
    create table philips.node5(node5_id number,
                               constraint node5_id_pk primary key(node5_id)
                               enable);
    grant all on philips.node5 to philips;
    create or replace trigger philips.tgr_node5
       before delete or insert or update on philips.node5
       begin
         null;
       end;
    -- 3
    create table philips.dictionary(table_name varchar2(30));
    insert into philips.dictionary values ('ROOT1');
    insert into philips.dictionary values ('ROOT2');
    insert into philips.dictionary values ('NODE1');
    insert into philips.dictionary values ('NODE2');
    insert into philips.dictionary values ('NODE3');
    insert into philips.dictionary values ('NODE4');
    insert into philips.dictionary values ('NODE5');
    --4
    create or replace package body philips.pck_restore_philips as
      procedure sp_select_tables is
        aExportTablesPhilips     utl_file.file_type := null; -- file to write DDL of tables   
        aExportReferencesPhilips utl_file.file_type := null; -- file to write DDL of references
        aExportIndexesPhilips    utl_file.file_type := null; -- file to write DDL of indexes
        aExportGrantsPhilips     utl_file.file_type := null; -- file to write DDL of grants
        aExportTriggersPhilips   utl_file.file_type := null; -- file to write DDL of triggers
        sDirectory               varchar2(100) := '/app/oracle/admin/tace/utlfile'; -- directory \\bmduhom01or02 
        cTables                  udt_tables; -- collection to store table names for the relational depth
      begin
        -- omits all referential constraints:
        dbms_metadata.set_transform_param(dbms_metadata.session_transform, 'REF_CONSTRAINTS', false);
        -- omits segment attributes (physical attributes, storage attributes, tablespace, logging):
        dbms_metadata.set_transform_param(dbms_metadata.session_transform, 'SEGMENT_ATTRIBUTES', false);
        -- append a SQL terminator (; or /) to each DDL statement:
        dbms_metadata.set_transform_param(dbms_metadata.session_transform, 'SQLTERMINATOR', true);
        -- create/open files for export DDL:
        aExportTablesPhilips := utl_file.fopen(sDirectory, 'DDLTablesPhilips.pdc', 'w', 32767);
        aExportReferencesPhilips := utl_file.fopen(sDirectory, 'DDLReferencesPhilips.pdc', 'w', 32767);
        aExportIndexesPhilips := utl_file.fopen(sDirectory, 'DDLIndexesPhilips.pdc', 'w', 32767);
        aExportGrantsPhilips := utl_file.fopen(sDirectory, 'DDLGrantsPhilips.pdc', 'w', 32767);
        aExportTriggersPhilips := utl_file.fopen(sDirectory, 'DDLTriggersPhilips.pdc', 'w', 32767);
        select d.table_name bulk collect
          into cTables -- collection with the names of tables in the schema philips
          from all_tables t, philips.dictionary d
         where owner = 'PHILIPS'
           and t.table_name = d.table_name;
        -- execution
        sp_seeks_ddl(aExportTablesPhilips,
                     aExportReferencesPhilips,
                     aExportIndexesPhilips,
                     aExportGrantsPhilips,
                     aExportTriggersPhilips,
                     cTables);
        -- closes all files
        utl_file.fclose_all;
      end sp_select_tables;
      procedure sp_seeks_ddl(aExportTablesPhilips     in utl_file.file_type,
                             aExportReferencesPhilips in utl_file.file_type,
                             aExportIndexesPhilips    in utl_file.file_type,
                             aExportGrantsPhilips     in utl_file.file_type,
                             aExportTriggersPhilips   in utl_file.file_type,
                             cTables                  in out nocopy udt_tables) is
        cDDL       clob := null; -- colletion to save DDL
        plIndex    pls_integer := null;
        sTableName varchar(30) := null;
      begin
        for i in cTables.first .. cTables.count loop
          plIndex    := i;
          sTableName := cTables(plIndex);
           * Retrieves the DDL and the dependent DDL into cDDL clob       *      
          * for the selected table in the collection, and writes to file.*
          begin
            cDDL := dbms_metadata.get_ddl('TABLE', sTableName, 'PHILIPS');
            sp_writes_ddl(aExportTablesPHILIPS, cDDL);
          exception
            when dbms_metadata.object_not_found then
              null;
          end;
          begin
            cDDL := dbms_metadata.get_dependent_ddl('REF_CONSTRAINT', sTableName, 'PHILIPS');
            sp_writes_ddl(aExportReferencesPhilips, cDDL);
          exception
            when dbms_metadata.object_not_found2 then
              null;
          end;
          begin
            cDDL := dbms_metadata.get_dependent_ddl('INDEX', sTableName, 'PHILIPS');
            sp_writes_ddl(aExportIndexesPhilips, cDDL);
          exception
            when dbms_metadata.object_not_found2 then
              null;
          end;
          begin
            cDDL := dbms_metadata.get_dependent_ddl('OBJECT_GRANT', sTableName, 'PHILIPS');
            sp_writes_ddl(aExportGrantsPhilips, cDDL);
          exception
            when dbms_metadata.object_not_found2 then
              null;
          end;
          begin
            cDDL := dbms_metadata.get_dependent_ddl('TRIGGER', sTableName, 'PHILIPS');
            sp_writes_ddl(aExportTriggersPhilips, cDDL);
          exception
            when dbms_metadata.object_not_found2 then
              null;
          end;
        end loop;
      end sp_seeks_ddl;
      procedure sp_writes_ddl(aExport in utl_file.file_type,
                              cDDL    in out nocopy clob) is
        pLengthDDL  pls_integer := length(cDDL);
        plQuotient  pls_integer := null;
        plRemainder pls_integer := null;
      begin
          * Register variables to control the amount of lines needed   *
         * for each DDL and the remaining characters to the last row. *
        select trunc(pLengthDDL / 32766), mod(pLengthDDL, 32766)
          into plQuotient, plRemainder
          from dual;
          * Join DDL in the export file.                            *
         * ps. 32766 characters + 1 character for each line break. *
        -- if the size of the DDL is greater than or equal to limit the line ...
        if plQuotient >= 1 then
          -- loops for substring (lines of 32766 characters + 1 break character):
          for i in 1 .. plQuotient loop
            utl_file.put_line(aExport, substr(cDDL, 1, 32766));
            -- removes the last line, of clob, recorded in the buffer:
            cDDL := substr(cDDL, 32767, length(cDDL) - 32766);
          end loop;
        end if;
          * If any remains or the number of characters is less than the threshold (quotient = 0), *
         * no need to substring.                                                                 *
        if plRemainder > 0 then
          utl_file.put_line(aExport, cDDL);
        end if;
        -- record DDL buffered in the export file:
        utl_file.fflush(aExport);
      end sp_writes_ddl;
    begin
      -- executes main procedure:
      sp_select_tables;
    end pck_restore_philips;<font color="red">The problem is that I still have ...
    When creating the primary key index is created and this is repeated in the file indexes.
    How to avoid?</font>

  • SHOW THE PARENT CHILD TABLE RELATIONSHIP TABLE

    hi experts,
    I want show the parent child relation ship tables
    for exmple iam passing the emp table then display related child tables like dept,grade after that again child table(dept,grade) related to child relationship tables like recursive
    Regards,
    VENKAT

    Probably something like below. This may not be exactly what you are looking for, but one way to get what you are asking for.
    Only if you can give specifics, of your Input being passed and the Output, it might be possible to provide more help. But you also need to help us with your best effort on this.
    select *
      from (
            select prior table_name Child, table_name Parent
              from user_constraints
             start with constraint_name = some_constraint_name_of_Parent_Table
            connect by constraint_name = prior r_constraint_name
           ) a
    where a.child is not null;

  • Loading to Parent -Child Tables simultaneously

    I have a requirement to populate parent-child tables in a single interface simultaneoulsy. I couldnt find anyway to add multiple targets and am wondering why this key feature is absent in ODI. The same thing is easily achievable in BPEL.
    Could some one please advice a work around for this.
    Your help is much appreaciated

    ODI 11g does come with a new IKM 'IKM Oracle Multi Table Insert'. This does allow multi table inserts, but will require more than one interface.
    Oracle Multi-Table Inserts
    A new Integration KM for Oracle allows populating several target tables from a single source, reading the data only once. It uses the INSERT ALL statement.
    COMPONENT NAME: IKM Oracle Multi Table Insert
    COMPONENT VERSION: 11.1.2.4
    AUTHOR: Oracle
    COMPATIBILITY: ODI 11.1.1.3 and above
    DESCRIPTION:
         - Integrates data from one source into one to many Oracle target tables in append mode, using a multi-table insert statement (MTI).
    REQUIREMENTS:
         - Oracle Database 9iR1 or above
         - See BASIC CONFIGURATION section
    BASIC CONFIGURATION
         - This IKM must be used in integration interfaces that are sequenced in a Package:
              - The first interface of the Package must have a temporary target and the KM option DEFINE_QUERY set to YES.
              This first interface defines the structure of the SELECT clause of the multi-table insert statement (that is the source flow).
              - Subsequent integration interfaces must source from this temporary datastore and have the KM option IS_TARGET_TABLE set to YES.
              - The last interface of the Package must have the KM option EXECUTE set to YES in order to run the multi-table insert statement.
              - Do not set "Use Temporary Interface as Derived Table(Sub-Select)" set to true on any of the interfaces.
         - If large amounts of data are appended, consider to set the KM option OPTIMIZER_HINT to /*+ APPEND */.
    OPTIONS (Refer to the Option descriptions for more information on each option)
         - DEFINE_QUERY: Set to Yes if this interface describes the source query (SELECT clause of the statement). This interface must have a temporary target.
         - IS_TARGET_TABLE: Set to Yes this interface using the source query to load one of the target tables. This interface must source from an interface with a temporary target using this IKM and having the KM option DEFINE_QUERY set to YES.
         - EXECUTE: Set to Yes for the last interface in the Package. This interface will run the multi-table insert statement.
         - COMMIT: Commit transaction. This applies only to the last interface in the Package.
         - TRUNCATE: Set to Yes to truncate this interface target table.
         - CREATE_TARG_TABLE: Create target table? May only be used on target interfaces, but not on source interfaces (defining the source data).
         - OPTIMIZER_HINT: Hint for the multi-table insert statement.
    RESTRICTIONS:
         - This KM can only be used in integration interfaces that are part of a Package.
         - All source and target datastores need to reside on same data server.
         - Journalized source data is not supported.
         - Temporary indexes are not supported.
         - Flow/static control is not supported.
         - The TRUNCATE option cannot work, if the target table is referenced by another table (foreign key).

  • How can we archive Partioning in parent child tables in Normalised way.

    Hi Friends.
    Could you please suggest me
    How can we archive Partioning in parent child tables in Normalised way.
    Bill_parent(
    Bill_no number,
    Bill_date date .-- I want to create Partition on this column
    customer_id
    Bill_Child{
    bill_no number,
    Bill_c_no number,
    Item_code number
    Qty number
    Bill_Acsry{
    Bill_c_no number,
    acsry_it_code number,
    qty number
    Now for there Child Table I have also create a Bill_date column that is against Normalization
    i.e
    Bill_parent(
    Bill_no number,
    Bill_date date.
    customer_id
    ) Partion by Range (Bill_date).......................
    Bill_Child{
    bill_no number,
    Bill_c_no number,
    Item_code number
    Qty number,
    Bill_Date date,-- against normalisation
    }Partion by Range (Bill_date).......................
    Bill_Acsry{
    Bill_c_no number,
    acsry_it_code number,
    qty number,
    Bill_Date date,-- against normalisation
    }Partion by Range (Bill_date)....
    with regards
    Siddharth Singh([email protected])

    Looks like the new Reference Partitioning feature in 11g is what you want. In previous versions I think you're stuck with the denormalisation.

  • Trigger & Mutating Tables (Parent-Child relationship, Referencing Constraint related)

    Dear Sir,
    Wish you a very Happy New Year !!!
    I am facing a problem related to Database Trigger.
    Sir, I have two tables Cust and Sick.
    Cust is having the following fields :
    SDF_CUST_BRCD NOT NULL NUMBER(5)
    CUST_CUSTID NOT NULL VARCHAR2(6)
    UCD_CUST_SEGMENTCODE NOT NULL VARCHAR2(7)
    CUST_FIRSTBORROWER NOT NULL VARCHAR2(30)
    UCD_CUST_CONSTORGCODE NOT NULL VARCHAR2(7)
    VLGC_CUST_VILLAGECODE VARCHAR2(4)
    CUST_PAN VARCHAR2(20)
    UCD_CUST_STAFFCODE VARCHAR2(7)
    CUST_RESIDENTSTATFLAG VARCHAR2(1)
    CUST_BKGSINCEDATE DATE
    UCD_CUST_SICKUNITCODE VARCHAR2(7)
    Cust's Primary Key is the combination of Brcd, CustId
    And Sick Table Structure is as under :
    PRDT_SICK_REPORTDATE NOT NULL DATE
    CUST_SICK_BRCD NOT NULL NUMBER(5)
    CUST_SICK_CUSTID NOT NULL VARCHAR2(6)
    UCD_SICK_REASONCODE NOT NULL VARCHAR2(7)
    SICK_SINCEDATE NOT NULL DATE
    SICK_LOSSMAKINGDATE DATE
    SICK_ACCMLOSSAMT NUMBER(16,2)
    UCD_SICK_VIABILITYCODE NOT NULL VARCHAR2(7)
    UCD_BIFR_STATUS_CODE VARCHAR2(7)
    SICK_BIFRDATE DATE
    SICK_REHABSANCDATE DATE
    CUST_SICK_SICKUNITCODE VARCHAR2(7)
    Sick's Primary Key is the combination of ReportDate, BrCD, Custid
    Sick's (Brcd and Custid) referencing to Cust (BrCd, CustId).
    I want to insert/update into the sick table corrponding to Cust
    Insertion/Updation.
    I have written a trigger on Cust which is working fine provided
    that foreign key constraint
    is diabled. As soon as constraint is enabled the trigger is
    giving error
    ORA-04091: table CIS.CUST is mutating, trigger/function may not
    see it
    Sir, It is also working fine if the record is already exist in
    Sick table.
    Is is not working in 2 cases :
    1. While entering a new record into the Cust with
    SICKUNIT_CODE='SW00001'
    2. If we are changing the SickUnit_Code in Cust and correponding
    record doesn't exist in Sick.
    Please write me the solution.
    Thanking you
    yours sincerely
    Rajesh Kumar Jain
    Trigger Text is
    create or replace trigger tr_cust_sick
    after insert or update on Cust for each row
    declare
    Fn_Return boolean;
    Tr_Exception Exception;
    begin
    Fn_Return := Fn_cust_sick
    (:new.UCD_CUST_SICKUNITCODE,:new.SDF_CUST_BRCD,:new.CUST_CUSTID,I
    NSERTING,UPDATING,DELETING);
    If Not Fn_Return then
    Raise Tr_Exception;
    End if;
    exception
    when Tr_Exception then
    Dbms_output.put_line('Tr_Exception ' ||Sqlerrm);
    When others then
    Dbms_output.put_line(Sqlerrm);
    end;
    Function Text is :
    $$$$$$$$$
    create or replace function fn_cust_sick
    (SickUnitCode_in In Cust.Ucd_Cust_SickunitCode%Type,Brcd_in In
    Sdf.Sdf_Brcd%Type,Custid_in In Cust.Cust_Custid%
    Type,Inserting_in In Boolean ,Updating_in In Boolean,Deleting_in
    In Boolean)
    return boolean is
    ddate date default '01-Jul-1955';
    repdate ppar.ppar_reportdate%type default '31-Mar-2001';
    viabcode sick.ucd_sick_viabilitycode%type default 'VI00000';
    ReasonCD sick.ucd_sick_reasoncode%type default 'SK00000';
    Ret_Flag Boolean := False;
    begin
    if Updating_in then
    begin
    update sick
    set CUST_SICK_SICKUNITCODE = SickUnitCode_in
    where prdt_sick_reportdate = repdate and
    cust_sick_brcd = Brcd_in and
    Cust_Sick_CustId = Custid_in;
         Ret_Flag := True;
    if sql%notfound then
    if To_Number(Substr(SickUnitCode_in,3)) > 0 then
    insert into sick
    (PRDT_SICK_REPORTDATE,
    CUST_SICK_BRCD,
    CUST_SICK_CUSTID,
    UCD_SICK_REASONCODE,
    SICK_SINCEDATE,
    UCD_SICK_VIABILITYCODE,
    CUST_SICK_SICKUNITCODE,
              SUBO_SICK_SICKBORRCODE)
    values
    (repdate,
    Brcd_in,
    Custid_in,
    reasoncd,
    ddate,
    viabcode,
    SickUnitCode_in,
              'SB00001');
    Ret_Flag := True;
         Return(Ret_Flag);
         end if;
    end if;
    exception
    when others then
    dbms_output.put_line('Exception Update '|| Sqlerrm);
    return(Ret_Flag);
    end;
    elsif Inserting_in then
    begin
    if To_Number(Substr(SickUnitCode_in,3)) > 0 then
    insert into sick
    (PRDT_SICK_REPORTDATE,
    CUST_SICK_BRCD,
    CUST_SICK_CUSTID,
    UCD_SICK_REASONCODE,
    SICK_SINCEDATE,
    UCD_SICK_VIABILITYCODE,
    CUST_SICK_SICKUNITCODE,
              SUBO_SICK_SICKBORRCODE)
    values
    (repdate,
    Brcd_in,
    Custid_in,
    reasoncd,
    ddate,
    viabcode,
    SickUnitCode_in,
              'SB00001');
    Ret_Flag := True;
    end if;
         Return(Ret_Flag);
    exception
    when others then
    dbms_output.put_line('Exception Insert '|| Sqlerrm);
    return(Ret_Flag);
    end;
    end if;
    return(Ret_Flag);
    exception
    when Others then
    dbms_output.put_line('Main Exception '|| Sqlerrm);
    return(Ret_Flag);
    end;
    $$$$$$$$$$$

    Hi,
    double click the Application Module to open the AM editor. Select the data Model category. On the right hand side you see what is selected for use in an application, on the left hand side is what you have available as View Object. To create T1-->T2-->T3, you
    - Select T1 and move it to the right
    - Select T2 under T1 on the left and move it to the right under T1
    - Select T3 under T2 on the left and move it under T2 in T1 on the right
    Frank

  • Parent child table question

    HI i have some questions which iam unclear please help me
    1) in a parent child relationship.. is it always 1-m relation from parent to child?
    2) can a parent table be on many side? i.e can a child - parent be 1- m?
    3) if i itake employee as child table and department as parent table then dept_id will be the foreigh key in employee table ...
    Now if i want to add a new employee who is not assigned to any department can i add it ?
    4) In an identifying relationship ... a child table has concatenated primary key (pk of child,pk of parent)
    should we still add any other primary key to the table....in addition to this concatenated key?
    thanks in advance
    raj

    Hi!
    1) in a parent child relationship.. is it always 1-m relation from parent to child?
    yes unless you create a unique index on the foreign key column
    2) can a parent table be on many side? i.e can a child - parent be 1- m?
    no, if you need an n-m you will need an intersection table
    e.g. employees - emp_dept - departments
    in this case the emp_dept table would contain the foreign keys of employees and departments
    3) if i itake employee as child table and department as parent table then dept_id will be the foreigh key in employee table ...
    Now if i want to add a new employee who is not assigned to any department can i add it ?
    no, you will have to insert the master first
    Best regards,
    PP

  • Parent-child tables

    Hi,
    I have requirement like we have to delete a record called IT_PROG from jobs table.the jobs table have child tables employees,job_history, the employees table act as parent for employees,departments tables.How can i delete all related records using single query or single pl/sql block.
    Thanks in advance,
    Vi

    Hi,
    include it in your original table design would be the best way, with prime key, foreign key constraints and on delete cascade options.
    Other than that utilise trigger logic to coordinate your delete, but the first way is definitely the best, as triggers should be a last resort in databases....
    regards,
    Robert.

  • Parent child tables - how to maintain RI

    Here is my scenario:
    In our model, we have parent child relationship between tables.
    We are not sure how the parent tables are populated. If incremental update, it should be fine (assuming if needed rows will be inserted in the child table manually). If the tables are truncated and data is inserted again – that might be a problem since there exist relationship with child tables. What are the various options for handling such cases?
    Option1: cascade delete
    Option 2: ...?

    I'm not sure I understand the goal here...
    - Are you trying to design a data model? If so, wouldn't the business and data requirements tell you whether you need to truncate and reload the parent table or whether you can do an incremental load? It wouldn't seem to make sense to design a data model with no understanding of how the model is going to be used.
    - Are you trying to design a load process that works with an existing data model? If so, are you trying to design an incremental load? Or a load that involves a truncate and reload? Does the existing data model have foreign key constraints?
    Specifying the Oracle version and a bit of information about the application (i.e. is this an OLTP application, a data warehouse, something else) would probably also be helpful.
    Justin

  • Primary&foreign key rerlation ship

    hi folks,
    i am going to pick material in mm03 transaction after that i selected  classification tab choose batches for class type it displays values and clisifications
    now i want to find tables which is having the relation ship (primary key and foreign key)between material number and class type
    so could plz clarify my doubt
    regards,
    sree

    Hi
    Check table DD05S.
    Award points if found useful.
    Regards
    Inder

  • Multi-Table Foreign Key

    Hi all
    I am using oracle 9i, is it possible to create foreign key that referenced by more than one table, for example if I have such field I want the value for this field be referenced by values exist in either Table X or Table Y.
    Message was edited by:
    giggs11

    Hi,
    If I understood your question, and if you want that a value in one table should exist in both tables X and Y, then this is possible.
    SQL> create table x (id number constraint pk_x primary key);
    Table created.
    SQL> create table z (id number constraint pk_z primary key);
    Table created.
    SQL> create table a (id number);
    Table created.
    SQL> alter table a add constraint fk_a_x foreign key (id) references x;
    Table altered.
    SQL> alter table a add constraint fk_a_z foreign key (id) references z;
    Table altered.
    SQL> insert into x values (1);
    1 row created.
    SQL> insert into z values (1);
    1 row created.
    SQL> insert into a values (1);
    1 row created.
    SQL> delete from x;
    delete from x
    ERROR at line 1:
    ORA-02292: integrity constraint (A.FK_A_X) violated - child record found
    SQL> delete from z;
    delete from z
    ERROR at line 1:
    ORA-02292: integrity constraint (A.FK_A_Z) violated - child record found
    SQL> insert into x values (2);
    1 row created.
    SQL> insert into a values (2);
    insert into a values (2)
    ERROR at line 1:
    ORA-02291: integrity constraint (A.FK_A_Z) violated - parent key not found
    SQL> insert into z values (2);
    1 row created.
    SQL> insert into a values (2);
    1 row created.Cheers
    Legatti

  • Insert Record with Parent/Child Tables doesn't work with Oracle - unlike AC

    Hi,
    I just Migrated a MS Access 2010 Database to an Oracle 11g Backend with the SQL Developer Tool.
    The Migration went fine, all the Tables and Views are migrated.
    I'm working with MS Access as Frontend.
    The application has some Datasheets with Subdatasheets with Parent/Child Relationship. (1-n Relationship)
    After changing to Oracle, it's not possible, to Insert a new Record in a Subdatasheet I always get the following Error Message:
    "The Microsoft Access database engine cannot find a record in the table 'xxxx' with key matching field(s) 'zzzzz'"
    It used to work perfect with the MS Access Backend, do I need a trigger which first adds the child Record ?
    Or what should I do?
    Thank you

    Hi Klaus,
    Thanks for your answer. I still haven't solved my problem. The only way would be to use a singel 1:n Relationship, but in fact I need a n:m Relationship.
    I tried the same scenario with a new Access Application, same result.
    To clearify my problem.
    Goal: Parent Form with Parent Records, Linked Child Form with Child Records in a Datasheet View => Insert of a NEW Child Record.
    I have 3 Tables (table1 = Parent tabel, table2 = Child Table, table12 = n:m Tabel with PK and two FK)
    The Recordsource of the Parent Form is Tabel1
    The Recordsource of the Child Form is Table2 joined with Table12.
    In my Old Access Project, Access Triggered the Insert and filled Table12 with the NEW PK of Table2.
    It seems like Access can't do that anymore....
    I'm pretty desperate and I'm sure it is just a litte thing to fix.....

  • Commit Rollback for Parent & Child table

    Hi,
    I need to load data to a parent table and child table (Record by Record), i.e one record will be loaded to the parent table and the related child record will be loaded to child table.
    After first record loaded to child table, the next record will be loaded to the parent table.
    My requirement is, I should not commit the parent table before the child record is transferred (so that i can rollback if my record got failed). So I have set the parent table IKM commit option to NO. Because of this, my child record is not loaded to the correcsponding target table, its failed because the parent record is not commited.
    Do we have any possiblities to overcome this issue.
    Thanks in Advance,
    Ram Mohan T

    Cezar,
    I couldn't make the CKM options to "No Commit". When i did that i am getting the following error at step "16 - Control - CUSTOMER_DET - insert PK errors" ,
    12838 : 72000 : java.sql.SQLException: ORA-12838: cannot read/modify an object after modifying it in parallel.
    This error occurs at the CKM. so i have made all the CKM options to "commit" and IKM, LKM to "No Commit". It seems to be fine.
    Cezar,
    I have some plan for the scenario that i mentioned in the previous update (One dept id and all related employees). Please verify this,
    1) create a procedure which extracts dept_id from source tab and passes it to the scenario(in target tab) of a package.
    2) This package has the variable of dept_id, interface1 which loads data to dept and following that another procedure(2).
    3) This procedure2 will extract the emp_id that corresponds to the value of the variable dept_id. And passes this emp_id to tha scenario in target tab.
    4) This scenario is of a package which has the emp_id variable and interface2 for loading employees.
    While executing this plan, the problem is,
    1) Interface1 which loads Dept_Id is not commited (due to the KMs with commit set to "No Commit"), so that the employee records are getting loaded to the error table.
    2) I have made the interface1 KM commit option to "Default: Yes " (But still the Knowledge modules steps are No commit), but still the child records are getting loaded to error table.
    3) As per the above scenario, all these transforamtions are not taking in the same transaction. Thats the problem i believe.
    Do we have any possiblities to overcome this Cezar?
    Thanks in Advance,
    Ram Mohan T
    Edited by: T. Ram Mohan on Mar 5, 2009 11:43 AM

  • Parent Child Tables in OBIEE

    Hi,
    I have three tables to be added in OBIEE Admin Tool
    1. Request Master (Req_ID is PK)
    2. Complaints (Req_ID is PK)
    3. Compliments (Req_ID is PK)
    Table 2 and 3 are linked to table 1 in a 1:1 relationship. so basicallly, all requests have a record in the master table (Request master) and depending on the type of request, there will either be a detail record in table 2 or table 3.
    Can someone guide me as to what would be the best way to configure the relationships in the admin tool on the Physical & BMM layers.
    -Osden

    I know you said you have primary key defined already but just to make sure, can you follow these steps:
    1) Double click on dimension table
    2) go to tab 'Keys'. check if your primary key is defined there.
    3) If not, in 'Key Name', type in the key name
    4) select the primary key(column) in 'Columns'.
    5) Click OK.
    and then try to create hierarchy by following these steps:
    1) Right Click on the dimension table
    2) Create Logical Dimension -> Dimension with Parent-Child Hierarchy...
    3) Click OK (if you are OK with default values)

  • Sum within a self-contained parent-child table

    I have two tables - a "key" table containing a multi-layer parent-child relationship, and an "amount" table containing the keys for the leaf nodes in the key table as well as numeric values (e.g. amounts).
    I want a query that returns each row in the key table as well as the sum of the amount table's amounts for all of that key's leaf nodes (so the root node would have the sum of all of the amount values).
    Here's what I mean - I have two tables, KEY and AMOUNT
    KEY has two columns, key and parent_key; key and parent_key have a CONNECT BY relationship on parent_key = prior key (with parent_key null for the root):
    KEY     PARENT_KEY
    0       null
    1       0
    2       0
    3       0
    1A      1
    2A      2
    2B      2
    3A      3
    3B      3
    3C      3
    1A1     1A
    1A2     1A
    2A1     2A
    2A2     2A
    2B1     2B
    3A1     3A
    3A2     3A
    3C1     3C
    3C2     3CAMOUNT has two columns, key and amount; key points to KEY.key, and amount is a value for that particular key
    (note that all key values are leaf nodes in the KEY table)
    KEY     AMOUNT
    1A1     1
    1A2     2
    2A1     3
    2A2     4
    2B1     5
    3A1     6
    3A2     7
    3C1     8
    3C2     9 What I want is a result that looks like this, where each key's amount is the sum of its eventual leaf keys' amounts
    KEY     AMOUNT
    0       45
    1        3
    2       12
    3       30
    1A       3
    2A       7
    2B       5
    3A      13
    3B       0
    3C      17
    1A1      1
    1A2      2
    2A1      3
    2A2      4
    2B1      5
    3A1      6
    3A2      7
    3C1      8
    3C2      9For example, key 2A's value, 7, is the sum of the values of 2A1 and 2A2; key 3's value is the sum of 3A1, 3A2, 3C1, and 3C2.
    Is there a way of doing this with a single query?
    The idea I came up with is, do a select on KEY with a "CONNECT_BY_PATH key" column so each row includes a string containing the keys of all of its ancestors, and then do a join on AMOUNT with amount.key IN the CONNECT_BY_PATH column; however, with a larger amount of data, this takes quite a bit of time. Is there a faster / more obvious way of doing this?

    SQL> with key_tbl as (
      2                   select '0' key,null parent_key from dual union all
      3                   select '1','0' from dual union all
      4                   select '2','0' from dual union all
      5                   select '3','0' from dual union all
      6                   select '1A','1' from dual union all
      7                   select '2A','2' from dual union all
      8                   select '2B','2' from dual union all
      9                   select '3A','3' from dual union all
    10                   select '3B','3' from dual union all
    11                   select '3C','3' from dual union all
    12                   select '1A1','1A' from dual union all
    13                   select '1A2','1A' from dual union all
    14                   select '2A1','2A' from dual union all
    15                   select '2A2','2A' from dual union all
    16                   select '2B1','2B' from dual union all
    17                   select '3A1','3A' from dual union all
    18                   select '3A2','3A' from dual union all
    19                   select '3C1','3C' from dual union all
    20                   select '3C2','3C' from dual
    21                  ),
    22    amount_tbl as (
    23                   select '1A1' key,1 amount from dual union all
    24                   select '1A2',2 from dual union all
    25                   select '2A1',3 from dual union all
    26                   select '2A2',4 from dual union all
    27                   select '2B1',5 from dual union all
    28                   select '3A1',6 from dual union all
    29                   select '3A2',7 from dual union all
    30                   select '3C1',8 from dual union all
    31                   select '3C2',9 from dual
    32                  )
    33  select  key,
    34          nvl(sum(amount),0) amount
    35    from  (
    36           select  connect_by_root k.key key,
    37                   amount
    38             from  key_tbl k,
    39                   amount_tbl a
    40             where a.key(+) = k.key
    41             connect by k.parent_key = prior k.key
    42          )
    43    group by key
    44    order by key
    45  /
    KEY     AMOUNT
    0           45
    1            3
    1A           3
    1A1          1
    1A2          2
    2           12
    2A           7
    2A1          3
    2A2          4
    2B           5
    2B1          5
    KEY     AMOUNT
    3           30
    3A          13
    3A1          6
    3A2          7
    3B           0
    3C          17
    3C1          8
    3C2          9
    19 rows selected.
    SQL> SY.

Maybe you are looking for

  • What's wrong with my iPhone 4 when the speaker is touched it starts to vibrate

    It keeps vibrating if the sound speaker is pushed

  • Getting default value in query PLD

    Hi Experts, I have made a query PLD.When I preview the pld,I shows me someother value. For eg If I want to see preview of vendor let say V0007 but in preview I can see only for V002.V002 is default in pld.If I use any vendor code instead of v0007,it

  • Help needed with Time Machine multiple drives set up

    Hello, I need help in finding out if what I want to do is possible. I upgraded to Mountain Lion today as I understood it can handle multiple back up drives. I see how to add a 2nd back up drive, however I do not see a way to put different folders ont

  • 5700 - Email - Send - Set the code table

    I installed the Psiloc Crystal Japanese But when i send message to a my friend she cannot see my messages because her phone (or her Mobile Operator: Japana AU) Wants emails only with JIS but my nokia send only as unicode. Can I do something? Is it a

  • BADI for PO release through ME29n

    Hi Experts, I have to send an IDOC as & when user release the Purchase order from ME29n. I got a user exit 'M06E0004' for release strategy but it sends idoc when i open the Transaction ME29n. Instead of that i have to send it on the click on that rel