Check row count being updating : Update Data « PL SQL « Oracle PL / SQL






Check row count being updating

    
SQL>
SQL>
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>
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.UPDATE statement can be used within PL/SQL programs to update a row or a set of rows
2.Select for update
3.Update with variable
4.Two UPDATE statements.
5.Check SQL%ROWCOUNT after updating
6.Exception handling for update statement
7.Update salary with stored procedure
8.Update table and return if success
9.Decrease salary with user procedure
10.Change price and output the result
11.Run an anonymous block that updates the number of book IN STOCK
12.Run an anonymous block that updates the number of pages for this book
13.Run the anonymous block to update the position column
14.Ajust price based on price range
15.Bundle several update and insert statements into one procedure
16.Use procedure to update table