How to update multiple columns from different tables using cursor.

Hi,
i have two tables test1 and test2. i want to udpate the column(DEPT_DSCR) of both the tables TEST1 and TEST2 using select for update and current of...using cursor.
I have a code written as follows :
DECLARE
v_mydept1 TEST1.DEPT_CD%TYPE;
v_mydept2 TEST2.DEPT_CD%TYPE;
CURSOR C1 IS SELECT TEST1.DEPT_CD,TEST2.DEPT_CD FROM TEST1,TEST2 WHERE TEST1.DEPT_CD = TEST2.DEPT_CD AND TEST1.DEPT_CD = 'AA' FOR UPDATE OF TEST1.DEPT_DSCR,TEST2.DEPT_DSCR;
BEGIN
OPEN C1;
     LOOP
          FETCH C1 INTO v_mydept1,v_mydept2;
          EXIT WHEN C1%NOTFOUND;
          UPDATE TEST2 SET DEPT_DSCR = 'PLSQL1' WHERE CURRENT OF C1;
          UPDATE TEST2 SET DEPT_DSCR = 'PLSQL2' WHERE CURRENT OF C1;
     END LOOP;
     COMMIT;
END;
The above code when run says that it runs successfully. But it does not updates the desired columns[DEPT_DSCR].
It only works when we want to update single or multiple columns of same table...i.e. by providing these columns after "FOR UPDATE OF"
I am not sure what is the exact problem when we want to update multiple columns of different tables.
Can anyone help me on this ?

oops my mistake.....typo mistake...it should have been as follows --
UPDATE TEST1 SET DEPT_DSCR = 'PLSQL1' WHERE CURRENT OF C1;
UPDATE TEST2 SET DEPT_DSCR = 'PLSQL2' WHERE CURRENT OF C1;
Now here is the upated PL/SQL code where we are trying to update columns of different tables --
DECLARE
v_mydept1 TEST1.DEPT_CD%TYPE;
v_mydept2 TEST2.DEPT_CD%TYPE;
CURSOR C1 IS SELECT TEST1.DEPT_CD,TEST2.DEPT_CD FROM TEST1,TEST2 WHERE TEST1.DEPT_CD = TEST2.DEPT_CD AND TEST1.DEPT_CD = 'AA' FOR UPDATE OF TEST1.DEPT_DSCR,TEST2.DEPT_DSCR;
BEGIN
OPEN C1;
LOOP
FETCH C1 INTO v_mydept1,v_mydept2;
EXIT WHEN C1%NOTFOUND;
UPDATE TEST1 SET DEPT_DSCR = 'PLSQL1' WHERE CURRENT OF C1;
UPDATE TEST2 SET DEPT_DSCR = 'PLSQL2' WHERE CURRENT OF C1;
END LOOP;
COMMIT;
END;
Please let us know why it is not updating by using using CURRENT OF

