Cursor not found : 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. 8. Cursor not found
SQL>
SQL>
SQL>
SQL>
SQL> create table employee
  2          (
  3           empl_no                integer         primary key
  4          ,lastname               varchar2(20)    not null
  5          ,firstname              varchar2(15)    not null
  6          ,midinit                varchar2(1)
  7          ,street                 varchar2(30)
  8          ,city                   varchar2(20)
  9          ,state                  varchar2(2)
 10          ,zip                    varchar2(5)
 11          ,zip_4                  varchar2(4)
 12          ,area_code              varchar2(3)
 13          ,phone                  varchar2(8)
 14          ,company_name           varchar2(50));

Table created.

SQL>
SQL>
SQL> insert into employee(empl_no,lastname,firstname,midinit,street,city,state,zip,zip_4,area_code,phone,company_name)
  2  values(1,'Jones','Joe','J','10 Ave','New York','NY','11111','1111','111', '111-1111','A Company');

row created.

SQL>
SQL> insert into employee(empl_no,lastname,firstname,midinit,street,city,state,zip,zip_4,area_code,phone,company_name)
  2  values(2,'Smith','Sue','J','20 Ave','New York','NY','22222','2222','222', '222-111','B Company');

row created.

SQL>
SQL> insert into employee(empl_no,lastname,firstname,midinit,street,city,state,zip,zip_4,area_code,phone,company_name)
  2  values(3,'Anderson','Peggy','J','500 St','New York','NY','33333','3333','333', '333-3333','C Company');

row created.

SQL>
SQL> insert into employee(empl_no,lastname,firstname,midinit,street,city,state,zip,zip_4,area_code,phone,company_name)
  2  values(4,'Andy','Jill', null,'93St','New York','NY','44444','4444','212', '634-7733','D Company');

row created.

SQL>
SQL> insert into employee(empl_no,lastname,firstname,midinit,street,city,state,zip,zip_4,area_code,phone,company_name)
  2  values(5,'OK','Carl','L','19 Drive','New York','NY','55555','3234','212', '243-4243','E Company');

row created.

SQL>
SQL> insert into employee(empl_no,lastname,firstname,midinit,street,city,state,zip,zip_4,area_code,phone,company_name)
  2  values(6,'Peter','Jee','Q','38 Ave','New York','NY','66666','4598','212', '454-5443','F Inc');

row created.

SQL>
SQL> insert into employee(empl_no,lastname,firstname,midinit,street,city,state,zip,zip_4,area_code,phone,company_name)
  2  values(7,'Baker','Paul','V','738 St.','Queens','NY','77777','3842','718', '664-4333','G Inc');

row created.

SQL>
SQL> insert into employee(empl_no,lastname,firstname,midinit,street,city,state,zip,zip_4,area_code,phone,company_name)
  2  values(8,'Young','Steve','J','388 Ave','New York','NY','88888','3468','212', '456-4566','H Associates Inc');

row created.

SQL>
SQL> insert into employee(empl_no,lastname,firstname,midinit,street,city,state,zip,zip_4,area_code,phone,company_name)
  2  values(9,'Mona','Joe','T','9300 Ave','Kansas City','MO','99999','3658','415', '456-4563','J Inc');

row created.

SQL>
SQL> insert into employee(empl_no,lastname,firstname,midinit,street,city,state,zip,zip_4,area_code,phone,company_name)
  2  values(10,'Hackett','Karen','S','Kings Rd. Apt 833','Bellmore','NY','61202','3898','516', '767-5677','AA Inc');

row created.

SQL>
SQL> insert into employee(empl_no,lastname,firstname,midinit,street,city,state,zip,zip_4,area_code,phone,company_name)
  2  values(11,'Bob','Jack','S','12 Giant Rd.','Newark','NJ','27377','3298','908', '123-7367','Z Associates');

row created.

SQL>
SQL>
SQL> create table ord(
  2           order_no               integer         primary key
  3          ,empl_no                integer
  4          ,order_date             date not null
  5          ,total_order_price      number(7,2)
  6          ,deliver_date           date
  7          ,deliver_time           varchar2(7)
  8          ,payment_method         varchar2(2)
  9          ,emp_no                 number(3,0)
 10          ,deliver_name           varchar2(35)
 11          ,gift_message           varchar2(100)
 12           );

Table created.

