Update a column using cursor

Hi everyone,
still playing around with newbie stuff here. Is it possible to update a column or a row using a cursor? I understand how to fetch a data using a cursor, but not sure if it can help to update a data.
If it can, what's the syntax?
Regards,
Valerie

hi,
why you opted to update rows by using cursor.
why not you opt DML
or
just want to know
SQL> SET LINE 32323
SQL> /
Rollback complete.
SQL> SELECT *FROM EMP;
      7499 KITTU      SALESMAN        7698 20-FEB-81      15800      25050         30
      7566 JONES      MANAGER         7839 02-APR-81       3175     446.25         20
      7654 RAVIKUMAR  SALESMAN        7698 28-SEP-81       1450     1587.5         30 [email protected]
      7698 BLAKE      MANAGER         7839 01-MAY-81       3050      427.5         30
      7782 CLARK      MANAGER         7839 09-JUN-81       2650      367.5         10
      7788 SCOTT      ANALYST         7566 09-DEC-82       3200        450         20
      7839 KING       PRESIDENT            17-NOV-81       5200       8250         10
      7844 TURNER     SALESMAN        7698 08-SEP-81       1700        225         30
      7876 ADAMS      CLERK           7788 12-JAN-83       1300        165         20
      7900 JAMES      CLERK           7698 03-DEC-81       1150       85.5         30 [email protected]
      7902 FORD       ANALYST         7566 03-DEC-81       3200        450         20
      7934 MILLER     CLERK           7782 23-JAN-82       1500        195         10
      8000 KINGBABA   PRESIDENT            17-NOV-81       5200       8250         10
      8001 TURNER RAV SALESMAN        8000 08-SEP-81       1700        450         30
14 rows selected.
SQL> DECLARE
  2  CURSOR CUR_EMP IS SELECT *FROM EMP;
  3  CUR_EMP1 CUR_EMP%ROWTYPE;
  4  BEGIN
  5  OPEN  CUR_EMP;
  6  LOOP
  7  FETCH CUR_EMP INTO CUR_EMP1;
  8  EXIT WHEN CUR_EMP%NOTFOUND;
  9  UPDATE EMP SET ENAME='TEST'
10  WHERE ENAME=CUR_EMP1.ENAME;
11  END LOOP;
12  CLOSE CUR_EMP;
13  END;
14  /
PL/SQL procedure successfully completed.
SQL> SELECT *FROM EMP;
      7499 TEST       SALESMAN        7698 20-FEB-81      15800      25050         30
      7566 TEST       MANAGER         7839 02-APR-81       3175     446.25         20
      7654 TEST       SALESMAN        7698 28-SEP-81       1450     1587.5         30 [email protected]
      7698 TEST       MANAGER         7839 01-MAY-81       3050      427.5         30
      7782 TEST       MANAGER         7839 09-JUN-81       2650      367.5         10
      7788 TEST       ANALYST         7566 09-DEC-82       3200        450         20
      7839 TEST       PRESIDENT            17-NOV-81       5200       8250         10
      7844 TEST       SALESMAN        7698 08-SEP-81       1700        225         30
      7876 TEST       CLERK           7788 12-JAN-83       1300        165         20
      7900 TEST       CLERK           7698 03-DEC-81       1150       85.5         30 [email protected]
      7902 TEST       ANALYST         7566 03-DEC-81       3200        450         20
      7934 TEST       CLERK           7782 23-JAN-82       1500        195         10
      8000 TEST       PRESIDENT            17-NOV-81       5200       8250         10
      8001 TEST       SALESMAN        8000 08-SEP-81       1700        450         30
14 rows selected.Edited by: user291283 on Sep 1, 2009 10:42 PM

