Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Cursor with Update inside

Ragul HalanSep 18 2015 — edited Sep 18 2015

Hi All,

I am having a situation here, I have two identical records in a table and I am writing a cursor to fetch these records.

In the 1st loop I am updating both the rows of the table with a site, but when the cursor comes for the second loop this updated record is not reflected in the cursor value.

Appreciate your time and help.

Code used:

CREATE TABLE xx_cur_test

(

name varchar2(30),

id number,

site_id number

);

INSERT INTO xx_cur_test (name) values ('SITE1');

INSERT INTO xx_cur_test (name) values ('SITE1');


Anonymous block

DECLARE

  CURSOR c1

  IS

     SELECT * FROM xx_cur_test;

BEGIN

  FOR i IN c1

  LOOP

    dbms_output.put_line ('site id'||NVL(i.site_id,0));     -- in the second loop the site_id value still shows null - what might be the possible cause ?

    IF i.site_id IS NULL THEN

      dbms_output.put_line ('Inside IF');

    END IF;

     UPDATE xx_cur_test SET site_id = '123';

    COMMIT;

  END LOOP;

END;



Thanks,

Ragul

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 16 2015
Added on Sep 18 2015
14 comments
1,914 views