Implicit Cursors: sql%rowcount : Implicit Cursor « Cursor « Oracle PL / SQL






Implicit Cursors: sql%rowcount

  
SQL>
SQL> CREATE TABLE departments
  2  (department_id           number(10)            not null,
  3   department_name      varchar2(50)      not null,
  4   CONSTRAINT departments_pk PRIMARY KEY (department_id)
  5  );

Table created.

SQL>
SQL>
SQL>
SQL> insert into departments ( department_id, department_name )
  2                    values( 1,             'Data Group' );

1 row created.

SQL>
SQL> insert into departments ( department_id, department_name )
  2                    values( 2,             'Purchasing' );

1 row created.

SQL>
SQL> insert into departments ( department_id, department_name )
  2                    values( 3,             'Call Center' );

1 row created.

SQL>
SQL> insert into departments ( department_id, department_name )
  2                    values( 4,             'Communication' );

1 row created.

SQL>
SQL> declare
  2  begin
  3    update departments
  4       set department_name = department_name
  5     where 1 = 2;
  6
  7    dbms_output.put ('An update with a WHERE clause 1 = 2 effects ');
  8    dbms_output.put_line(sql%rowcount || ' records.');
  9
 10    update departments
 11       set department_name = department_name;
 12
 13    dbms_output.put('No WHERE clause in an update effects ');
 14    dbms_output.put_line(sql%rowcount || ' records.');
 15  end;
 16  /
An update with a WHERE clause 1 = 2 effects 0 records.
No WHERE clause in an update effects 4 records.

PL/SQL procedure successfully completed.

SQL>
SQL> drop table departments;

Table dropped.

SQL> --

   
  








Related examples in the same category

1.Use implicit cursor
2.Implicit cursors: SQL%FOUND returns TRUE if SQL statement found one or more records
3.use for loop cursor
4.Cursor for loop
5.Reference implicit in insert statement
6.use cursor attributes on the implicit SQL cursor.
7.Implicit cursor by for loop
8.Test cursor attributes with an implicit cursor
9.Use implicit or explicit cursor to insert 50000 rows to a table
10.Use passed in value with creating a cursor
11.Write an implicit cursor in a FOR loop and use the data
12.explicit cursor with cursor variable
13.for data in ( select * from tableName )