Check sql%rowcount : Cursor Attributes « Cursor « Oracle PL/SQL Tutorial

Oracle PL/SQL Tutorial
1. Introduction
2. Query Select
3. Set
4. Insert Update Delete
5. Sequences
6. Table
7. Table Joins
8. View
9. Index
10. SQL Data Types
11. Character String Functions
12. Aggregate Functions
13. Date Timestamp Functions
14. Numerical Math Functions
15. Conversion Functions
16. Analytical Functions
17. Miscellaneous Functions
18. Regular Expressions Functions
19. Statistical Functions
20. Linear Regression Functions
21. PL SQL Data Types
22. PL SQL Statements
23. PL SQL Operators
24. PL SQL Programming
25. Cursor
26. Collections
27. Function Procedure Packages
28. Trigger
29. SQL PLUS Session Environment
30. System Tables Data Dictionary
31. System Packages
32. Object Oriented
33. XML
34. Large Objects
35. Transaction
36. User Privilege
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Oracle PL/SQL Tutorial » Cursor » Cursor Attributes 
25. 14. 6. Check sql%rowcount
SQL>
SQL>
SQL>
SQL> create table employee (
  2  id                             number,
  3  employee_type_id               number,
  4  external_id                    varchar2(30),
  5  first_name                     varchar2(30),
  6  middle_name                    varchar2(30),
  7  last_name                      varchar2(30),
  8  name                           varchar2(100),
  9  birth_date                     date  ,
 10  gender_id                      number );

Table created.

SQL>
SQL>
SQL>
SQL> create table gender (
  2  id                             number,
  3  code                           varchar2(30),
  4  description                    varchar2(80),
  5  active_date                    date          default SYSDATE  not null,
  6  inactive_date                  date );

Table created.

SQL>
SQL>
SQL>
SQL> insert into gender id, code, description values 1'F''Female' );

row created.

SQL> insert into gender id, code, description values 2'M''Male' );

row created.

SQL> insert into gender id, code, description values 3'U''Unknown' );

row created.

SQL>
SQL>
SQL> create table employee_type (
  2  id                             number,
  3  code                           varchar2(30),
  4  description                    varchar2(80),
  5  active_date                    date          default SYSDATE  not null,
  6  inactive_date                  date );

Table created.

SQL>
SQL> insert into employee_type(id,code,description)values(1,'C','Contractor' );

row created.

SQL> insert into employee_type(id,code,description)values(2,'E','Employee' );

row created.

SQL> insert into employee_type(id,code,description)values(3,'U','Unknown' );

row created.

SQL>
SQL>
SQL>
SQL> set serveroutput on size 1000000;
SQL>
SQL> declare
  2      v_first_name   employee.first_name%TYPE;
  3      v_middle_name  employee.middle_name%TYPE;
  4      v_last_name    employee.last_name%TYPE;
  5      v_name         employee.name%TYPE;
  6      d_birth_date   employee.birth_date%TYPE;
  7      n_count        number;
  8
  9  begin
 10    v_first_name  := 'JOHN';
 11    v_middle_name := 'J.';
 12    v_last_name   := 'DOE';
 13    v_name        := rtrim(v_last_name||', '||v_first_name||' '||v_middle_name);
 14    d_birth_date  := to_date('19800101', 'YYYYMMDD');
 15
 16    begin
 17      insert into employee (
 18             id,
 19             employee_type_id,
 20             external_id,
 21             first_name,
 22             middle_name,
 23             last_name,
 24             name,
 25             birth_date,
 26             gender_id )
 27      select 12,
 28             myCursor.id,
 29             lpad('12', 9'0'),
 30             v_first_name,
 31             v_middle_name,
 32             v_last_name,
 33             v_name,
 34             d_birth_date,
 35             c2.id
 36      from   employee_type myCursor,
 37             gender c2
 38      where  myCursor.code = 'C'
 39      and    c2.code = 'M'
 40      and not exists (
 41        select 1
 42        from   employee x
 43        where  x.name = v_name
 44        and    x.birth_date = d_birth_date
 45        and    x.gender_id  = c2.id );
 46
 47      n_count := sql%rowcount;
 48    exception
 49      when OTHERS then
 50        raise_application_error(-20006, SQLERRM||' oinsert employee');
 51    end;
 52
 53    DBMS_OUTPUT.PUT_LINE(to_char(n_count)||' row(sinserted.');
 54  end;
 55  /
row(sinserted.

PL/SQL procedure successfully completed.

SQL>
SQL> drop table gender;

Table dropped.

SQL>
SQL> drop table employee;

Table dropped.

SQL>
SQL> drop table employee_type;

Table dropped.

SQL>
SQL>
25. 14. Cursor Attributes
25. 14. 1. An example of cursorValue cursor using %ISOPEN
25. 14. 2. An example of cursor variable using %ROWCOUNT
25. 14. 3. using %ROWCOUNT as an incremental rowcount
25. 14. 4. An example to illustrate parameterized cursors and cursorValue%NOTFOUND
25. 14. 5. using SQL%BULK_ROWCOUNT and SQL%ROWCOUNT
25. 14. 6. Check sql%rowcount
25. 14. 7. While cursorVariable%found loop
25. 14. 8. Cursor not found
25. 14. 9. sql%notfound
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.