A complete example of using SELECT FOR UPDATE cursors : Cursor for Update « Cursor « Oracle PL/SQL Tutorial






SQL>
SQL>
SQL> create table product(
  2     product_id number(4)     not null,
  3     product_description varchar2(20) not null
  4  );

Table created.

SQL>
SQL> insert into product values (1,'Java');

1 row created.

SQL> insert into product values (2,'Oracle');

1 row created.

SQL> insert into product values (3,'C#');

1 row created.

SQL> insert into product values (4,'Javascript');

1 row created.

SQL> insert into product values (5,'Python');

1 row created.

SQL>
SQL>
SQL> create table sec_product(
  2     product_id number(4)     not null,
  3     product_description varchar2(20) not null
  4  );

Table created.

SQL>
SQL>
SQL> BEGIN
  2    INSERT INTO sec_product
  3      SELECT * FROM product;
  4    COMMIT;
  5  END;
  6  /

PL/SQL procedure successfully completed.

SQL> DECLARE
  2    CURSOR myCursor IS
  3      SELECT * FROM sec_product FOR UPDATE OF product_description;
  4    v_product_description VARCHAR2(20);
  5  BEGIN
  6    FOR idx IN myCursor LOOP
  7      v_product_description :=UPPER(idx.product_description);
  8      UPDATE sec_product
  9      SET product_description =v_product_description
 10      WHERE CURRENT OF myCursor;
 11    END LOOP;
 12    COMMIT;
 13  END;
 14  /

PL/SQL procedure successfully completed.

SQL>
SQL> drop table product;

Table dropped.

SQL> drop table sec_product;

Table dropped.








25.10.Cursor for Update
25.10.1.Cursor for update
25.10.2.Using WHERE CURRENT OF
25.10.3.A complete example of using SELECT FOR UPDATE cursors
25.10.4.Cursor FOR UPDATE NOWAIT
25.10.5.Check error code and Raise the proper error