Home >> FAQs/Tutorials >> Oracle Tutorials

Oracle Tutorials - Attributes of the Implicit Cursor

By: FYIcenter.com

(Continued from previous topic...)

How To Use Attributes of the Implicit Cursor?

Right after executing a DML statement, you retrieve any attribute of the implicit cursor by using SQL%attribute_name, as shown in the following tutorial exercise:

CREATE TABLE student (id NUMBER(5) PRIMARY KEY,
  first_name VARCHAR(80) NOT NULL,
  last_name VARCHAR(80) NOT NULL);
Table created.

DECLARE
  id NUMBER;
  first_name CHAR(10);
BEGIN
  id := 29;
  first_name := 'Bob';
  INSERT INTO student VALUES(id, first_name, 'Henry');
  first_name := 'Joe';
  INSERT INTO student VALUES(id+1, first_name, 'Bush');
  DBMS_OUTPUT.PUT_LINE('# of rows inserted: '
    || SQL%ROWCOUNT);
 
  first_name := 'Fyi';
  UPDATE student SET first_name = first_name WHERE id = 29;
  IF SQL%FOUND THEN
      DBMS_OUTPUT.PUT_LINE('# of rows updated: '
        || SQL%ROWCOUNT);
  END IF;

  UPDATE student SET first_name = first_name
    WHERE id = id+1;
  IF SQL%NOTFOUND THEN
    DBMS_OUTPUT.PUT_LINE('No records updated.');
  END IF;
    
  DELETE FROM student WHERE id = id;                    
  DBMS_OUTPUT.PUT_LINE('# of rows deleted: '
    || SQL%ROWCOUNT);
END; 
/
# of rows inserted: 1
# of rows updated: 1
No records updated.
# of rows deleted: 2

(Continued on next topic...)

  1. What Is a Cursor?
  2. How Many Types of Cursors Supported in PL/SQL?
  3. What Is the Implicit Cursor?
  4. How To Use Attributes of the Implicit Cursor?
  5. How To Loop through Data Rows in the Implicit Curosr?
  6. How To Define an Explicit Cursor?
  7. How To Open and Close an Explicit Cursor?
  8. How To Retrieve Data from an Explicit Cursor?
  9. How To Retrieve Data from a Cursor to a RECORD?
  10. How To Use FETCH Statement in a Loop?
  11. How To Use an Explicit Cursor without OPEN Statements?
  12. Can Multiple Cursors Being Opened at the Same Time?
  13. How To Pass a Parameter to a Cursor?
  14. What Is a Cursor Variable?
  15. How To Define a Cursor Variable?
  16. How To Open a Cursor Variable?
  17. How To Loop through a Cursor Variable?
  18. How To Pass a Cursor Variable to a Procedure?
  19. Why Cursor Variables Are Easier to Use than Cursors?

Oracle Tutorials:

More...


Other Tutorials/FAQs:

More...


Related Resources:

More...


Selected Jobs:

More...