Select cursor for update: multiple columns of different tables

Hello

I have two tables test1 and test2. I want to udpate the column (DEPT_DSCR) from the TEST1 and TEST2 using select for update and current tables of the... with the cursor.

I have a code drafted as follows:
DECLARE
v_mydept1 TEST1. TYPE % DEPT_CD;
v_mydept2 TEST2. TYPE % DEPT_CD;
CURSOR C1 IS SELECT TEST1. DEPT_CD, TEST2. DEPT_CD OF TEST1, TEST2 WHERE TEST1. DEPT_CD = TEST2. DEPT_CD AND TEST1. DEPT_CD IS 'AA' FOR THE UPDATE OF TEST1. DEPT_DSCR, TEST2. DEPT_DSCR;
BEGIN
OPEN C1;
LOOP
FETCH C1 INTO v_mydept1, v_mydept2;
WHEN EXIT C1% NOTFOUND;
UPDATE TEST1 SET DEPT_DSCR IS "PLSQL1" WHERE CURRENT OF C1;.
SETTING A DAY TEST2 SET DEPT_DSCR = 'PLSQL2' WHERE CURRENT OF C1.
END LOOP;
COMMIT;
END;

The code above when it is run, declares that it runs successfully. But it does not update the columns you want [DEPT_DSCR].

It works only when we want to update one or more columns of the same table... i. e by providing these columns after ' to UPDATE THE.
I don't know what exactly is the problem when you want to update several columns of different tables.

Can someone help me on this?

user12944938 wrote:
But it's more the notion of compensation and understanding.

See the link below:
http://download.Oracle.com/docs/CD/B10501_01/AppDev.920/a97269/pc_06sql.htm

See the section RESTRICTION in the link above.

Twinkle

Tags: Database