Similar Messages

  • Update some columns using case....

    Hi ,
    Is it possible to update some columns using case statement...????
    For example when col1 is null then update to a value 'x' else update it to the value '*' , when col2 is null then update to a value y else update it to compute the running total up to that time....
    This update statement is contained in db packaged procedure and it receives the values...as parameters....
    How can i write down this update statement...?????
    Many thanks,
    Simon

    Hi ,
    Cant' it be used for two or more columns that have to be updated....????
    i mean
    update table set col_a = case when col_a is null then col_a else '*',
                       col_b = case when col_b is null then col_b else col_b+col_b_var
      end
      where .....The above in bold is running total.... This update is defined in a procedure and it receives numbers as parameters, so the need is to add them for every record it receives...., that's why i set above col_b+col_b_var... where col_b_var is the parameter of the procedure....
    SORRY...IT IS POSSIBLE.....
    Thanks , a lot
    Simon
    Message was edited by:
    sgalaxy

  • Updating a table using cursor is taking long time in oracle

    Hi,
    I am working on the oracle database 11gR2. I am trying update a table column which is newly added through cursor. below is the cursor.
    BEGIN
         FOR lcur_tab IN (select l.LOGIN_ID as login_id, lt.ERROR_CODE as error_code from LOGIN l INNER JOIN LOGIN_TASK lt ON (l.LAST_LOGIN_TASK_ID = lt.LOGIN_TASK_ID) )
         LOOP
                   UPDATE ACCOUNT SET LOGIN_ERROR_CODE = lcur_tab.error_code where ACCOUNT_ID IN (SELECT ACCOUNT_ID FROM LOGIN_ACCOUNT where LOGIN_ID = lcur_tab.login_id ) ;
         end LOOP;
         commit;
    END;
    In the cursor we are trying to copy the Login table error_code value to LOGIN_ERROR_CODE of ACCOUNT Table, for the accounts associated with that Login. Here newly added column is LOGIN_ERROR_CODE in account table. this account table have 11million rows in it. when i used the above cursor it took 3hours and still running. So we stopped after that. Is there any way i can change this cursor syntax to update those column values. How can we do this type of updates?
    Also i am planning to run thus update in the background . I don't have much knowledge on the PL/SQL stuff. So please help on this.
    Thanks in advance.
    Edited by: Hari on Mar 21, 2012 10:06 PM

    Is there a reason that you don't want to do this with a single `UPDATE` statement? That should be quite a bit more efficient.
    Something like
    UPDATE account a
       SET login_error_code = (
          select lt.error_code
            from login_task lt
                 join login l on (l.last_login_task_id = lt.login_task_id)
                 join login_account la on (la.login_id = l.login_id)
           where la.account_id = a.account_id )
    WHERE EXISTS (
          select 1
            from login_task lt
                 join login l on (l.last_login_task_id = lt.login_task_id)
                 join login_account la on (la.login_id = l.login_id)
           where la.account_id = a.account_id );Justin

  • How to update the columns using sql queries?

    create table emp(eno number(5),ename varchar2(20),dno number(2),dname varchar2(20),loc_id number(3), location varchar2(10));
    insert into emp(eno,ename,dno,loc_id) values(1,'tom1',10,1);
    insert into emp(eno,ename,dno,loc_id) values(2,'tom2',20,2);
    insert into emp(eno,ename,dno,loc_id) values(3,'tom3',30,3);
    insert into emp(eno,ename,dno,loc_id) values(4,'tom4',40,4);
    insert into emp(eno,ename,dno,loc_id) values(5,'tom5',50,5);
    insert into emp(eno,ename,dno,loc_id) values(6,'tom6',60,6);
    insert into emp(eno,ename,dno,loc_id) values(7,'tom7',70,7);
    insert into emp(eno,ename,dno,loc_id) values(8,'tom8',80,8);
    create table dept(dno number(3),dname varchar2(10));
    insert into dept values(10,'RM');
    insert into dept values(10,'DD');
    insert into dept values(10,'TD');
    create table location(loc_id number(3),location varchar2(20));
    insert into location values(1,'palani');
    insert into location values(1,'salem');
    insert into location values(1,'kalpattu');
    insert into location values(1,'thirukoyilur');
    insert into location values(2,'thaeni');
    insert into location values(2,'villupuram');
    insert into location values(2,'yercaud');
    insert into location values(3,'thiruvanamalai');
    insert into location values(3,'trichy');
    insert into location values(7,'tanjore');
    insert into location values(4,'tirunelveli');
    insert into location values(4,'namakal');
    insert into location values(5,'bangalore');
    insert into location values(6,'chennai');
    insert into location values(6,'calcutta');
    insert into location values(7,'tirupathy');
    insert into location values(7,'bombay');
    insert into location values(7,'kumbokonam');
    My requirement is to update the department name and location of toms present in employee table without using cursors, loops.
    The column department number and loc_id are used for joins.
    I am in a situation to deliver my code on time.

    try this
    update emp tt
    set (dname,location ) = (
    select res,res1 from (select a.eno,a.ename,a.dno,b.dname,a.loc_id,c.location
    from emp a,
    dept b,
    location c
    where a.dno = b.dno
    and a.loc_id = c.loc_id
    ) t
    where tt.eno = t.eno
    model
    return updated rows
    partition by (eno)
    dimension by (row_number() over (order by eno) as rn)
    measures(cast (dname as varchar2(50))  as res,cast (location as varchar2(300)) as res1)
    rules
    upsert
    iterate(1000)
    until(presentv(res[iteration_number + 2],1,0) = 0)
    res[0] = res[0] ||','|| res[iteration_number + 1],
    res1[0] = res1[0] ||','|| res1[iteration_number + 1]))
    ;output
    1     tom1     10     ,RM,RM,RM,RM,DD,TD,DD,DD,TD,TD,TD,DD     1     ,palani,salem,kalpattu,thirukoyilur,palani,thirukoyilur,kalpattu,thirukoyilur,palani,salem,kalpattu,salem
    2     tom2     20          2     
    3     tom3     30          3     
    4     tom4     40          4     
    5     tom5     50          5     
    6     tom6     60          6     
    7     tom7     70          7     
    8     tom8     80          8     

  • How to update a column using hibernate

    how to update a particular column using hibernate..
    iam using oracle database

    I think you didn't get the point. This is a generic Java forum... not a Hibernate forum.

  • Update hidden column using Apply MRU

    I want to update username which is a hidden column with an value when I submit update using ApplyMRU. How can I do it?
    Apex 4.1, Browser IE/FireFox, Using Form Tabular with ApplyMRU.

    Can someone help on this?

  • Update a column using a connect by or other for hierachical relationships

    I have a column which represents the 'order' of which a record loaded out of a table.
    This 'order' is coming in wrong.
    I know, because of a relatoinship between two of the columns what the correct order should be.
    So for example if I do this:
    select transid, laborcode, supervisorfrom enclabor_iface
    connect by prior laborcode = supervisor
    start with supervisor = 0;
    I get all the records in the correct order... but of course I'd like to figure out how to use this in an update statement to update the transid columns, which is the order.
    Can someone tell me if this is possible, and if so, how to do so?
    I have tried a few things with no luck yet, as the attempt took over 15 minutes to run so I thought I had coded it badly.
    thanks
    Jeff

    Hi, Jeff,
    Sure, that's possible.
    The ROWNUM pseudo-column is assigned as the CONNECT BY clause (including ORDER SIBLINGS BY) is being applied, so you can use ROWNUM to capture the hierarchical order.
    I don't have a copy of your table, so I'll use scott.emp to illustrate:
    SELECT       ename, empno, mgr
    ,       ROWNUM          AS r_num
    FROM       scott.emp
    START WITH     mgr     IS NULL
    CONNECT BY     mgr     = PRIOR EMPNO
    ORDER SIBLINGS BY     ename
    ;Output:
    ENAME      EMPNO   MGR      R_NUM
    KING        7839                1
    BLAKE       7698  7839          2
    ALLEN       7499  7698          3
    JAMES       7900  7698          4
    MARTIN      7654  7698          5
    TURNER      7844  7698          6
    WARD        7521  7698          7
    CLARK       7782  7839          8
    MILLER      7934  7782          9
    JONES       7566  7839         10
    FORD        7902  7566         11
    SMITH       7369  7902         12
    SCOTT       7788  7566         13
    ADAMS       7876  7788         14The default CONNECT BY ordering guarantees that (for example) all of BLAKEs descendants will come after BLAKE and before anyone who is not a descendant of BLAKE. However, it says nothing about whether BLAKE will come before JONES, or vice-versa. If that's important, use ORDER SIBLINGS BY.
    To store those numbers in your table, do the query above in a MERGE statement.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    If you're asking about a DML statement, such as MERGE, the sample data will be the contents of the table(s) before the DML, and the results will be state of the changed table(s) when everything is finished.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.
    Edited by: Frank Kulash on Feb 7, 2012 11:46 AM

  • How to update multiple rows using cursor.

    hi all,
    i want to update rows fetched by a cursor. it don't update the rows.
    and gives error:
    ORA-01002     fetch out of sequence
    here is the trigger.
    Declare
         alert_id ALERT := Find_Alert('on');
         alert_button NUMBER;
         var number :=10;
         v_al char(3);
         v_al_da date;
         s_date date;
         al_on number;
         to_time number;
         cursor rem is
              select re_about, alarm, alert_date
              from remind
              where alarm='ON' AND alert_date = :control.showdate
              for update;
    begin
         for rem_record IN rem LOOP
              Set_Alert_Property(alert_id, ALERT_MESSAGE_TEXT, rem_record.re_about);
              al_on := show_alert('ON');
              IF alert_button = ALERT_BUTTON1 THEN
              update remind
              set alarm = 'OFF'
              --where re_about = rem_record.re_about
              where current of rem;
              ELSE
              NULL;
              END IF;
              COMMIT;
         END LOOP;
    end;
    thanks
    Muhammad Nadeem
    Mardan

    thanks dear,
    i tried the following code outside the loop
    but the same problem.
    here is the code:
    Declare
         alert_id ALERT := Find_Alert('on');
         alert_button NUMBER;
         var number :=10;
         v_al char(3);
         v_al_da date;
         s_date date;
         al_on number;
         to_time number;
         cursor rem is
              select re_about, alarm, alert_date
              from remind
              where alarm='ON' AND alert_date = :control.showdate
              for update;
    begin
         for rem_record IN rem LOOP
         Set_Alert_Property(alert_id, ALERT_MESSAGE_TEXT, rem_record.re_about);
              al_on := show_alert('ON');
              IF alert_button = ALERT_BUTTON1 THEN
              update remind
              set alarm = 'OFF'
         where current of rem;
              ELSE
              NULL;
              END IF;
         END LOOP;
    if :SYSTEM.FORM_STATUS = 'changed' then
         COMMIT;
    end if;
    end;
    thanks
    Muhammad Nadeem

  • Updating a column using deleted/inserted during update statement execution

    I need to capture the old value while update statement is executed. I can not insert into temp table (there are many samples online where you can use OUTPUT clause to insert data in same table or another temp table)
    something like 
     declare @count table
        id int,
        changed varchar (50)
    insert into @count (id,changed) values (2,'T')
    insert into @count (id,changed) values (3,'T')
    insert into @count (id,changed) values (4,'T')
    select * from @count
    UPDATE @count
    SET id=5,
        Changed = GETDATE() -- here instead of date, I want to get inserted.id and  deleted.id
    OUTPUT inserted.id,
           deleted.id
        where id = 2
      SELECT *FROM @count
    Any help on this will be very much appreciated....

    I am not sure to follow your question but you can get the old value just by doing:
    UPDATE @count
    SET id=5,
        Changed =  id
    OUTPUT inserted.id,
        deleted.id
    WHERE id = 2;
    since SQL Server uses all-at-once operations.
    Microsoft SQL Server 2012 T-SQL Fundamentals
    http://shop.oreilly.com/product/0790145321978.do
    AMB
    Some guidelines for posting questions...

  • Need to update multiple columns using another table

    I have 2 tables. and i need to update rows of 1 table using another table
    Table1
    Serial_no.     payment_date     Payment_amt
    101     22/11/2010     150
    101     18/03/2011      355
    102     15/04/2011      488
    103     20/05/2011      178
    102     14/06/2011      269
    101     28/06/2011      505
    Table2
    Serial_no     Charge_amt      Last_paymt_dt     Last_paymt_amt
    101     255
    102     648
    103     475
    I want to update Last_paymt_dt and Last_paymt_amt of table2 using Table1, I have written following update statement but it gives error that single row subquery return multiple row.
    Update Table2
    set (Last_paymt_dt,Last_paymt_amt) = (select max(payment_date, payment_amt) from table1
    where table1.Serial_no = table2.Serial_no group by payment_amt)
    kindly suggest how should i update.

    SQL> select * from table1
      2  /
    SERIAL_NO PAYMENT_DA PAYMENT_AMT
           101 22/11/2010         150
           101 18/03/2011         355
           102 15/04/2011         488
           103 20/05/2011         178
           102 14/06/2011         269
           101 28/06/2011         505
    6 rows selected.
    SQL> select * from table2
      2  /
    SERIAL_NO CHARGE_AMT LAST_PAYMT LAST_PAYMT_AMT
           101        255
           102        648
           103        475
    SQL> update  table2
      2     set  (last_paymt_dt,last_paymt_amt) = (
      3                                            select  max(payment_date),
      4                                                    max(payment_amt) keep(dense_rank last order by payment_date)
      5                                              from  table1
      6                                              where table1.serial_no = table2.serial_no
      7                                           )
      8  /
    3 rows updated.
    SQL> select * from table2
      2  /
    SERIAL_NO CHARGE_AMT LAST_PAYMT LAST_PAYMT_AMT
           101        255 28/06/2011            505
           102        648 14/06/2011            269
           103        475 20/05/2011            178
    SQL> SY.

  • 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

  • UPDATE COLUMNS USING MAPPINGS

    I have to migrate data from one table to another where one of the columns is the same in both tables. e.g. ID COLUMN
    Is there a way to migrate data such that I can update all rows in the ID column in table 2 with corresponding values from ID column in table 1 using one update statement?
    i.e.
    TABLE 1 || TABLE 2
    ID || ID
    2 || 5
    5 || 9
    8 || 4
    34 || 98
    67 || 762
    89 || 99
    I want to use 1 update statement if possible to update all rows in ID column table 2 with values in ID column in table 1
    Thanks
    Edited by: 331991 on Feb 4, 2010 11:04 PM

    Hi,
    You can do this by using cursor.
    At First you have to save the id mapping relationship in a temp table, for example MAPPING_TABLE.
    Then you can do this as follow:
    Declare
        Cursor TO_UPDATE IS
        SELECT NEW.ID MEW_ID, NEW.COL1, NEW COL2,...., MAP.OLD_ID
        FROM NEW_TABLE NEW,
                  MAPPING_TABLE MAP
        WHERE NEW.ID=MAP.NEW_ID
        ORDER BY OLD_ID;
    Begin
        FOR REC IN  TO_UPDATE LOOP
             UPDATE OLD_TABLE
             SET ID=REC.NEW_ID,COL1=REC.COL1, COL2=REC.COL2, ....
             WHERE ID=REC.OLD_ID;
        END LOOP;
        COMMIT;
    End; The better way, that you may let a column for control issue.
    IF ATTRIBUTE1 is NULL for EACH ROW
    Declare
        Cursor TO_UPDATE IS
        SELECT NEW.ID MEW_ID, NEW.COL1, NEW COL2,...., MAP.OLD_ID
        FROM NEW_TABLE NEW,
                  MAPPING_TABLE MAP
        WHERE NEW.ID=MAP.NEW_ID
        ORDER BY OLD_ID;
    Begin
        FOR REC IN  TO_UPDATE LOOP
             UPDATE OLD_TABLE
             SET ID=REC.NEW_ID,COL1=REC.COL1, COL2=REC.COL2, ...., ATTRIBUTE1 = REC.OLD_ID
             WHERE ID=REC.OLD_ID
             AND ATTRIBUTE1 IS NULL;
        END LOOP;
        COMMIT;
    End; Best regards,
    Zhxiang
    Edited by: zhxiangxie on Feb 5, 2010 12:19 PM

  • 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

  • How to fetch columns in cursor using FETCH?

    create or replace PROCEDURE newprocedur(outname OUT VARCHAR2,outroll OUT NUMBER) AS
    CURSOR c1 IS
    select Name,Rollno,Section from emp;
    BEGIN
    Open c1;
    fetch c1 into outname,outroll;
    Here out of 3 columns in cursor is it possible to fetch only two columns using FETCH like i did above??
    Edited by: im_asa on Nov 1, 2012 3:58 AM

    Hi,
    If you need only two why to fetch three ?
    Just doing it by yourself will show you what will happen.
    Regards
    Yoonas

  • How to update data returned using REF CURSOR

    Hi all,
    I am trying to update updated data in a gridview but the update button seem to do nothing as i retrieve data using REF CURSOR.
    Let me describe the architecture of my application first. I'm trying to implement best practice whenever possible. I am following the data access tutorial published in www.asp.net , the only difference is that i have an Oracle (10g) database. So I split my application into three layers, data access, business logic, and presentation layer. I'm also writing all queries in an Oracle package.
    So I have my Oracle packages that perform CRUD operations. Then I have an xsd file that define dataTable based on the package procedure. My business logic layer then calls functions defined in the xsd file. And finally a detailsView control that uses an ObjectDataSource to call business logic functions.
    In a nutshell, I am just trying to update records retrieved using REF CURSOR. Your help is very much appreciated. Please let me know if further details are required. Cheers,

    In the DataSet (xsd) where your DataTable is defined, you just need to add additional methods to the TableAdapter to handle insert, update and delete, either with SQL or by mapping to stored procedures.
    Alternatively in code, create an OracleDataAdapter and supply its InsertCommand, UpdateCommand and DeleteCommand.
    David

Maybe you are looking for