SQL>
SQL>
SQL>
SQL> insert into ord(order_no,empl_no,order_date,total_order_price,deliver_date,deliver_time,payment_method,emp_no,deliver_name,gift_message)
  2  values(1,1,add_months(sysdate, -1)235.00'14-Feb-1999', '12 noon', 'CA',1, null, 'Gift for wife');

row created.

SQL>
SQL> insert into ord(order_no  ,empl_no ,order_date ,total_order_price ,deliver_date ,deliver_time ,payment_method ,emp_no,deliver_name ,gift_message )
  2  values(2,1,add_months(sysdate, -2)50.98'14-feb-1999', '1 pm', 'CA',7'Rose', 'Happy Valentines Day to Mother');

row created.

SQL>
SQL> insert into ord(order_no  ,empl_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message )
  2  values(32,add_months(sysdate, -3)35.99'14-feb-1999', '1 pm', 'VS',2'Ruby', 'Happy Valentines Day to Mother');

row created.

SQL>
SQL> insert into ord(order_no  ,empl_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message )
  2  values(42,add_months(sysdate, -4)19.95'14-feb-1999', '5 pm', 'CA',2'Coy', 'Happy Valentines Day to You');

row created.

SQL>
SQL> insert into ord(order_no  ,empl_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message )
  2  values(79,add_months(sysdate, -7)35.95'21-jun-1999', '12 noon', 'VS', 2'Fill', 'Happy Birthday from Joe');

row created.

SQL>
SQL> insert into ord(order_no  ,empl_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message )
  2  values (812, add_months(sysdate, -8)35.95'1-jan-2000', '12 noon', 'DI',3'Laura', 'Happy New Year''s from Lawrence');

row created.

SQL>
SQL> insert into ord(order_no  ,empl_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message )
  2  values (912, add_months(sysdate, -9)75.95'2-jan-2000', '12 noon', 'CA',7'Sara', 'Happy Birthday from Lawrence' );

row created.

SQL>
SQL> insert into ord(order_no  ,empl_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message )
  2  values(104, add_months(sysdate, -10)19.95, sysdate, '2:30 pm', 'VG',2'OK', 'Happy Valentines Day to You');

row created.

SQL>
SQL> insert into ord(order_no  ,empl_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message )
  2  values(112, add_months(sysdate, -11)30.00, sysdate+2'1:30 pm', 'VG',2'Hi', 'Happy Birthday Day to You');

row created.

SQL>
SQL> insert into ord(order_no  ,empl_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message)
  2  values(127, add_months(sysdate, -12)21.95, sysdate-2'3:30 pm', 'CA',2'Jack', 'Happy Birthday Day to You');

row created.

SQL>
SQL> insert into ord(order_no  ,empl_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message)
  2  values(137, add_months(sysdate, -1)21.95, sysdate, '3:30 pm', 'CA',2'Jay', 'Thanks for giving 100%!');

row created.

SQL>
SQL>
SQL>
SQL>
SQL> alter table employee add(discount number);

Table altered.

SQL>
SQL> create or replace procedure employee_discount1 as
  2    cursor cust_cur is
  3                 select empl_no, sum(total_order_priceas sales
  4                 from ord group by empl_no;
  5    cust_rec cust_cur%rowtype;
  6    v_discount  employee.discount%type;
  7    myStart  number := dbms_utility.get_time;
  8  begin
  9   open cust_cur;
 10   loop
 11     fetch cust_cur into cust_rec;
 12     if cust_cur%notfound then exit; end if;
 13     case
 14      when cust_rec.sales <= 10 then
 15           v_discount := .00;
 16
 17      when cust_rec.sales <= 20 then
 18           v_discount := .10;
 19
 20      when cust_rec.sales <= 50 then
 21           v_discount := .15;
 22
 23      else v_discount := .20;
 24     end case;
 25     update employee
 26       set discount = v_discount
 27       where empl_no = cust_rec.empl_no;
 28   end loop;
 29   close cust_cur;
 30   commit;
 31   dbms_output.put_line(
 32        round( (dbms_utility.get_time - myStart100
 33                ,2|| ' seconds');
 34  end;
 35  /

Procedure created.

SQL> show errors
No errors.
SQL>
SQL>
SQL> exec employee_discount1

PL/SQL procedure successfully completed.

SQL>
SQL> drop table ord;

Table dropped.

SQL> drop table employee;

Table dropped.

SQL>
SQL>
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.