Updating A child Table As Administrator

Hello Eevryone, I read a post here http://forums.adobe.com/thread/463635. And i first off want to commend you guys on your awesome contribution to novices like me. I understand the technique presented here but I have a different problem though. I have two tables, which are related by one to many. Personals Table and Courses Table. One person can have many courses. Only the Admin can update and add new courses. The Courses Table has a Foreign key: personal_Id. The admin has a view page and can update personals table easily. How can I add and update courses for a selected Person. I mean how to build the recordset in Dreamweaver CS5 so that I cant pick just that persons ID and add all course just for his account. In the technical sense how do I parse the FK_personal_Id so that the add course form or update course form only stores the course for that personal_ID on Personal Table. Please I hope you understand how I have explained it but I would love to know this procedure. Thank you very much.

You don't really want to create a recordset to update the tables. You don't mention what scripting language you are using. In ASP, you CAN  create updateable recordsets, but it's really not necessary in this circumstance. You simply need to create an update statement to update the parent table, and an insert statement to insert the record into the related table when the form is posted. You can use DW's server behaviors to accomplish one or the other if you want - but not both. If I am performing a CUD on multiple tables, I would think about writing a stored procedure. Again, it depends on your DBMS. I'd suggest looking into DW Insert record and update record server behaviors to start with.