Similar Questions

  • Update multiple columns from multiple tables in a single UPDATE request

    Hello

    I'm trying to figure if I'm heading in the right direction.

    I want to update multiple columns from multiple tables in a single UPDATE request. Also, I would like to update multiple columns in a table from the tables.

    Scenario 1

    UPDATE Table2, Table 3
    SET T2.Column1 = T1.Column1 
    ,T2.Column2 = T1.Column2
    ,T3.Column2 = T1.Column2
    FROM Table1 T1, Table2 T2, Table3 T3
    WHERE T1.id = T2.id
    and T1.id = T3.id
    
    

    Scenario 2

    UPDATE Table3
    SET T3.Column1 = T1.Column1 
    T3.Column2 = T1.Column2
    ,T3.Column3 = T2.Column3
    ,T3.Column4 = T2.Column4
    FROM Table1 T1, Table2 T2, Table3 T3
    WHERE T3.id = T1.id
    and T3.id = T2.id
    
    

    Hello

    For scenario 1, you must write separate instructions UPDATE table2 and table3.

    To guard against someone else change one of these tables while you act so you can copy all relevant data in a global temporary table and update this global temporary table table3.

    ENGAGE only when two tables have been changed.

    You can write a procedure or an INSTEAD OF trigger to do all this.

    For scenario 2, you can reference many tables that you need when new table3.  It might be more efficient and simpler to use the MERGER rather than UPDATED.  For example:

    MERGE INTO table3 dst

    WITH THE HELP OF)

    SELECT t1.id

    t1.column1

    t1.column2

    t2.column3

    t2.column4

    FROM table1 t1

    JOIN table2 t2 ON t1.id = t2.id

    )             src

    WE (dst.id = src_id

    WHEN MATCHED THEN UPDATE

    SET dst.column1 = src.column1

    dst.column2 = src.column2,

    dst.column3 = src.column3,

    dst.column4 = src.column4,

    ;

  • PL SQL program unit does not compile with cursor for UPDATE NOWAIT

    All,

    I am trying to use a cursor for UPDATE NOWAIT to avoid hung sessions on the shape of the front end.

    I am using a syntax such as:

    CURSOR my_cur (p_val)
    IS
    SELECT 1
    FROM my_table
    WHERE my_col = p_val
    FOR UPDATE NOWAIT.

    However, later in the procedure, when I try to refer to the cursor with the following syntax:
    (after opening/get the cursor...)

    UPDATE my_table
    SET my_col2 =: MY_BLOCK. FOO
    WHERE CURRENT OF my_cur;

    I get the following compilation error:
    Error 404 on line 140, column 30
    cursor 'MY_CUR' must be declared with to use with the CURRENT UPDATES OF

    The strange thing is that if I remove the "NOWAIT" keyword, the program unit compiles.

    If nothing else has noticed this? No workaround or patch solution? Is this a known bug?

    Thank you very much
    -Chris

    Try one

    FOR UPDATE OF ID NOWAIT;
    

    where ID is the name of a column in the table.

  • How update the column in the table based on the value selected in apex4.1

    Hi all
    I have the following tables,
    leave_type table,it has the following fields,
    1.emp_name,
    2.sick
    3.casual
    and it has the values as follows,
    emp_name                  sick             casual
    guru                           10                10
    mishra                         10                10
    leave_master table and it includes the following fields
    1.emp_name,
    2.leave_type
    3.no_of_days
    I have the form based on the table "leave_master"
    Here, the leave_type has the LOV which includes.
    sick and casual.

    When the form is filled out and clicked on the button submit,
    I need to update the column leave_type in table leave_type,
    for example,.
    if 
    emp_name:guru
    leave_type:sick
    no_of_days:3
    then I want to update the leave_type column,
    sick sick = - no_of_days for the 'guru' of name
    That is to say, ill = 10-3 = 7

    then the leave_type of the table must be,
    emp_name                       sick             casual
    guru                                 7                10
    mishra                              10               10
    someone can such me what code or method I can use?
    Thank you.

    Published by: Gurujothi on May 24, 2012 21:54

    Published by: Gurujothi on May 24, 2012 21:54

    Try something like this...

    BEGIN
    IF: PXX_LEAVE_TYPE = "Sick" THEN
    UPDATE LEAVE_TYPE
    THE PATIENT VALUE = SICK -: PXX_NO_OF_DAYS
    WHERE EMP_NAME =: PXX_EMP_NAME;
    ON THE OTHER
    UPDATE LEAVE_TYPE
    DEFINE CASUAL = CASUAL -: PXX_NO_OF_DAYS
    WHERE EMP_NAME =: PXX_EMP_NAME;
    END IF;
    COMMIT;
    END;

  • UPDATE multiple columns with conditional parameters

    I have a procedure that updates several columns of a table using the parameter of the procedure. Is it possible to have a update unique with the parameter SET conditional statement?
    CREATE TABLE TEMP
    (POL_NUM NUMBER,
    OED DATE,
    TERM NUMBER,
    TRANS_CD CHAR(2));
    
    INSERT INTO TEMP VALUES (1, '1 AUG 2009', 12, 'NB');
    INSERT INTO TEMP VALUES (2, '4 AUG 2009', 12, 'XL');
    INSERT INTO TEMP VALUES (3, '2 AUG 2009', 12, 'RN');
    COMMIT;
    
    CREATE OR REPLACE PROCEDURE TMP_PROC (
      pPOL_NUM NUMBER,
      pOED IN DATE,
      pTERM IN NUMBER,
      pTRANS_CD CHAR2)
    AS
    BEGIN
      IF pOED IS NOT NULL THEN
        UPDATE TEMP SET OED = pOED WHERE POL_NUM = pPOL_NUM;
      END IF;
    
      IF pTERM IS NOT NULL THEN
        UPDATE TEMP SET TERM = pTERM WHERE POL_NUM = pPOL_NUM;
      END IF;
    
      IF pTRAN_CD IS NOT NULL THEN
        UPDATE TEMP SET TRANS_CD = pTRANS_CD WHERE POL_NUM = pPOL_NUM;
      END IF;
      COMMIT;
    EXCEPTION
      WHEN OTHERS THEN
         NULL;
    END;
    Is it possible to replace several IFs code to have only one UPDATE statement with the condition that update the column only if the parameter passed is not null? In the real world scenario, I have more than 3 columns and I do not want to write lots of IF blocks.

    Please help gurus!

    Published by: Kuul13 on September 18, 2009 13:26

    Hello

    Maybe this,.

    Create OR Replace Procedure TMP_PROC( pPOL_NUM  IN Number
                                        , pOED      IN Date
                                        , pTERM     IN Number
                                        , pTRANS_CD IN Varchar2 ) As
    Begin
       UPDATE TEMP
          SET OED      = NVL(POED     , OED )
            , TERM     = NVL(PTERM    , TERM )
            , TRANS_CD = NVL(PTRANS_CD, TRANS_CD )
        WHERE POL_NUM = PPOL_NUM;
       Commit;
    Exception
       When Others Then
          Null;
    End;
    

    Kind regards
    Christian Balz

  • Display and update of fields in different tables on the same page.

    I am facing two problems...

    (1) I have a report on which I show several fields of 4 different tables. For each row of data, there is a link to change on the first column. By clicking on the link change, I show you a form where I want to show the respective data. On the link change, even if I send you the data in the report, they do not appear on the form (what edit link is clicked). Also, there is only room for 3 items to ship through the link change.
    How to display the data correctly on the form? Is there another way to use the link change?

    (2) on the form, how do I update the data from different tables?

    Thank you

    Gargi

    Hi Lisa,

    The text of presentation on the INSTEAD OF triggers is in: [http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_7004.htm#sthref7918]

    First of all, your SQL View contains a unique key so that your triggers and the two Apex know what is updated.

    Then, you can create instead of triggers for "instead of INSERT ON viewname", 'instead of UPDATE ON viewname' and 'DELETE ON viewname' on your SQL view. What do these triggers depends on what you need. In the trigger code, you refer to new data using: NEW.column_name and old data using: OLD.column_name (updates both: OLD and: NEW values).

    I'm not sure of the SEPARATE, the GROUP IN question. You would certainly have a unique key on each record. It could be that the DISTINCT or GROUP BY clause will have to be taken out of the SQL view and is part of the source of the region, so that the SQL view does nothing with the data other than to join several tables in a single "table" from the Primary Key/Foreign Key relationship.

    Andy

  • Oracle how to multiply two columns of different tables and results

    Oracle how to multiply two columns of different tables and get the result in the third column?

    I want to multiply all the lines of the quantinty column in the table of quantity with the relevant lines of the table of prices price column and get the result of multiplying in the third column. What should I use procedure trigerr? OR IS IT POSSIBLE HOW TO DO IT PLEASE HELP :D

    Edited by: 994229 2013-03-15 12:44
    /* Formatted on 3/15/2013 3:51:08 PM (QP5 v5.185.11230.41888) */
    CREATE TABLE mytable1
    AS
       (SELECT 1 id, 5 VALUE FROM DUAL
        UNION ALL
        SELECT 2, 7 FROM DUAL
        UNION ALL
        SELECT 3, 8 FROM DUAL);
    
    CREATE TABLE mytable2
    AS
       (SELECT 1 id, 4 VALUE FROM DUAL
        UNION ALL
        SELECT 2, 12 FROM DUAL
        UNION ALL
        SELECT 10, 12 FROM DUAL);
    
      SELECT id,
             mytable1.VALUE,
             mytable2.VALUE,
             mytable1.VALUE * mytable2.VALUE product
        FROM mytable1 FULL OUTER JOIN mytable2 USING (id)
    ORDER BY id;
    
    ID     VALUE     VALUE_1     PRODUCT
    1     5     4     20
    2     7     12     84
    3     8
    10          12     
    
  • How to set the color for a particular column in the table in advance?

    How can we set the color for a particular column in advance table based on a few feteched of vo in process request query parameter?

    Hello

    Reference http://oraclearea51.com/blog/dynamically-color-the-rows-in-an-oa-framework-advanced-table.html

    and prev thread. Can color us the lines in the column of a table

    It will be useful.

    Kind regards
    GYAN

  • PL/SQL with cursor for update another slider

    Hi all

    I'm doing the sub process... I just wrote this code for example... can someone give me idea how to
    This... I have attached the error msg that I am below...

    CREATE OR REPLACE PROCEDURE EMP_COMPARE
    AS

    CURSOR c_emp_err
    IS
    SELECT EMPNO IN EMP_ERR;

    CURSOR c_emp_cur
    IS
    SELECT EMPNO, FRST_NAME, LAST_NAME
    FROM EMP WHERE DEPTNO = 20;

    BEGIN

    FOR r_emp IN c_emp_cur
    LOOP
    IF r_emp. EMPNO NOT IN CHOICE - INCLUDING the EMP (c_emp_err) WHO are IN THE error TABLE
    THEN
    UPDATE EMP SET APPLY_DATE = SYSDATE
    WHERE EMPNO = r_emp. EMPNO;
    END IF;
    END LOOP;

    END;

    ERR: PLS-00320: the declaration of the type of the expression is incomplete or incorrect

    Thanks in advance...

    Hello

    I see.
    My answer is always application: do not use the sliders if you don't have to. Looking for a way to do what you need to use only the SQL statements.

    If you really not to use the two sliders, where some values in a come on the other, you can have nested cursors.
    For example, the use of scott tables, you want to give a raise of 10% for all salaray everyone in any department based in a given city.
    You may have two sliders:
    (1) find each department based in the city of right
    (2) find every employee in the Department of (1)

    CREATE OR REPLACE PROCEDURE     slow_update
    (     in_city_name     IN     VARCHAR2
    )
    AS
         CURSOR     dept_csr     (target_loc     VARCHAR2)
         IS     SELECT     deptno
              FROM     dept
              WHERE     loc     = UPPER (target_loc);
    
         CURSOR     emp_csr     (target_deptno     NUMBER)
         IS     SELECT     empno
              FROM     emp
              WHERE     deptno     = target_deptno;
    BEGIN
         FOR     dept_rec IN dept_csr (in_city_name)
         LOOP
              FOR     emp_rec IN emp_csr (dept_rec.deptno)
              LOOP
                   UPDATE     emp
                   SET     sal     = sal * 1.1
                   WHERE     empno     = emp_rec.empno;
              END LOOP;
         END LOOP;
    END     slow_update;
    

    Notice how I used parameters in the sliders.

    You must perform the procedure as follows:

    EXECUTE  slow_update ('Dallas');
    

    Repeat: This is only for demonstration purposes.
    The smart way to do such an UPDATE does not require the sliders or PL/SQL:

    UPDATE     emp
    SET     sal     = sal * 1.1
    WHERE     deptno     IN     (
                   SELECT     deptno
                   FROM     dept
                   WHERE     loc     = UPPER (:target_city_name)
                   );
    
  • I'm trying to update Firefox by clicking 'Help' but I cannot select "Check for Updates". Help!

    There are several Web sites and online services that become a problem or are unusable for me because I don't have the latest version of Firefox. But I tried to update and cannot. I go to the 'Help' drop, and the "Check For Updates" option is greyed out and unselectable. Help, please!

    If he has problems with the update or the permissions then simpler is to download the full version and trash the version currently installed to do a clean install of the new version.

    Download a new copy of the Firefox program and save the file on the desktop disk image (dmg)

    • Trash the present application Firefox to do a clean (re-) install
    • Install the new version you downloaded

    Your profile data is stored in the Firefox profile folder, so you will not lose your bookmarks and other personal data.

  • Automatically update the column in the table in OBIEE

    Hi people,

    I have a requirement to say I need to update a column of table based on a condition, but this update should happen on a daily basis (I mean that it would be held once per day) by checking if all the records in this column meets the condition then update

    example:-column = 'pending', then using the "approved". As records of transactions every day in the table lights. OBIEE should check and update the line so the next time it does not show this line as "pending".

    I thought of 2 approaches to this
    (1) through the write-back, it is possible to update but manually (the question is it can't be automated or on demand on daily basis and update multiple records on a go)
    (2) write a stored procedure or a function of update, but how can I perform this procedure either regular or run once daily.how to use it?

    Any thoughts on the above two points or any method you can think off the coast.

    Any help is appreciated!

    See you soon,.
    KK

    Murielle,

    This shud be easy...
    -Create a direct database... with the Update statement
    for example: Update table set col = "Approved" where col = 'pending '.
    -Create an ibot using the RFI above and plan on a daily basis.

    This will update the complete table with the new value on a daily basis based on the State

  • Update multiple rows in a table at a time

    Hi all

    I write a stored procedure that fills all columns in a table, that table with a query with the exception of a single column, say 'ABC' column in this table. I have to load this left on column using a different query that refers to some other tables. How can I update this column 'ABC' with all its rows of data from a different query?

    Thank you very much!!

    If you post an update with a create table and insert statements, it would be useful... I think that you want to update a table with a select from another table using a join... is that correct?

    c customer update
    Set client_name =)
    Select client_name
    of another_customer_table one
    where a.customer_id = c.customer_id_from_original_customer_table
    )
    where c.customer_id in (select customer_id from another_customer_table)

    Where clause is required only if you don't want to update missing customer_ids to null.

  • Problem updating multiple rows in the table using subquery

    Hi everyone, I can't update multiple lines with a subquery. Here is the configuration:
    create table mytable (
    col_a number primary key,
    col_b number,
    col_c number,
    col_d number);
    
    insert into mytable values (1 ,1,1,15);
    insert into mytable values (2 ,1,2,7 );
    insert into mytable values (3 ,1,3,11);
    insert into mytable values (4 ,1,4,23);
    insert into mytable values (5 ,1,5,14);
    insert into mytable values (6 ,2,1,50);
    insert into mytable values (7 ,2,2,41);
    insert into mytable values (8 ,2,3,13);
    insert into mytable values (9 ,2,4,12);
    insert into mytable values (10,2,5,19);
    insert into mytable values (11,3,1,10);
    insert into mytable values (12,3,2,92);
    insert into mytable values (13,3,3,81);
    insert into mytable values (14,3,4,17);
    insert into mytable values (15,3,5,66);
    insert into mytable values (16,4,1,54);
    insert into mytable values (17,4,2,41);
    insert into mytable values (18,4,3,22);
    insert into mytable values (19,4,4,24);
    insert into mytable values (20,4,5,17);
    For this example, by using an update statement (or merge if this is better), I mean set values for col_d where col_b = 3 equal to that of the col_d where col_b = 1 and col_c equal between them. Results should resemble the following after the update:
    col_a col_b col_c col_d
    1     1     1     15
    2     1     2     7
    3     1     3     11
    4     1     4     23
    5     1     5     14
    6     2     1     50
    7     2     2     41
    8     2     3     13
    9     2     4     12
    10    2     5     19
    11    3     1     15
    12    3     2     7
    13    3     3     11
    14    3     4     23
    15    3     5     14
    16    4     1     54
    17    4     2     41
    18    4     3     22
    19    4     4     24
    20    4     5     17
    I see her there within my reach using this query, where I want to put b_col_d = a_col_d, but miss me something, this query returns too many rows when it is used in the update statement.
    select * from (
      select col_a as a_col_a, col_b as a_col_b, col_c as a_col_c, col_d as a_col_d
      from mytable
      where col_b = 1
      ) a, (
      select col_a as b_col_a, col_b as b_col_b, col_c as b_col_c, col_d as b_col_d
      from mytable
      where col_b = 3
      ) b
    where a.a_col_c = b.b_col_c
    Update column_d set mytable = (select? where?)

    Can someone help me get there? I use 10 gr 2.

    Thank you!
    Mark

    I hope that's what you're looking for:

    SQL > UPDATE mytable myt1
      2  SET    col_d = ( SELECT myt2.col_d
      3                   FROM   mytable myt2
      4                   WHERE  myt2.col_b = 1
      5                   AND    myt1.col_c = myt2.col_c
      6                 )
      7  WHERE  col_b = 3
      8  AND    EXISTS
      9         ( SELECT NULL
     10           FROM   mytable myt2
     11           WHERE  myt2.col_c = myt1.col_c
     12         )
     13  ;
    
    5 rows updated.
    
    SQL > SELECT * FROM mytable ORDER BY col_a;
    
                   COL_A                COL_B                COL_C                COL_D
    -------------------- -------------------- -------------------- --------------------
                       1                    1                    1                   15
                       2                    1                    2                    7
                       3                    1                    3                   11
                       4                    1                    4                   23
                       5                    1                    5                   14
                       6                    2                    1                   50
                       7                    2                    2                   41
                       8                    2                    3                   13
                       9                    2                    4                   12
                      10                    2                    5                   19
                      11                    3                    1                   15
                      12                    3                    2                    7
                      13                    3                    3                   11
                      14                    3                    4                   23
                      15                    3                    5                   14
                      16                    4                    1                   54
                      17                    4                    2                   41
                      18                    4                    3                   22
                      19                    4                    4                   24
                      20                    4                    5                   17
    
    20 rows selected.
    

    Thank you very much for providing the sample data in a format that is easy to consume form, as well as the expected results.

  • How to update exists column on the table with the exact number and auto increment

    Hello

    I have a table with more than 10 million rows and there is a column called 'number_zaq', I want to update this column on line frist from 2000 and + 1 for the next all ranks.

    Update your_table

    Set number_zaq = rownum + 2000-1;

  • How to upgrade all the record for a particular column in a table based on search criteria.

    Hi all

    I'm new to ADF. I have a requirement where I have to perform the update of mass on a table.

    Scenario:

    Ex: I have a search region manual dept. where I search with deptId: 20. I get 20 records in my table. now I have another area where I have an inputchoice list that contains all the column names that exist in the dept table. Beside that, I have a text box and a button update

    The user now, first research with dept id: 20 and click on the button Search, where it shows 20 record in the table. He then select an input choicelist(ex: ManagerId) column, then enter the new value in the decision-making box(ex: abc) then click on the button update.

    Now, I want to, all the records in the ManagerId column with dept id: 20 update with the new value 'abc '.

    Can someone help me with the code.

    Thanks in advance...

    Hello

    If you go to your VO and generate the ViewObjectImpl, here you can create a method that contains two parameters, 1 the name attribute and 2 the value.

    Then you can follow something as explained in this post:

    ADF tutorial: how to apply actions in bulk to a view object lines

    The only difference is that you must create a method like this:

    ' Public Sub updateAttribute (attribute String, Integer value) {}

    RowSetIterator iter = createRowSetIterator (null);

    While (iter.hasNext ()) {}

    Line = iter.next ();

    row.setAttribute (attribute, value);

    }

    }

    Then execute you who expose a customer interface and then after you filter your table according to your criteria just this method passing the correct parameters.

    Concerning

Maybe you are looking for