Under The Guidance of Mr. R.L.Kadam: Maharashtra State Board of Technical Education Mumbai
Under The Guidance of Mr. R.L.Kadam: Maharashtra State Board of Technical Education Mumbai
Under The Guidance of Mr. R.L.Kadam: Maharashtra State Board of Technical Education Mumbai
A
PROJECT REPORT ON
“CURSORS”
UNDER THE GUIDANCE OF
MR. R.L.KADAM
…………………………of Institute, Dr. D. Y. Patil Polytechnic (Code: 0539) has completed the
Micro Project satisfactorily in Subject - .............. ( ............ ) for the academic year 20…..-
Place: …………………….
Enrollment No : ……………………………………..
The success & find outcome of this project required a lot of guidance &
assistance from many people and I am extremely privileged to have got all
along the completion of our project. All that we have done is only due to
such supervision & assistance & I would not forget to thanks them.
Date:
Place: Kolhapur.
INDEX
1 INTRODUCTION TO CURSORS 1
2 IMPLICIT CURSOR 1-2
3 IMPLICIT CURSOR ATTRIBUTES 2-3
4 DRAWBACKS OF IMPLICIT CURSOR 3
5 EXPLICIT CURSOR 3-4
6 DECLARING OPENING & CLOSING A CURSOR 4
7 FETCHING A RECORD FROM CURSOR 4-5
8 CURSOR FOR LOOPS 5-7
9 PARAMETERIZED CURSOR 7-8
DR.D.Y.PATIL POLYTECHNIC ,KASBA BAWADA
TOPIC : CURSORS
PL\SQL cursors provide a way to select multiple row data from the
database and then to process each row individually using a cursors.
We can traverse up and down a result set and retriveonly those rows
which are explicitly requested .Cursors basically help an application
to efficiently use a static result set.
Cursors is a problem to the private area in SQL that stores
information about processing a specific DML statement .The
drawback with select statement is that is returns only one row at a
time in a PL\SQL blocks .Cursors are capable for holding more than
one row. Used for grouping a set of rows and implementing a similar
logic to all the records of that group .
Set of row retrieved in a such a area is called an active day and its size
is depend on number of rows retrieved by search condition of the
query. Oracle reserves a memory area called cursors ,populates this
data with appropriate data and frees the area when task is completed.
1.Implicit cursor:-
These cursor is called as internal cursors and are
managed by oracle itself.
2.Explicit cursor:-
These cursor are user defined cursors used for
external processing.
IMPLICIT CURSOR:
1
DR.D.Y.PATIL POLYTECHNIC ,KASBA BAWADA
cursor closes after its associated statements run but its attributes
values remain available until another SELECT or DML statements is
executed . Cursor attributes return information about the state of the
cuesor. The syntax for an implicit cursor attribute in SQL attribute
e.g. SQL%found
SQL attribute will always cursor attribute refer to the recently run
DML or SELECT INTO statement .
Implicit Cursor Attributes:
1.SQL%ISOPEN
2.SQL%FOUND
3.SQL%NOTFOUND
4.SQL%ROWCOUNT
1.SQL%ISOPEN:
2.SQL%FOUND:
True if at least one row was processed .If any
DML or SELECT INTO statement returned any row the the value of
this attribute is true, if no rows were returned then the values is false
otherwise when no recent statement is executed then this value is null.
3.SQL%NOTFOUND:
True if no rows were processed . It works
like the SQL%FOUND but contrary results are obtained with
SQL%NOTFOUND that is false if rows are returned ,true if no rows
are returned ,true if no rows are returned and null if no recent
statement is executed.
2
DR.D.Y.PATIL POLYTECHNIC ,KASBA BAWADA
4.SQL%ROWCOUNT:
The number of rows processed by a SQL
statement . If shares null if no recent DML statements are executed
and stores the count of rows affected by the DML statement of select
into statement is executed.
Explicit cursor:
The cursor which is declared by user is called Explicit cursor .If select
statements in the PL/SQL returns multiple rows then you have to
create an explicit cursor .The set of rows returned by a multi-row
query is called the result set /Its size is the number of rows that meet
your search criteria.
Cursor cursorname IS SQL select statement;
Explicit cursorcan be controlled using following four control
statements .
1.DECLARE cursor in the declaration section
3
DR.D.Y.PATIL POLYTECHNIC ,KASBA BAWADA
2. Open :-
Open statement identifies the active set i.e. query returned
by select statement.
Syntax :- open cursorname;
3.FETCH:-
Fetch statement fetches rows into the variables cursors can
be made into use using cursor for loop |& fetch statement.
Syntax:- fetch cursorname into var1,var2……;
4.CLOSE :-
Close the cursor in the execution section before we end
of the PL/SQL block i.e. close statement closes the cursor.
Syntax:- close cursorname;
4
DR.D.Y.PATIL POLYTECHNIC ,KASBA BAWADA
OPEN cursor_name ;
When the last row has been processed the CLOSE statement disables
the cursor.
CLOSE cursor_name;
When a cursor is opened the first row becomes the current row.
Example:-
DECLARE
Emp_rec emp_tb1%rowtype;
CURSOR emp_cur IS
SELECT *
FROM emp_tb1
WHERE salary>10;
BEGIN
OPEN emp_cur;
FETCH emp_cur INTO emp_rec;
5
DR.D.Y.PATIL POLYTECHNIC ,KASBA BAWADA
Dbms_output.put_line(emp_rec.first_name//’ ‘//emp_rec.last_name);
CLOSE emp_cur;
END;
/
Output:-
Emp_rec.first_name Emp_rec.last_name
Tanvi Patil
Diksha Shinde
Shradha Dhumal
Syntax :
for record IN cursor_name
loop
action
end loop;
end;
/
Example:
Declare
Cursor c1 is select *from emp;
Begin
6
DR.D.Y.PATIL POLYTECHNIC ,KASBA BAWADA
Parameterized Cursor:
Example:
Declare
my_record emp%ROWTYPE;
7
DR.D.Y.PATIL POLYTECHNIC ,KASBA BAWADA
If 5000 is passed in the value of max_wage ,only the name & salary
data for those employee whose salary is less than 5000 is returned.
Output:
Name Salary
Ram 1500
Krishna 1600
Varad 1550
Manthan 3950
8
DR.D.Y.PATIL POLYTECHNIC ,KASBA BAWADA
References:
www.google.com
www.wikipedia.com