UPDATE to update trigger another table

I am trying to write a trigger to the table (AFTER UPDATE) in which I want to update the same table in a different pattern. Notice that both tables has no unique or primary key constraint, so I am forced to compare the values in the column all the to the place where the condition.

Update OTHERSCHEMA. T1

the value =:NEW.c1 c1, c2 is:NEW.c2...

where c1 =:OLD.c1

AND c2 =:OLD.c2

Problem is when a column is null, it would seem that it is not comparable. I even tried

Update OTHERSCHEMA. T1

the value =:NEW.c1 c1, c2 is:NEW.c2...

where NVL (c1, NULL) = NVL (:OLD.c1, NULL)

AND NVL (c2, NULL = NVL (:OLD.c2, NULL)

Nothing helps. Can someone help me to write the correct statement?

Hello

eyap wrote:

I am trying to write a trigger to the table (AFTER UPDATE) in which I want to update the same table in a different pattern. Notice that both tables has no unique or primary key constraint, so I am forced to compare the values in the column all the to the place where the condition.

Update OTHERSCHEMA. T1

the value =:NEW.c1 c1, c2 is:NEW.c2...

where c1 =:OLD.c1

AND c2 =:OLD.c2

Problem is when a column is null, it would seem that it is not comparable. I even tried

Update OTHERSCHEMA. T1

the value =:NEW.c1 c1, c2 is:NEW.c2...

where NVL (c1, NULL) = NVL (:OLD.c1, NULL)

AND NVL (c2, NULL = NVL (:OLD.c2, NULL)

Nothing helps.

Naturally.  NVL (x, NULL) is always x, no matter what x is.

Can someone help me to write the correct statement?

x = is returns TRUE if (and only if) x and have the same value, and it returns FALSE if (and only if) x and have 2 different values.

NULL is not a value; in fact, it's quite the opposite.  NULL means that there is no value.  If x or is NULL, then x = y returns UNKNOWN.

DECODE allows to compare values or NULL values, so you can do something like

Update OTHERSCHEMA. T1

the value of c1 =: NEW.c1

, c2 =: NEW.c2

,       ...

where LESS (DECODE (c1,:OLD.c1, 1, 0)

, DECODE (c2,:OLD.c2, 1, 0)

)

;

If you would care to a full test script so that I can reproduce the problem, then I could test this.

Triggers often indicate a bad table design.  Why do you need to replicate the data in another table?

As you do, why not add a primary key?

Tags: Database

Similar Questions

  • Select the data in a table and update in another table

    Dear experts,

    create the table TB_ENCRYPT

    (

    Identification number,

    Varchar2 (200) KEY

    );

    INSERT INTO TB_ENCRYPT VALUES(1,'HJUVHDUIFBSDGVU');

    SELECT * FROM TB_ENCRYPT;

    1 HJUVHDUIFBSDGVU

    create TABLE users)

    username, NUMBER of

    password VARCHAR2 (200)

    );

    Insert users

    values (1, 123 # "")

    Insert users

    values (2, 456 #')

    Select * from users;

    1 123 #.

    # 2 456

    I want to select the data KEY for table TB_ENCRYPT column and update in the column of tables for the respective key user password

    TB_ENCRYPT table contains only a single key value. Comparing this key, I want to update the old value of the key to the new value.

    For encryption and decryption I followed the java class method.no is worried about that.

    create or replace

    PACKAGE PCK_ENC AUTHID CURRENT_USER AS

    FUNCTION DECRYPT (VARCHAR arg0, arg1 VARCHAR) AS VARCHAR BACK LANGUAGE JAVA NAME 'Encrclass.decrypt (java.lang.String, java.lang.String) return java.lang.String ';

    FUNCTION ENCRYPT (VARCHAR arg0, arg1 VARCHAR) AS VARCHAR BACK LANGUAGE JAVA NAME 'Encrclass.encrypt (java.lang.String, java.lang.String) return java.lang.String ';

    END;

    SELECT PCK_ENC. ENCRYPT('1234','HJUVHDUIFBSDGVU') FROM DUAL;

    HERE,

    1234 - is the password of the users table column data

    HJUVHDUIFBSDGVU - represents the key of table TB_ENCRYPT column data.

    Comparing this key, I want to update the old value of the key to the new value.

    I tried with this method

    declare

    cursor c1 is

    Select the key

    of TB_ENCRYPT

    where id = 1

    update the id;

    Start

    for c1_rec looping c1

    update users

    password is PCK_ENC. Encrypt (Password, Key)

    the location being c1;

    commit;

    end loop;

    end;

    /

    Help, please

    You can use the MERGE statement.

    merge into users
    using tb_encrypt
       on (id = userid)
      when matched then
          update set password = PCK_ENC.ENCRYPT(password,key);
    

    And why you encrypt your password. This isn't a good idea. Just password hash.

  • trigger that updates another table?

    Hi all

    I'm trying to define a trigger on tableA:

    Name ID Pk Null column?     Default data Type

    TITLE 1 Y VARCHAR2 (5 Char)
    FULLNAME 2 Y VARCHAR2 (80 Char)
    UNIVERSITYID 3 N VARCHAR2 (9 Char)
    APPL_NO 4 N NUMBER (11)
    APPL_NO_HASH 5 N VARCHAR2 (4000 bytes)
    OFFER_EXPIRATION_DATE 6 DATE
    APPLICATION_CANCEL_DATE 7 Y DATE
    ROOM_HALL 8 Y VARCHAR2 (39 bytes)
    ACCEPTED_FLAG 9 Y CHAR (1 byte)
    TIMESTAMP (6) Y ACCEPTED_DATE 10
    RECORD_CREATE_DATE 11 Y TIMESTAMP (6) systimestamp


    When the ACCEPTED_FLAG column is updated, I want an execution of the trigger and upadate a column with sysdate on another table...

    That's what I have so far:



    CREATE OR REPLACE TRIGGER INTER_SCHEMA. ACCEPTED_DATE_TRIGGER
    AFTER UPDATE
    OF ACCEPTED_FLAG
    WE scheme. ACCOM_OFFER_ACCEPTANCE
    REFERENCING NEW AS new OLD IN the old
    FOR EACH LINE
    BEGIN
    insert id whre table_b (column) values (sysdate) =?
    END;



    Any advice would be appretiated.

    Thank you very much

    Trigger knows the records that are updated. Trigger can use the recordings ": OLD ' pointer.
    You should have the code to something like:

    update table_b set table_b.column = sysdate) whre id = :old.table_b_id;
    

    And column mus "table_b_id" exist in the ACCOM_OFFER_ACCEPTANCE table.

  • trigger for update field in a table with the sum of the fields to another table

    My experience in creation of triggers and pl/sql in general can be described in terms of oracle with the null value. I practiced by creating arrays and applications on my personal server at home to help me with some of my work related tasks. Right now I am creating a trigger which will, after insert, update, delete on the update of the table assignment_time_track the area of the time_spent on the table of assignments with the sum of the time_spent on the assignment_time_track table fields. I hope that run on the sentence it is clear to the people other than me. I tried this script on my own using the tool of creation of trigger for Oracle Database Express Edition, but I get the following error:

    Create a trigger failed, for the following reason:
    ORA-06552: PL/SQL: ORA-06553 finished Compilation unit analysis: PLS-320: the declaration of the type of the expression is incomplete or incorrect

    Here is my attempt to create the trigger on my own.

    create or replace trigger "ASSIGNMENT_TIME_TRACK_T1".
    AFTER
    INSERT or update or delete on 'ASSIGNMENT_TIME_TRACK '.
    for each line
    Start
    update assignments
    Set time_spent = (select sum (time_spent)
    of assignment_time_track
    where assignment_time_track.name = assignments.name);

    end;
    /


    If what I posted is not clear or more detail is needed, let me know and I will respond with a full description of tables and my goals for each table. Thanks in advance for any help. I also gladly accepts links to tutorials or lessons that explain how to do this kind of thing.

    Published by: bobonthenet on March 9, 2009 14:01

    I think I understand what you mean :)

    Rather than use a trigger to keep the master table (assignments) in sync with the time spent on the details, it would be much easier to use a query to do this, maybe creating a view.

    Something along the lines of

    SQL> create table assignments
      2  (id number primary key
      3  ,name varchar2(10)
      4  );
    
    Table created.
    
    SQL>
    SQL> create table assignment_time_tbl
      2  (id number primary key
      3  ,assid number references assignments
      4  ,time_spent number
      5  );
    
    Table created.
    
    SQL>
    SQL> insert into assignments
      2  select rownum
      3       , 'a'
      4    from all_objects
      5   where rownum < 5
      6  /
    
    4 rows created.
    
    SQL>
    SQL> insert into assignment_time_tbl
      2  select rownum
      3       , rownum
      4       , rownum * 3
      5    from all_objects
      6   where rownum < 5
      7  /
    
    4 rows created.
    
    SQL>
    SQL> commit;
    
    Commit complete.
    
    SQL>
    SQL>
    SQL> select a.id
      2       , a.name
      3       , (select sum (time_spent)
      4            from assignment_time_tbl
      5           where assid = a.id
      6         )
      7    from assignments a
      8  /
    
            ID NAME       (SELECTSUM(TIME_SPENT)FROMASSIGNMENT_TIME_TBLWHEREASSID=A.ID)
    ---------- ---------- -------------------------------------------------------------
             1 a                                                                      3
             2 a                                                                      6
             3 a                                                                      9
             4 a                                                                     12
    
  • BEFORE the UPDATE trigger between field in both tables

    Hi Oracle Experts,

    I'm a newbie in the triggers. I want to do a trigger that fires whenever changes are made to a table, updates a field in the second table. The details are as below:

     SAMPLE (
    SAMPLEID    NUMBER(10,0)
    ACTIVITYID     NUMBER(10,0)
    ACTIVITYTABLEID     VARCHAR2(20 BYTE)
    SAMPLEDT     DATE
    SAMPLEPTID     VARCHAR2(20 BYTE)
    SAMPLENOTIFY     VARCHAR(1 BYTE)
    )
    

    SAMPLE_RESULT(
    SAMPLEID     NUMBER(10,0)
    TESTID     VARCHAR2(20 BYTE)
    PROPERTYID     VARCHAR2(20 BYTE)
    TESTERID     VARCHAR2(20 BYTE)
    ENTRYDT     DATE
    RESULTNUM     NUMBER(18,8)
    RESULT     VARCHAR2(20 BYTE)
    RESULTTYPE     VARCHAR(1 BYTE)
    RESULTSTATUS     VARCHAR2(1 BYTE)
    )
    

    The idea of relaxation:

    CREATE OR REPLACE
    TRIGGER "DBA".AUTO_NOTIFY
    BEFORE UPDATE OF RESULT ON SAMPLE_RESULT
    FOR EACH ROW
    WHEN (NEW.PROPERTYID = 'Action Taken')
    BEGIN
    
    //my idea
    :new.sample.samplenotify = 'S'
    
    //but i don't know how to make a reference to another table
    
    END;
    

    The trigger will fire every time the propertyid is pronounced, it sets the value of samplenotify in the example in table for the of '.

    Is this possible?

    Thank you in advance.

    La: new.column_name syntax applies only to the table that the trigger is on.  You will need to use an update on the other table.

    CREATE OR REPLACE TRIGGER auto_notify

    BEFORE the UPDATE result WE sample_result

    FOR EACH LINE

    WHEN (NEW. PROPERTYID = "Taken Action")

    BEGIN

    Example of UPDATE

    SET s = samplenotify"

    WHERE sampleid =: NEW.sampleid;

    END auto_notify;

    /

  • update a table, however I would like to save the old news in an another tabl

    Hello all; I have a table called table_one,

    That contains the following information
    carid            place
    Benz            New York
    BMW            London
    This information will usually be updated in the near future, however, I would like a situation where before information is updated, the old information is stored in another table called table_two first. for example, table_one, say that New York is so updated to Toronto, I want

    CARiD place
    Benz New York

    first recorded in table_two before the update is done. How can I do to make it. Thank you

    You can use a trigger to insert the old lines to another table.

    syntax:

    CREATE or REPLACE TRIGGER trigger_name
    BEFORE UPDATE
        ON table_name
        [ FOR EACH ROW ]
    DECLARE
        -- variable declarations
    BEGIN
        -- trigger code
    EXCEPTION
        WHEN ...
        -- exception handling
    END;
    

    for example

    CREATE OR REPLACE TRIGGER emp_before_update
    BEFORE UPDATE ON empployee FOR EACH ROW
    DECLARE
        v_username varchar2(10);
    BEGIN
        insert into employee_backup
         (employee_id,
          first_name,
          last_name)
        values
         (:old.employee_id,
          :old.first_name,
          :old.last_name);
    END;
    
  • How to write the trigger for update of 2 tables

    Hi all
    I have 2 tables,

    1.lv_data,
    It contains the following fields,
    emp_name        tot_days
     guru                    18
                
    2.leave_data
    It contains the following fields,
     emp_name          From_date              to_date            no_of_days       remaining_days
     guru                    02/05/2012          03/05/2012           2                         
    In the second table, if the data is inserted.
    the no_of_days will be calculated automatically (from to_date - From_date) + 1,

    Here, I need to write the trigger to update the remaining_days column,

    First table for all tot_days emp_name is 18 days,
    Thus, in the second table every time that the record is inserted.
    the remaining_days must be calculated as follows,

    remaining_days: = tot_days - no_of_days and this (calculated) value should be updated in the tot_days column in the first table (lv_data).

    Example:
    emp_name        tot_days
    guru                    18
                
    2.leave_data
     emp_name          From_date              to_date            no_of_days        remaining_days
     guru                    02/05/2012          03/05/2012         2                          16
    [/code  
    
    Now the first table should be updated like,
    emp_name tot_days
    Guru 16


    So I need to update to 2 tables,
    can someone help me to update these 2 tables through TRIGGER?

    Thank you
    Kind regards
    gurujothi

    Edited by: Gurujothi may 1, 2012 19:54

    It is generally considered bad practice to store the value even in 2 places. You are having the kind of problems that you are experiencing now. It is much easier to store in the main table and get the value from there where you need to show in your forms.

  • Table is the mutation of error in after the update trigger

    Hello

    In all of my table, I have columns EDITDATE and EDITUSER. So whenever a table is updated I need to update these two fields with the USER and SYSDATE. For this I use a BEFORE UPDATE trigger. This trigger is activated, but I get "ORA-04091: table %s.%s is changing, function of triggering/can not see" error every time I update the table. I used this method in SQL Server. I understand that Oracle doesn't have to be the same as SQL Server but I do not know there is a way to do this. Do you know what it is?

    EDIT: Here is the Code of the trigger

    create or replace
    TR_LEGISLATION_CALCUL_AE RELAXATION
    BEFORE THE UPDATE
    ON LEGISLATION_CALCUL
    FOR EACH LINE
    DECLARE
    v_LEGISLATIONCALCULID NUMBER (10,0);

    BEGIN
    SELECT: NEW. LEGISLATIONCALCULID

    IN v_LEGISLATIONCALCULID
    FROM DUAL;
    UPDATE LEGISLATION_CALCUL
    SET EDITUSER_ID = UID,
    EDITDATE = SYSDATE
    WHERE LEGISLATIONCALCULID = v_LEGISLATIONCALCULID;
    END;

    Published by: Mikhail on 12 March 2012 23:54

    Mikhail says:
    Hello

    In all of my table, I have columns EDITDATE and EDITUSER. So whenever a table is updated I need to update these two fields with the USER and SYSDATE. For this I use the AFTER UPDATE trigger. This trigger is activated, but I get "ORA-04091: table %s.%s is changing, function of triggering/can not see" error every time I update the table. I used this method in SQL Server. I understand that Oracle doesn't have to be the same as SQL Server but I do not know there is a way to do this. Do you know what it is?

    EDIT: Here is the Code of the trigger

    create or replace
    TR_LEGISLATION_CALCUL_AE RELAXATION
    BEFORE THE UPDATE
    ON LEGISLATION_CALCUL
    FOR EACH LINE

    just put this in your before update (and not after the update as you mentioned) for each trigger line:

    BEGIN
    
    :new.EDITUSER_ID := UID;
    :new.EDITDATE := SYSDATE;
    
    END;
    
  • Update of table as select another table

    Hi all

    How can I update column with data from another table.

    UPDATE PAR6. C CUENT
    SET C.LIMIT = 0
    WHERE
    T.EMISA = C.EMISA
    AND T.SUCUR = C.SUCUR
    AND T.PRODUCT = C.PRODUCT
    AND T.NUMER = C.NUMER
    AND T.EMISA = 8
    and T.product = 23
    AND IN t.ESTA (2, 3)

    ERROR: ora-00904 "T". "" ESTADO ": invalid identifier

    SELECT * FROM PAR6. TRE T
    WHERE T.EMISA = 8
    AND T.PRODUCT = 23
    AND T.ESTADO TO (2,3)

    Returns 26 lines.

    SELECT * FROM PAR6. C CUENT
    WHERE C.EMISA = 8
    AND C.PRODUCT = 23
    AND C.ESTADO TO (2,3)

    Returns 0 rows.

    My goal is to update the 26 lines to PAR6. Table CUENT. Is it possible or I do soometing evil in general. Any help would be appreciated.

    Thank you very much.

    Kind regards
    Robert

    >
    UPDATE PAR6. C CUENT
    SET C.LIMIT = 0
    WHERE
    T.EMISA = C.EMISA
    AND T.SUCUR = C.SUCUR
    AND T.PRODUCT = C.PRODUCT
    AND T.NUMER = C.NUMER
    AND T.EMISA = 8
    and T.product = 23
    AND IN t.ESTA (2, 3)
    >

    Something like that.

    UPDATE PAR6.CUENT C
    SET C.LIMIT=0
    WHERE exists (select null from PAR6.TAR T
                         where
                                  T.EMISA=C.EMISA
                           AND T.SUCUR=C.SUCUR
                           AND T.PRODUCT=C.PRODUCT
                           AND T.NUMER=C.NUMER
                           AND T.EMISA = 8
                           and T.product = 23
                           AND t.ESTA IN (2, 3)
                         )
    

    Visit this link for more information about correlated subqueries.

    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/queries007.htm

    Thank you

    REDA

    @Sybrand: my apologies, I didn't see your post when I posted. However, I like the way you approach.

    Published by: Raj on May 27, 2011 02:11
    @Sybrand: my apologies, I didn't see your post when I posted. However, I like the way you approach.

  • Update of the table based on another

    Hello

    I'm trying to update a date column in a table based on another table. There is a unique ID in each table that identifies and connects each person:
    update patient_bu a set a.entry_date = (select b.entry_date from CLIENT_MED_DT b where a.id = b.id)
    This is the error:

    ORA-01427: einreihig subquery returns multiple rows


    The problem (I think) is that the select statement back several dates for records people. There are some people / records that have multiple entry dates, but I'm only interested in the most recent date.

    How can I update this table with only the most recent date?

    Thanks for any help,
    Matt

    Oh well, I forgot the UPDATE clause:

    SQL> create table patient_bu
      2  (id number
      3  ,entry_date date);
    
    Table created.
    
    SQL> create table client_met_dt
      2  (id number
      3  ,entry_date date);
    
    Table created.
    
    SQL> merge into patient_bu a
      2  using (select id
      3               ,max(entry_date) max_date
      4         from   client_met_dt
      5         group  by id
      6        ) b
      7  on    (a.id = b.id)
      8  when  matched then update
      9        set a.entry_date = b.max_date;
    
    0 rows merged.
    
  • Update of table column in this table corresponds with another table

    UPDATE of table column where this table corresponds to a column with another table of columns,
    Example:

    I need to update column in the table SIEBEL_ASSETS MATACH_FLAG = 'Yes' when less than the conditions of the
    Select a.*, SIEBEL_ASSETS a, gis_cad, c
    where upper (a.Province) = upper (c.province)
    and upper (a.TOWNSHIP_NAME_EXT) = upper (c.suburb)
    and a.Stand_ # = c.ERF_NO
    update siebel_assets a
    set    match_flag = 'yes'
    where  exists (select 1
                   from   gis_cad c
                   where  upper(a.Province) = upper(c.province)
                   and    upper(a.TOWNSHIP_NAME_EXT) = upper(c.suburb)
                   and    a.Stand_# = c.ERF_NO
                  )
    ;
    
  • How can simple trigger for verification of status update on the table... - I get upd sql then?

    Hi guys,.

    I need to do a temporary simple audit on all updates on a table.

    That's why I create a trigger for her...

    However, I need to capture the SQL statement to make the update as well... However I have no way to do it, because it is always replaced by a SQL code I run to get the SESSION ID...

    Here is the trigger...
    ----------------------

    create or replace
    alert_setting_trg relaxation
    before the update on user_alert_settings
    for each line
    declare
    number of v_sid;
    v_username varchar2 (100);
    v_osuser varchar2 (100);
    v_machine varchar2 (100);
    v_program varchar2 (100);
    v_module varchar2 (100);
    v_prevsqlid varchar2 (100);
    v_sqltext varchar2 (100);

    Start
    SELECT SYS_CONTEXT ('USERENV', 'SID')
    IN v_sid
    FROM DUAL;

    SELECT the username, osuser, machine, program, module, PREV_SQL_ID
    IN v_username, v_osuser, v_machine, v_program, v_module, v_prevsqlid
    SESSION $ v where SID = v_sid;

    SELECT sql_text
    IN v_sqltext
    V $ sqltext
    WHERE SQL_ID = v_prevsqlid;

    INSERT INTO alert_settings_log
    VALUES (sysdate, v_sid, v_username, v_osuser, v_machine, v_program, v_module, v_sqltext,: new.user_id,: new.service_grp,: new.alert_setting_id,: old.alert_active,: new.alert_active);

    end;


    Now the problem is that...
    the capture of SQL statement will always be

    SELECT SYS_CONTEXT ('USERENV', 'SID')
    IN v_sid
    FROM DUAL;


    and not the UPDATE table statement.

    1st quarter) I have to get the SID of the session before I could know what SQL it is running.

    However, once I get the SID, the SQL to UPDATE the SID is run changes the SQL that gets the SID.

    What can I do?

    Rgds,
    Noob

    Instead of to the request in three steps, do it in 1. Replace all three of your queries with something like:

    SELECT s.username, s.osuser, s.machine, s.program, s.module, q.sql_text
    INTO v_username, v_osuser, v_machine, v_program, v_module, v_sqltext
    FROM v$session s, v$sql_area q
    WHERE s.sid = SYS_CONTEXT('USERENV','SID') and
          s.prev_sql_id = q.sql_id
    

    John

  • Insert/update of the lines in tabular form from one table to another table

    Hello

    I'm having a tabular presentation for a table (equip_test) with 2 columns (equip_id, equip_name). I create a new

    Button (submit_alt) in this tabular form. I need to insert or update lines that are changed in this table to form

    another table (equip_staging) when you press the submit_alt button. How can I do this? How can I identify which lines are

    Insert or update? The process of the page I am trying since this button is
    begin
    
    FOR i in 1..APEX_APPLICATION.G_F01.count
    
    LOOP
    insert into equip_staging values(APEX_APPLICATION.G_F02(i),APEX_APPLICATION.G_F03(i));
    END LOOP;
    
    end;
    But it does not work. Help, please

    Thank you

    TJ

    Unchecking (does not) the column is a problem. Use this SQL instead (which is included in my examples):

    SELECT empno,
              empno
           || apex_item.hidden (33, wwv_flow_item.md5 (ename, sal, job))
                                                                    empno_display,
           ename, sal, job
      FROM emp
    

    and join this column hidden from your display column. In this way, it should work. When you feel there is no data found message in the treatment in a table, it will mean that the id does not exist.

    Denes Kubicek
    ------------------------------------------------------------------------------
    http://deneskubicek.blogspot.com/
    http://www.Opal-consulting.de/training
    http://Apex.Oracle.com/pls/OTN/f?p=31517:1
    ------------------------------------------------------------------------------

  • Update of Table to another Table in another DB

    I have 2 different tables in 2 different bases.  We'll call it base1 table1 and table2 of base2.  I want to update table1 in database1 based on data residing in table2 in base2.  Both Oracle 11 g.  I wrote a script, but it is the most effective way to perform the update?

    What I'm doing...

    I want to compare the data from the source (table 2) and update my target (table 1) data based on a perfect match.  I want to update the respective fields in table1 with the data in table2, if and only if, there is a perfect match of the table1_key = table2_key fields.  If it finds the match, and then it retrieves the respective data and maps it to its respective columns.

    declare

    cursor c1 is

    SELECT * FROM schema2.table2@mydblink WHERE table2_key IS NOT NULL;

    Start

    I'm in c1 LOOP

    UPDATE table1 t1

    SET table1_c1 = i.table2_c1,

    table1_c2 is i.table2_c2,

    table1_c3 is i.table2_c3,

    table1_c4 is i.table2_c4,

    table1_c5 is i.table2_c5,

    table1_c6 is i.table2_c6,

    table1_c7 is i.table2_c7

    where exists (select 1 from classdefinition cd where t1.object_class_id = cd.object_id and cd.symbolic_name = 'DC' t1.table1_key is not null and t1.table1_c1 is null and t1.table1_key = i.table2_key);

    END LOOP;

    END;

    /

    output

    Any suggestion is appreciated.  Thank you!!

    Select * from table2@mydblink where table2_key = 'xxx '; -Search registration

    If you have two rows are you can update two rows. You can't wait to update three.

    Char (30) is more convenient, please change to VARCHAR2 as soon as POSSIBLE.

    You should now use TRIM (table1_key) = (table2_key) TRIM to match just like CHAR autopad space at the end.

  • Update the values in the Table from another Table containing historical data

    So, I have two tables, a table and a master table.  The current table is updated each week and at the end of the week, is copied to the main table to keep historical data.  I have update the table in progress early in the week and want to take the latest data from the master table and update the current table with the data.  The current table could have additional IDs or some of the IDS could have deposited (these lines would receive data in the main table).  I want to only update the rows in the current table that have existing data to the attr1, attr2, attr3 columns.  A particular ID may have more than one record in the primary table, I want only the last disk to use for updating the current table.  The data from a different database where no direct connection is possible then I have to import data every week.  Here are some statements of create/insert:

    create table current_T (ID1 varchar(100),adate date,attr1 varchar(100),attr2 varchar(100),attr3 varchar(100))
    

    create table Master_T (ID1 varchar(100),adate date,attr1 varchar(100),attr2 varchar(100),attr3 varchar(100))
    
    

    begin
    insert into current_T (ID1,adate)
    values ('IE111','08/02/13');
    insert into current_T (ID1,adate)
    values ('IE112','08/02/13');
    insert into current_T (ID1,adate)
    values ('IE113','08/02/13');
    
    insert into master_T (ID1,adate,attr1,attr2,attr3)
    values ('IE111','08/01/13','yes','abc','123');
    insert into master_T (ID1,adate,attr1,attr2,attr3)
    values ('IE112','08/01/13','no','dgf','951');
    insert into master_T (ID1,adate,attr1,attr2,attr3)
    values ('IE113','08/01/13','no','dgf','951');
    insert into master_T (ID1,adate,attr1,attr2,attr3)
    values ('IE113','07/01/13','no','dgf','951');
    end;
    

    This has been a scratcher for me head and any help would be greatly appreciated.  I'm coding in Apex 4.1

    Thank you

    -Steve

    Not tested

    merge into current_t c

    using (select *)

    Of

    (select m.*

    row_number() over (partition by m.id1 m.adate DESC order) rn

    of master_t m

    )

    where rn = 1

    ) u

    on (c.id1 = u.id1)

    When matched then update

    Set c.adate = u.adate

    c.attr1 = u.attr1,

    c.attr2 = u.attr2,

    c.attr3 = u.attr3,

    When not matched then insert

    (c.id1, c.adate, c.attr1, c.attr2, c.attr3)

    values

    (u.id1, u.adate, u.attr1, u.attr2, u.attr3)

    ;

Maybe you are looking for