Similar Messages

  • Update data to upper case in parent/child tables

    Hi Gurus!
    In production we have a product table and which is being reference by many tables making it parent child relationship. By mistake, we realized that last month some product were added in lower case and now we got a request to update all these product codes to upper case so that the existing code that use these tables have no impact. Appreciate if you can give some idea on how can I update the existing data in the parent table to upper case along with the child records?
    Regards
    Sri

    Are the product code that you need to update what is stored in the child tables? If so, then you would need to do it in several steps, something like:
    Identify the child tables
    SELECT table_name, constraint_name
    FROM user_constraints
    WHERE r_constraint_name = (SELECT constraint_name
                               FROM user_constraints
                               WHERE table_name = 'PRODUCT_TABLE' and
                                     constraint_type = 'P');Create the new upper case product code in product table:
    INSERT INTO product_table
    SELECT UPPER(product_code), other_columns
    FROM product_table
    WHERE product_code <> UPPER(product_code);Update the child tables to uppercase the product codes
    UPDATE child1
    SET product_code = UPPER(product_code)
    WHERE product_code <> UPPER(product_code);finally, delete the lower case product codes from product_table
    DELETE FROM product_table
    WHERE product_code <> UPPER(product_code);John

  • Child Table Cache Problem - Only in Environment

    Hi All,
    I have master-child tables in a page. Master table is based on a VO and child table is based on pl/sql EO. When user updates any child table row and hits on save, I load the same page again by releasing AM. The problem is when the page loads again after update, two records are being shown in child table. One record with old value and other record with the modified value. But in database only record exists and it is successfully updated. If we again hit "Apply" on the page then only the updated record is shown. I am sure this is due to vo/eo caches. But after insert/update, I am forwarding to same page with retain am set to false. So this should clear-off all associated caches. I had even tried to clear vo caches explicitly before redirection. But even this doesnt help. This issue exists only in the environment but cannot be reproduced locally in JDev. Its working perfectly fine in JDev.
    Any pointer on the above issue?
    Thanks in advance,
    Murari

    hmm...caching may be happening at webbean level rather than the VO level. You can confirm this by getting the value of VO.getrowcount in processRequest.
    For both Classical table as well as Advanced Table, clearcache() method is available to clear the cache of data object for inner table. Call this in processRequest. You can put in a check to call this only when you self-redirect to this page.

  • UPDATE of column in parent only UPDATEs first row in DENORMALIZED child table

    In the Repositiry in Designer 6i, I denormalized DESC1 column to
    pull the value of DESC1 in the parent table. The child table has
    four (4) records with matching foreign keys. When I go into my
    Form and update DESC1 in the parent, only the first of the four
    child DESC1's are updated. Any ideas?
    Thanks,
    Dan

    Dan,
    Sorry, known bug, but should be fixed in next release.
    Have a look via metalink at article <Note:156833.1> this
    explains in detail the problem and a fix.
    The bug no was <1974122>
    regards
    David

  • Cascade update of primary key in child tables

    Hi,
    We have a typical scenario in which the primary key has to propage to the child table into 3 levels. We are getting the no parent key exception if we create new data into the three tables using 3 level master detail relationship and execute commit operation. The following is the structure of the tables.
    Parent_table (sno number primary key, name varchar2(100));
    Child_table (fk_sno number primary key, name varchar2(100), foreign key (fk_sno) references parent_table(sno));
    GrandChild_table (sno number primary key, fk_sno number, name varchar2(100), foreign key (fk_sno) references Child_table(fk_sno));
    The requirement is to update fk_sno in child_table and grandchild_table with the trigger generated primary key sno in the parent_table.
    The application module is having the following structure
    parenttable
    |
    ----------childtable
    |
    -----------grandchild_table
    If we create new records into parent_table and child_table it is working fine when we commit the data. If we create another record into grandchild_table and commit data we are getting the foreign key violation exception. We are using composition in the association to update the modified values to refresh the data.
    Is there any problem in the data model to use fk_sno as primary key and foreign key in child_table.
    Thanks and Regards,
    S R Prasad

    Hmm, another example is CSKS, this logic was probably designed already in the 1980s...maybe it was seen beneficial to be able to select the currently valid record by using the primary key only (the first record where DATBI is larger than system date, not possible when DATAB is the key instead).
    Maybe there are better explanations. Why do you need to know this, just curious?
    Thomas

  • Update column data to Upper Case in parent and child table

    Hi ,
    I am facing issue while updating column value to upper case in parent table and child table. How can i do that ?
    when updating parent row:
    ORA-02292: integrity constraint (XXXXXXXXXXXXXX_FK) violated - child record found
    When updatng corresponding child row:
    ORA-02291: integrity constraint (XXXXXXXXXXXXXXXX_FK) violated - parent key not found
    how can i update on both the places ?
    Regards,
    AA

    I am facing issue while updating column value to upper case in parent table and child table. How can i do that ?
    Why do you need to do that?
    That is just ONE of several questions you should answer before you start modifying your data.
    1. What is your 4 digit Oracle version? (result of SELECT * FROM V$VERSION)
    2. If both values are the same case what difference does it make what that case is?hen you don't need to alter your original data.
    3. What is the source of the column values you are using now? If you change your data to upper case it will no longer be identical to the source data.
    4. What is your plan for enforcing future values to be stored in UPPER case? Are you going to use a trigger? Have you written and tested such a trigger to see if it will even work the way you expect?
    5. Why aren't you using a surrogate key instead of a 'business' data item? You have just demonstrated one reason why surrogate keys can be useful: their actual value is NOT important.
    You should reexamine your problem and architecture and consider other alternatives.
    One alternative is to add a new 'surrogate key' column to use as the primary key. Just create a new sequence and use a trigger to populate the new column. Your current plans will require a trigger to perform the case conversion so instead of the just use the trigger to provide the value.
    If the change is being done to facilitate searching you could just add a VIRTUAL column UPPER_MY_COLUMN and index that instead. Then you could search on that new virtual column and the data values would still be identical to the original data source.

  • Update key in parent and child tables

    Situation:
    Parent table (p) has a PK, p.parent_id. Child table (c) has a FK c.parent_id which, of course, points back to PK, p.parent_id.
    I need to UPDATE the key in both tables but I am concerned about throwing a FK constraint violation. How does one get around this? Does one update the child first then the parent or vice versa? Seems either way a FK violation will occur...
    thank u.

    1) If you ever anticipate wanting to update a key, that key should not be the primary key of a table. Primary keys should be immutable. If this is going to happen with any regularity, you need to re-examine the underlying data model.
    2) If the constraints were declared to be deferrable, you would simply mark them as deferred, update both tables, and commit (at which point the constraint would be validated). If the constraints were not declared to be deferrable, you will probably need to end up dropping and re-creating one or the other (presumably as a deferrable constraint this time).
    Justin

  • How to update parent and child tables while updating parent table

    I have a parent table EMPLOYEE which includes columns (sysid, serviceno,employeename...) sysid is Primary key, serviceno is Unique key and I have child table DEPENDENT includes columns (sysid,employee_sysid,name,dob...) here again SYSID is primary key for DEPENDENTS table, employee_sysid is Foreign key of EMPLOYEE table.
    Now I want to change SYSID (using sequence) in EMPLOYEE table which need to be update in DEPENDENTS table as well
    Note: I have 10000 records in EMPLOYEE table as well as I have 5 more child tables which need to update new SYSID.
    please help me

    first disable the FOREIGN KEY Constraints.
    you can update Parent as well as Child record also with help of trigger.
    here i am giving you one examlpe..it may help u.
    create table parent(id number primary key,name varchar2(100))
    create table child_1(id number primary key,p_id number,dob date,
    CONSTRAINT FK_id FOREIGN KEY (p_id) REFERENCES parent (ID))
    create table child_2(id number primary key,p_id2 number,addr varchar2(1000),
    CONSTRAINT FK_id2 FOREIGN KEY (p_id2) REFERENCES parent (ID))
    insert some test data to parent and child tables.
    alter table child_2 disable constraint FK_id2
    alter table child_1 disable constraint FK_id2
    CREATE OR REPLACE TRIGGER delete_child
    BEFORE UPDATE ON parent
    FOR EACH ROW
    BEGIN
    UPDATE CHILD_1
    SET P_ID=:NEW.ID
    WHERE P_ID=:OLD.ID;
    UPDATE CHILD_2
    SET P_ID2 =:NEW.ID
    WHERE P_ID2=:OLD.ID;
    END;
    then Upadte parent table primary key col and check the child tables.
    then enable the constraints...

  • 11g child table update locking

    Hi,
    I'm posting this question after searching on multiple places and trying to understand 11g locking mechanism.
    I've a table TXN1 transaction and has FKs to 3 different tables Account, customer, country and currency. ALL FKs are indexed (bitmap). I am updating TXN1 of amount column about 10,000 rows. (SID 1) As expected, it has taken lock type 3 SX on TXN1. But it has taken on lock type 4 (share) on Account, customer and country. Committing every 10k rows.
    At the same time sid 2 is inserting into another TXN2 table which has FK to the same dimensions account, customer and currency. Only FK on ac_id is bitmap indexed. The inserts have taken SX lock(type 3) on tXN2 table (expected). But it is trying to take SX type 3 lock on account, customer, currency tables. typ3 lock taken on CCY but waiting on CST. But It is blocked by sid 1. It has resulted into Enque-TM contention and resulted into anywhere 60-300 secs wait time..
    I understand update/delete in parent table results into locking of SX of child tables and need the FKs to be indexed to avoid etc. I didn't understand the following and appreciate if someone can help me.
    1. Why is SID1 taking shared lock on the parent tables Account,customer,country and currency tables? The update statement is not updating any of those FK columns nor referring them in where clause(if it matters!). Is it to ensure that the parent rows are not deleted?
    2. Why is SID2 taking SX lock on the dimension tables? Why is it not taking RS lock type 2 on parent rows? Why is SID1 taking shared lock type 4, but not 2?
    Thanks
    Ram
    Edited by: rkuppa on May 24, 2013 2:24 PM
    Edited by: rkuppa on May 24, 2013 2:25 PM
    Edited by: rkuppa on May 24, 2013 2:26 PM
    Edited by: rkuppa on May 24, 2013 2:33 PM
    Edited by: rkuppa on May 26, 2013 4:49 PM

    Table TxN(ac_id, cs_id, amt, amt_dollar), PK on ac_id,cs_id. constraint FK on ac_id to Table AC_DIM (ac_id, acctname), FK on cs_id to Table CST_DIM(cs_id, custname). These FK are bitmap indexed.
    Update qry: update TXN set amt_dollar =amt/1.1 where rownum<1000; commit; (sid 308)
    Table TXN2(ac_id, cs_id,ccy_id, amt, amt_dollar), PK on ac_id,cs_id,ccy_id. constraint FK on ac_id to Table AC_DIM (ac_id, acctname), FK on cs_id to Table CST_DIM(cs_id, custname), CCY_DIM(ccy_id). Only ac_id FK in the TXN2 table is indexed to bitmap.
    At the same time, another transaction is inserting into TXN2 1000 rows. (sid 127)
    SELECT l.sid, s.blocking_session blocker, SUBSTR(s.event,1,20),
    l.type, l.lmode, l.request, o.object_name, o.object_type
    FROM v$lock l, dba_objects o, v$session s
    WHERE UPPER(s.username) =  'MY_USER'
    AND l.id1 = o.object_id (+)
    AND l.sid = s.sid
    ORDER BY sid, type;
    SID     BLOCKER     SUBSTR(S.EVENT,1,20)     TYPE     LMODE     REQUEST     OBJECT_NAME     OBJECT_TYPE
    308          db file scattered re     AE     4     0     ORA$BASE     EDITION
    308          db file scattered re     TM     4     0     AC_DIM             TABLE
    308          db file scattered re     TM     4     0     CST_DIM             TABLE
    308          db file scattered re     TM     3     0     TXN             TABLE
    127     308     enq: TM - contention     AE     4     0     ORA$BASE     EDITION
    127     308     enq: TM - contention     TM     3     0     CCY_DIM             TABLE
    127     308     enq: TM - contention     TM     0     3     CST_DIM             TABLE
    *<< I don't see type 3 lock on AC_DIM for sid 127>>*
    SELECT
      S.SID,
      S.PROGRAM,
      S.SQL_HASH_VALUE,
      L.REQUEST,
      L.ID1,
      L.ID2,
      L.LMODE,
      L.TYPE,
      L.BLOCK
    FROM
      V$LOCK L,
      V$SESSION S
    WHERE
      (L.ID1, L.ID2, L.TYPE) IN
      (SELECT
        ID1,
        ID2,
        TYPE
      FROM
        V$LOCK
      WHERE
        REQUEST > 0)
      AND L.SID=S.SID;
    SID     PROGRAM                                      SQL_HASH_VALU REQUEST     ID1     ID2     LMODE     TYPE     BLOCK
    308     SQL Developer                            1733825831     0     509281     0     4     TM     1
    127     db-load.impl.n64@aittsmwp2 (TNS V1-V3)    4097376515     3     509281     0     0     TM     0Edited by: rkuppa on May 24, 2013 6:58 PM
    Edited by: rkuppa on May 24, 2013 7:12 PM
    Edited by: rkuppa on May 24, 2013 7:16 PM
    Edited by: rkuppa on May 26, 2013 4:42 PM
    Edited by: rkuppa on May 26, 2013 4:47 PM
    Edited by: rkuppa on May 26, 2013 4:55 PM

  • Update child table

    create table p (p1 number constraint ppk primary key);
    create table f (f1 number constraint ffk references p);
    create trigger pt after update on p for each row begin
    update f set f1 = :new.p1 where f1 = :old.p1;
    end;
    insert into p values(1);
    insert into p values(2);
    insert into p values(3);
    insert into f values(1);
    insert into f values(2);
    insert into f values(3);
    commit;
    After this when I execute
    update p set p1 = p1+1;
    I am seeing all the records updated 4 in table f.This is because of the fact that above dml updates multiple rows at once.
    My doubt: Is there any way to track which foreign key values have already been updated? Using that suggested way I would like to modify the trigger such that no row is updated twice.
    Thanks in advance.

    Please find the code which I have tried for the
    same...
    DROP TABLE f;
    DROP TABLE p;
    CREATE TABLE p (p1 NUMBER CONSTRAINT ppk PRIMARY
    KEY);
    CREATE TABLE f (f1 NUMBER CONSTRAINT ffk REFERENCES
    p);
    INSERT INTO p VALUES(1);
    INSERT INTO p VALUES(2);
    INSERT INTO p VALUES(3);
    INSERT INTO f VALUES(1);
    INSERT INTO f VALUES(2);
    INSERT INTO f VALUES(3);
    DROP TABLE a;
    CREATE TABLE a(arowid ROWID);
    DROP PACKAGE pkg;
    CREATE OR REPLACE PACKAGE pkg IS
    frowid ROWID;
    END;
    CREATE OR REPLACE PROCEDURE load(r ROWID) IS
         v NUMBER(1) :=0;
    BEGIN
         SELECT 1
         INTO v
         FROM a
         WHERE arowid=r;
         IF(v=0) THEN
              INSERT INTO a VALUES(r);
              pkg.frowid:=r;
         ELSE
              DBMS_OUTPUT.PUT_LINE(r||' is already updated.');
         END IF;
    END;
    CREATE TRIGGER ft AFTER UPDATE ON f FOR EACH ROW
    BEGIN
         load(:OLD.ROWID);
    END;
    CREATE TRIGGER pt AFTER UPDATE ON p FOR EACH ROW
    BEGIN
         UPDATE     f
         SET      f1 = :NEW.p1
         WHERE      f1 = :OLD.p1
         AND      f.ROWID=pkg.frowid;
    END;
    SQL> update p set p1=p1+1;
    update p set p1=p1+1
    ERROR at line 1:
    ORA-02292: integrity constraint (BI_LEARN.FFK)
    violated - child record found
    SQL>
    Could anyone help me for this.
    Thanks in AdvanceThe first logical error is here
         AND      f.ROWID=pkg.frowid;pkg,rowid to this point of time never corresponds to ROWID of table f.
    That's why UPDATE in trigger doesn't run and also other actions respectively.
    BTW: here
    CREATE OR REPLACE PROCEDURE load(r ROWID) IS
         v NUMBER(1) :=0;
    BEGIN
         SELECT 1
         INTO v
         FROM a
         WHERE arowid=r;
         IF(v=0) THEN
              INSERT INTO a VALUES(r);
              pkg.frowid:=r;
         ELSE
              DBMS_OUTPUT.PUT_LINE(r||' is already updated.');
         END IF;
    END;You get an exception NO_DATA_FOUND, if You haven't a record in table.
    Your branch starting with IF v=0 will be never processed ...
    Regards
    Dmytro

  • Parent-Child Table Update via Single Stored Procedure

    Uses: Oracle 9i Server via a Remote Connection with restriction, Oracle 9i client, .NET 2.0+System.Data.Oracle namespace, Delphi+BDE;
    I have an entry form which consists of a parent and a child table. I'm so keen in knowing whether there is any possibilities of updating the records via a single stored procedure? I mean if parent have a single record and corresponding to it, child have few records (more than 1 rows). I need to take the parent's value and child's value send it to the stored procedure and update it.
    Regards,

    The entry form gets the raw data from the user. So yes the data is captured front end but not updated nor processed. Once the user clicks "Save" or what ever the values are taken to the SP. In the SP the operations are done either as update or insert. Lets concentrate on Inserts only at the moment.
    I.e. there are 2 tables as:
    tbl_Payment(_PaymentID_, PaymentMode,PaymentDate, TotalPaymentValue);
    tbl_PaymentAccount(_PaymentID,AccountID_,PaymentValue);
    So the form has a top part which is bounded to the Parent Table which is "tbl_Payment" to few text boxes, and below it has a Datagrid, bounded to Child Table which is "tbl_PaymentAccount". And assume the the Single Stored Procedure as "sp_payment_addchg".
    I can pass newly entered values to the SP as:
    Command.Text = "sp_payment_addchg";
    /*so all the parent table bounded values are updated as*/
    Command.Parameter[0].value = text1.text;
    Command.Parameter[1].value = text2.text;
    and so on
    Since the DataGrid may have multiple rows, I cant figure it out how to get those rows into a single parameter.
    Regards,

  • Hello Gurus..... ISSUE with child Table update

    I have an issue with child table update
    I have created a GTC with one parent table and two child tables. I'm able to update the parent table and the values are found in db, but the ISSUE is the child Table values are not updating the db.
    please give me a solution
    regards
    Srikanth

    If you are keeping referential integrity in the database, not in the application, it is easy to find the child and parent tables. Here is a quick and dirty query. You can join this to dba_cons_columns to find out on which columns the referential constraints are defined. This lists all child-parent table including SYS and SYSTEM users. You can run this for specific users of course.
    select cons1.owner child_owner,cons1.table_name child_table,
    cons2.owner parent_owner,cons2.table_name parent_table
    from dba_constraints cons1,dba_constraints cons2
    where cons1.constraint_type='R'
    and cons1.r_constraint_name=cons2.constraint_name;

  • Master Child tables how to get the latest rows from both

    Hi,
    Need some help with the sql. I have two tables Master & Child. In my Master table I have multiple rows for the same record and in the child table also multiple rows for the same master row how can I get the latest one's from both.
    For example Data in my Master table looks like
    CONT_ID                  SEQ_NUM        DESCRIPTION
    1                         189             Update 2
    1                         188             Update 1
    1                         187              NewNow in the child table for the same CONT_ID I may have the following rows
    CONT_ID                   UPDATED_DATE                                     STATUS
    1                        3/16/2010 2:19:01.552700 PM                          P
    1                        3/16/2010 12:29:01.552700 PM                         A
    1                        3/16/2010 12:29:01.552700 PM                         P
    1                        3/16/2010 12:19:01.552700 PM                         NIn my final query how can I get the row with seq_num 189 as it's the latest in Master table and from child table the row with status of P as it's the latest one based on the time. Here is the query i have but it returns the latest row from the child table only and basically repeats the master table rows as opposed to one row that is latest from both:
    Thanks

    Hi,
    You can use the analytic ROW_NUMKBER function to find the latest row for each cont_id in each table:
    WITH     got_m_rnum     AS
         SELECT     cont_id,     seq_num,     description
         ,     ROW_NUMBER () OVER ( PARTITION BY  cont_id
                                   ORDER BY          seq_num     DESC
                           ) AS m_rnum
         FROM    master_table
    --     WHERE     ...     -- any filtering goes here
    ,     got_c_rnum     AS
         SELECT     cont_id, updated_date,     status
         ,     ROW_NUMBER () OVER ( PARTITION BY  cont_id
                                   ORDER BY          updated_date     DESC
                           ) AS c_rnum
         FROM    child_table
    --     WHERE     ...     -- any filtering goes here
    SELECT     m.cont_id,     m.seq_num,     m.description
    ,     c.updated_date,     c.status
    FROM     got_m_rnum     m
    JOIN     got_c_rnum     c     ON     m.cont_id     = c.cont_id
                        AND     m.m_rnum     = c.c_rnum
                        AND     m.m_rnum     = 1
    ;If you'd like to post CREATE TABLE and INSERT statements for the sample data, then I could test this.
    If there happens to be a tie for the latest row (say, there are only two rows in the child_table with a certain cont_id, and both have exactly the same updated_date), then this query will arbitrarily choose one of them as the latest.

  • 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>

  • How to insert record in child table with foreign key

    Hi,
    I am using Jdeveloper 11.1.2.0. I have two master table one child table.
    How to insert and update a record in child table with foreign key ?
    I have created VO based on three EO(one eo is updatable other two eo are references) by using joined query.
    Thanks in Advance
    Edited by: 890233 on Dec 24, 2011 10:40 PM

    ... And here is the example to insert using sequenceimpl by getting the primary key of the master record and insert master and detail together.
    Re: Unable to insert a new row with a sequence generated column id
    -Arun

Maybe you are looking for

  • Error 13 = Blue Screen of Death?

    Thought I'd try this board and see if anyone knows anything about 'error 13' and Panther. I have been plagued by this error message which pops up whenever I try to print from either of my printers or burn a CD. This all happened after I tried to load

  • Report  for "record payment history"  for customer ?

    Report  for "record payment history"  for customer ? Please send it.

  • FLVPlayback component skinAutoHide problem

    Hi guys! I have a problem with FLVPlayback component's skinAutohide property which works poorly when FLVPlayback component is the same size as your stage. The skin only hides when I move my mouse very slowly outside the FLVPlayback component. Also ma

  • Need help on NTFS

    Hi. I have some external hard drives which were readable when plug into my MBP. I was trying to make my NTFS external drive writable in my MBP. So I installed NT Filesystem for Mac OS X (NTFS_1.0d2). After the installation, my MBP can no longer detec

  • Startup Full Disk Error

    I have a Mac Book Air and last night I let it getting a plug in in order to watch videos, this morning I turned it on and all I got was a blue screen whit this message: YOUR DISK IS FULL. It only opens messenger but it is impossible to get to the fin