A Way For Learning

Cursor

No comments
1. Explain about cursors ?
A cursor is defined as a work area where SQL statement is executed.There are two types of cursors.
1.Implicit cursor
2.Explicit cursor


2. Give the attributes of the implicit cursors
The attributes of implicit cursors are:
%FOUND : true if the SQL DML statement returns a row or multiple rows to the cursor
%NOTFOUND :true if the SQL DML statement does not return a row to the cursor
%ISOPEN : to check whether cursor is open or not
%ROWCOUNT : display the number of results for a given SQL DML statement


3. Give an example how implicit cursor attributes can be used

CREATE OR REPLACE PROCEDURE  DISPLAY_FLIGHT
 AS
CURSOR DIS_FLI IS
SELECT * FROM FLIGHT WHERE SOURCE_CODE IN(SELECT CITY_CODE FROM CITY_MASTER WHERE CITY_NAME='MUMBAI');
REC_FLI DIS_FLI%ROWTYPE;
BEGIN
OPEN DIS_FLI;
LOOP
FETCH DIS_FLI INTO REC_FLI;
EXIT WHEN DIS_FLI %NOTFOUND;
DBMS_OUTPUT.PUT_LINE (REC_FLI.FID||' '||REC_FLI.FNAME||'  '||REC_FLI.SOURCE_CODE||' '||REC_FLI.DESTINATION_CODE||' '||REC_FLI.JOURNEY_HOURS);
END LOOP;
END;

No comments :

Post a Comment