Similar Messages

  • How to Query Multiple Fields from different Tables using Toplink Expression

    Hi,
    I am trying to prepare an Oracle Toplink Expression to qurey the multiple columns of different tables. the query as following. Please can anyone help?
    SELECT CYCLE.CYCLE_ID,
    CYCLE.ASPCUSTOMER_ID,
    CYCLE.FACILITYHEADER_ID,
    CYCLE.ADDUSER,
    ASP.FIRSTNAME || ' ' || ASP.LASTNAME ADDUSERNAME,
    CYCLE.ADDDATE,
    CYCLE.LASTUPDATEUSER,
    ASP.FIRSTNAME || ' ' || ASP.LASTNAME LASTUPDATEUSERNAME,
    CYCLE.LASTUPDATEDATE,
    CYCLE.CYCLENAME,
    CYCLE.CYCLENUMBER,
    CYCLE.DESCRIPTION
    FROM CYCLE,ASPUSER ASP
    WHERE CYCLE.ADDUSER = ASP.ASPUSER_ID
    and then i want to send that expression to readAllObjects method as a parameter
    Expression exp = (..............this is the required qurey expression...................)
    Vector employees = session.readAllObjects(getClass(), exp);
    thanks,

    You havent given any information on the mapping between Cycle and Asp. I presume there is a one to one mapping between them. Also it appears there is no "WHERE" clause to limit the number of cycles being retrieved. If that is the case then I presume you want to load all cycles in the system.
    Thats just a clientSession.readAllObjects(Cycle.class). If you have indirection turned on the Asp should get loaded when you do a cycle.getAsp().
    I presume that SQL you posted loads all the columns of CYCLE and ASP. If you are interested in a subset of CYCLE or ASP then you should do a ReportQuery or partial object read.
    Hi,
    I am trying to prepare an Oracle Toplink Expression
    to qurey the multiple columns of different tables.
    the query as following. Please can anyone help?
    SELECT CYCLE.CYCLE_ID,
    CYCLE.ASPCUSTOMER_ID,
    CYCLE.FACILITYHEADER_ID,
    CYCLE.ADDUSER,
    ASP.FIRSTNAME || ' ' || ASP.LASTNAME ADDUSERNAME,
    CYCLE.ADDDATE,
    CYCLE.LASTUPDATEUSER,
    ASP.FIRSTNAME || ' ' || ASP.LASTNAME
    LASTUPDATEUSERNAME,
    CYCLE.LASTUPDATEDATE,
    CYCLE.CYCLENAME,
    CYCLE.CYCLENUMBER,
    CYCLE.DESCRIPTION
    FROM CYCLE,ASPUSER ASP
    WHERE CYCLE.ADDUSER = ASP.ASPUSER_ID
    and then i want to send that expression to
    readAllObjects method as a parameter
    Expression exp = (..............this is the required
    qurey expression...................)
    Vector employees = session.readAllObjects(getClass(),
    exp);
    thanks,

  • How to display multiple data from different table in one table? please help

    Hi
    I got sun java studio creator 2(the separate installation not the one in the net beans)....
    My question is about displaying data that have been taken from the database.... I know how to display data in a table(just click on the table "bind data" )... but my question is that:
    when i want to use a sql statement that taken the data from different table...
    how can i display that data in the table(that will be shown in the web) ??? when i click bind data on the table i can only select one table i can't select more than one....
    Note:
    1) i'm using the rowset for displaying the data in the table, since the sql statement is depending on a condition(i.e. select a from b where c= ? )...
    2) i mean by different table is that( i.e. select a from table1,table2 )..
    thanks in advance...

    Hi,
    937440 wrote:
    Hi every one, this is my first post in this portal. Welcome to the forum!
    Be sure to read the forum FAQ {message:id=9360002}
    I want display the details of emp table.. for that I am using this SQL statement.
    select * from emp where mgr=nvl(:mgr,mgr);
    when I give the input as 7698 it is displaying the corresponding records... and also when I won't give any input then it is displaying all the records except the mgr with null values.
    1)I want to display all the records when I won't give any input including nulls
    2)I want to display all the records who's mgr is null
    Is there any way to incorporate to include all these in a single query..It's a little unclear what you're asking.
    The following query always includes rows where mgr is NULL, and when the bind variable :mgr is NULL, it displays all rows:
    SELECT  *
    FROM     emp
    WHERE     LNNVL (mgr != :mgr)
    ;That is, when :mgr = 7698, it displays 6 rows, and when :mgr is NULL it displays 14 rows (assuming you're using the Oracle-supplied scott.emp table).
    The following query includes rows where mgr is NULL only when the bind variable :mgr is NULL, in which case it displays all rows:
    SELECT     *
    FROM     emp
    WHERE     :mgr     = mgr
    OR       :mgr       IS NULL
    ;When :mgr = 7698, this displays 5 rows, and when :mgr is NULL it displays 14 rows.
    The following query includes rows where mgr is NULL only when the bind variab;e :mgr is NULL, in which case it displays only the rows where mgr is NULL. That is, it treats NULL as a value:
    SELECT     *
    FROM     emp
    WHERE     DECODE ( mgr
                , :mgr, 'OK'
                )     = 'OK'
    ;When :mgr = 7698, this displays 5 rows, and when :mgr is NULL, it displays 1 row.

  • How to update multiple records in the table using POST parameters:

    i got this idea from this website:http://www.karlrixon.co.uk/articles/sql/update-multiple-rows-with-different-values-and-a-s ingle-sql-query/comment-page-1/#comment-5409. Basically i am trying to update all the status in the results page, and by adding $i in front of the id in the text fields, and checkboxes, i can name the different inputs with different names:
    The image of how it takes the inputs is shown here:http://forums.adobe.com/thread/709034?tstart=0
    I tried this but got this error:Parse error: syntax error, unexpected T_IF, expecting ')' in C:\xampp\htdocs\Database Query\results_change.php on line 51
    will not work in the update code section:
    for($i=0;$i<$maxRows_Recordset1;$i++)
    {$a=sprintf("%s",GetSQLValueString($_POST['changeid $i'],"int"));
    $b=sprintf("%s",GetSQLValueString($_POST['checkbox $i'],"text"));
    $display_order .= array(
        $a => $b
    if($i<$maxRows_Recordset1-1)
    $ids = implode(',', array_keys($display_order));
    $updateSQL = "UPDATE `change` SET Status = CASE Change_id ";
    foreach ($display_order as $a => $b) {
        $updateSQL .= sprintf("WHEN %d THEN %s ", $a,$b);
    $updateSQL .= sprintf("END WHERE `Change_id` IN ($ids)");

    Hi,
    Try
    BEGIN
      FOR i IN 1..APEX_APPLICATION.G_F03.COUNT LOOP
        UPDATE xx_test
        SET checkbox = 'Y'
        WHERE rec_no = APEX_APPLICATION.G_F03(i);
      END LOOP;
    END;Code loops all checked checkbox. You do not need commit on page process.
    Regards,
    Jari
    http://dbswh.webhop.net/dbswh/f?p=BLOG:HOME:0

  • How to update multiple records in a table using procedure?

    Dear All,
    1 am using 11.1.2.1.0
    my question is i have a table like
    emp id(primary key), empname,location
    1                             damby      blore
    2                             rocky       kormangala
    3                              biswa     india
    my question  is i need to write one procure that at a time i can update empname and location(wat the value are there in empname and location i  need to change at a time).
    thanks
    Damby

    Hi, Damby,
    That sounds like what the UPDATE statement does, exactly.  Just use an UPDATE statement to change any number of columns in existing rows.  You don't need a procedure, but, if you're using a procedure for some other reason, you can do the UPDATE in the procedure.  UPDATE works the same in SQL or PL/SQL.
    Sometimes MERGE is more convenient than UPDATE.  Like UPDATE, it can change any number of columns, either in SQL or PL/SQL.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    In the case of a DML operation (such as UPDATE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
    Explain, using specific examples, how you get those results from that data.
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • How to update multiple records in custom table using checkbox in APEX 4.1?

    Hi,
    I have a SQL report which brings up all the data records using the following query.
    select
    "REC_NO" AS hidden_rec_no,
    "REC_NO",
    APEX_ITEM.CHECKBOX (3,rec_no) AS edit,
    "MEETING_TYPE",
    "PAGE_NO",
    "CHECKBOX"
    from "XX_TEST" m
    WHERE page_no = :p_page_no
    Out of all records, any records which are checked, I only want to update their flag to 'Y' on the database column "Checkbox". For this, I have a SUBMIT button on the report region. The processing code on pressing the SUBMIT button is:
    DECLARE.
    l_row NUMBER := 1;
    BEGIN
    FOR i IN 1..APEX_APPLICATION.G_F03.COUNT
    LOOP
    FOR j IN l_row..APEX_APPLICATION.G_F01.COUNT
    LOOP
    IF APEX_APPLICATION.G_F01(j) = APEX_APPLICATION.G_F03(i) THEN
    UPDATE xx_test
    SET checkbox = 'Y', -- APEX_APPLICATION.G_F03(j)
    WHERE rec_no = APEX_APPLICATION.G_F03(i);
    l_row := j + 1;
    EXIT;
    END IF;
    END LOOP;
    END LOOP;
    COMMIT;
    END;
    However, that is not happening. Please help me with this. Any solutions/suggestions are most welcome.
    Regards.

    Hi,
    Try
    BEGIN
      FOR i IN 1..APEX_APPLICATION.G_F03.COUNT LOOP
        UPDATE xx_test
        SET checkbox = 'Y'
        WHERE rec_no = APEX_APPLICATION.G_F03(i);
      END LOOP;
    END;Code loops all checked checkbox. You do not need commit on page process.
    Regards,
    Jari
    http://dbswh.webhop.net/dbswh/f?p=BLOG:HOME:0

  • How to use a USER_DATASTORE to index multiple columns in different tables

    I would appreciate if somebody can give an example or point to links with examples on how to use USER_DATASTORE on multiple columns in different tables. THe Oracle Text documentation only shows multiple columns in the same table.
    Thanks in advance.

    I am not sure why your getting the wrong results but you should seriously reconsider the approach your are taking. Using functions like this is very ineffecient and should be avoided at all cost.

  • How to delete a column from the table control in module pool?

    Hi,
      can any one please tell How to delete a column from the table control in module pool?
    thanks in advance
    warm regards
    HareeshKumar N

    hi hareesh,
    I think it is better to hide it.
    How to hide: You can check this link
    Dynamic Hide column in table control

  • How to do a SELECT from different tables into an internal table?

    How to do a SELECT from different tables into an internal table?
    I want to select data from MARA, MARC and ZPERSON and populate my ITAB_FINAL
    REPORT  zinternal_table.
    TABLES:
      mara,
      marc,
      zperson.
    TYPES:
    BEGIN OF str_table1,
      v_name LIKE zperson-zname,
      v_matnr LIKE marc-matnr,
      v_emarc LIKE marc-emarc,
      v_werks_d LIKE marc-werks_d,
      v_dstat LIKE marc-dstat,
      END OF str_table,
      i_table1 TYPE STANDARD TABLE OF str_table1.
    DATA:
    BEGIN OF str_table2,
    v_mandt LIKE mara-mandt,
    v_ernam LIKE mara-ernam,
      v_laeda LIKE mara-laeda,
    END OF str_table2,
    itab_final LIKE STANDARD TABLE OF str_table2.

    first find the link between mara , marc and zperson , if u have link to 3 tables then u can jus write a join and populate the table u want ( thats final table with all the fields).
    u defenitely have alink between mara and marc so join them and retrieve all data into one internal table.
    then for all the entries in that internal table retrieve data from zperson into another internal table.
    then loop at one internal table
    read another internal table where key equals in both the tables.
    finally assign fileds if sy-subrc = 0.
    gs_finaltable-matnr = gs_table-matnr
    etc...
    and finally append gs_finaltable to gt_finaltable.
    there u go ur final table has all the data u want.
    regards
    Edited by: BrightSide on Apr 2, 2009 3:49 PM

  • How can I select columns from a table EMP, using Select statement?.

    Hi Friends,
    How can I select columns from a table EMP?.
    I want to select columns of EMP table, using select statement.
    Please reply me urgently.
    Shahzad

    Something like this:
    scott@DBA> select empno,ename,job from emp;
         EMPNO ENAME      JOB
          7369 SMITH      CLERK
          7499 ALLEN      SALESMAN
          7521 WARD       SALESMAN
          7566 JONES      MANAGER
          7654 MARTIN     SALESMAN
          7698 BLAKE      MANAGER
          7782 CLARK      MANAGER
          7788 SCOTT      ANALYST
          7839 KING       PRESIDENT
          7844 TURNER     SALESMAN
          7876 ADAMS      CLERK
          7900 JAMES      CLERK
          7902 FORD       ANALYST
          7934 MILLER     CLERK
    14 rows selected.Check the documentation:
    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_10002.htm#sthref9697
    Message was edited by:
    Delfino Nunez

  • How to pick max value from a column of a table using cursor and iteration

    Hello Everybody
    I have a table loan_detail
    and a column in it loan_amount
    now i want to pick values from this table using cursor and then by using iteration i want to pick max value from it using that cursor
    here is my table
    LOAN_AMOUNT
    100
    200
    300
    400
    500
    5600
    700i was able to do it using simple loop concepts but when i was trying to do this by using cursor i was not able to do it .
    Regards
    Peeyush

    SQL> SELECT MAX(sal) Highest_Sal,MIN(sal) Lowest_Sal FROM emp;
    HIGHEST_SAL LOWEST_SAL
           5000        800
    SQL> set serverout on
    SQL> DECLARE
      2    TYPE tmp_tbl IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
      3    sal_tbl tmp_tbl;
      4    CURSOR emp_sal IS
      5      SELECT sal FROM emp;
      6    counter INTEGER := 1;
      7  BEGIN
      8    FOR i IN emp_sal LOOP
      9      sal_tbl(i.sal) := counter;
    10      counter := counter + 1;
    11    END LOOP;
    12    DBMS_OUTPUT.put_line('Lowest SAL:' || sal_tbl.FIRST);
    13    DBMS_OUTPUT.put_line('Highest SAL:' || sal_tbl.LAST);
    14  END;
    15  /
    Lowest SAL:800
    Highest SAL:5000
    PL/SQL procedure successfully completed.
    SQL> Even smaller
    SQL> DECLARE
      2    TYPE tmp_tbl IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
      3    sal_tbl tmp_tbl;
      4    CURSOR emp_sal IS
      5      SELECT sal FROM emp;
      6    counter INTEGER := 1;
      7  BEGIN
      8    FOR i IN emp_sal LOOP
      9      sal_tbl(i.sal) := 1;
    10    END LOOP;
    11    DBMS_OUTPUT.put_line('Lowest SAL:' || sal_tbl.FIRST);
    12    DBMS_OUTPUT.put_line('Highest SAL:' || sal_tbl.LAST);
    13  END;
    14  /
    Lowest SAL:800
    Highest SAL:5000
    PL/SQL procedure successfully completed.
    SQL> Edited by: Saubhik on Jan 5, 2011 4:41 PM

  • Best practice for deleting multiple rows from a table , using creator

    Hi
    Thank you for reading my post.
    what is best practive for deleting multiple rows from a table using rowSet ?
    for example how i can execute something like
    delete from table1 where field1= ? and field2 =?
    Thank you

    Hi,
    Please go through the AppModel application which is available at: http://developers.sun.com/prodtech/javatools/jscreator/reference/codesamples/sampleapps.html
    The OnePage Table Based example shows exactly how to use deleting multiple rows from a datatable...
    Hope this helps.
    Thanks,
    RK.

  • How to update the data in sqlserver table using procedure in biztalkserver

    Hi,
    Please can any one answer this below question
    how to update the data in sqlserver table using procedure in biztalkserver
    while am using executescalar,typedprocedure getting some warning
    Warning:The adapter failed to transmit message going to send port "SendtoSql1" with URL "mssql://nal126//MU_Stage2?". It will be retransmitted after the retry interval specified for this Send Port. Details
    Please send me asap....
    Thanks...

    Hi Messip,
    A detailed error would have helped us to answer you more appropriately but
    You can follow the post which has step by step instructions, to understand how to use Stored Procedure:
    http://tech-findings.blogspot.in/2013/07/insert-records-in-sql-server-using-wcf.html
    Maheshkumar
    S Tiwari|User
    Page|Blog|BizTalk
    2013: Inserting RawXML (Whole Incoming XML Message) in SQL database

  • How to update two columns in two tables?

    hi friends
    I have two tables linked to each other through SaleNo and SaleDT. their structure as below
    Sales Table============
    SaleNo int PK auto increment
    SaleDT Datetime PK
    Qnty decimal
    Units decimal
    Invoices table
    =================InvoiceNo int PK Auto incremented
    InvoiceDT Datetime
    SaleNo int FK
    SaleDT Datetime FK
    Note that SaleDT column is NOT assigned with getDate() expression.
    1. what I need to do is update the SaleDT column of Sales table and Invoices table with the value '2013-01-31 10:31:55.813', how do I do this without manually breaking the link between the tables?
    2. Assume SaleNos 15 to 27 needs update the SaleDT to '2013-06-12 10:31:55.813', how do I do this complex operation where I I have update SaleDt column of two table of SaleNo range from 15 to 27?
    thanks
    I use Visual studio 2012 Ultimate and SQL server 2008 developer edition!

    Why not below? May be you will not be able to change your design now, but just want to share.
    Sales Table============
    SALEID int PK autoincrement
    SaleNo int
    SaleDT Datetime
    Qnty decimal
    Units decimalUNIQUE (Saleno,SaleDT)
    Invoices table
    =================InvoiceNo int PK Auto incremented
    InvoiceDT Datetime
    SALEID int FK

  • Merge statement - update multiple columns from a single sub-select

    Is it possible to write in 10gR2, a MERGE statement, with UPDATE for multiple columns from a single sub_select?
    like this:
    MERGE INTO tableA
    using ( select * from temp) tmp
    on( tableA. col1 = tmp.col1)
    when matched then
    update set  ( tableA.col5,
                       tableA.col6,
                       tableA.col7) = ( select sum(col2), sum(col3), sum(col5)
                                                                                 from tableX
                                                                                where tableX.col1 = tableA.col1...)

    Hi,
    The USING clause is not a sub-query, so it can't reference columns from tables that are not in it.
    Include tableA in the USING clause if you really need to refer to it there. (It's not obvious that you do.)
    As always, it helps if you post:
    (1) The version of Oracle (and any other relevant software) you're using
    (2) A little sample data (just enough to show what the problem is) from all the relevant tables
    (3) The results you want from that data (In the case of a DML statement, such as MERGE, this will be the state of the tables when everything is finished.)
    (4) Your best attempt so far (formatted)
    (5) The full error message (if any), including line number
    Executable SQL statements (like "CREATE TABLE AS ..." or "INSERT ..." statements) are best for (2).
    If you can present your problem using commonly available tables (for example, tables in scott schema, or views in the data dictionary), then you can omit (2).
    Formatted tabular output is okay for (3).

Maybe you are looking for

  • How to call a Webdynpro view from BSP page (MVC) in a new window?

    Dear Experts, kindly advise how to call a webdynpro view from BSP application after performing an event (through button or hyper link). Regards, Sarat.

  • SAP Vendor Number and MDG Business Partner mapping table name

    Hello Expert, We are using MDG for Materials and Suppliers, while using we found some times error on vendore number and business partner mis-matching. Could you please tell me which table I should check where I can see ECC vendor number with MDG busi

  • How can I activate Java in Win 7 and Firefox 9?

    I need to log into a site that requires Java. I am running Window 7 64bit home Ed and Firefox 9.0.1. Java 64 is installed but does not show up in Firefox. I can find no troubleshooting info anywhere on your site regarding this problem

  • Load external SWF's help

    I am using this thumbnail gallery attached but instead of loading images through the xml I want to load external SWF'S. I also want to be able to control each SWF loaded in individually apparently in order to do that I need to give the container diff

  • Cisco Call Manager 9.1 on UCS E

    Hi Community. Does any one know if the Cisco Call Manager 9.1 is supported on UCS E? i already checked the documentation on cisco.com, but i just found something about the CCM 8.6 is supported but i didn't see any guide installation. Please help.