Interacting With Databases Class 12 Informatics Practices Revision Notes
Class 12 Informatics Practices students should refer to the following concepts and notes for Interacting With Databases in standard 12. These exam notes for Grade 12 Informatics Practices will be very useful for upcoming class tests and examinations and help you to score good marks
Interacting With Databases Notes Class 12 Informatics Practices
INTERACTING WITH DATABASES
Cursor is a method that provides a way to select multiple rows of data from the database and then process each row individually inside the PL/SQL program.
Types of Cursors :
♦ Implicit Cursor : Declared for all DML & PL/SQL SELECT statement including queries that return only one row.
♦ Explicit Cursor: For queries that return more than one row. Declared and named by programmer.
Explicit Cursor :
Following steps are followed when using the explicit cursor:
1. Declare the cursor.
2. Open the cursor.
3. Fetch the data from the cursor record by record.
4. Close the cursor.
Syntax for using cursor:
♦ Syntax of cursor declaration:
♦ Syntax of open statement:
♦ Syntax of fetch statement
♦ Syntax of close statement:
Explicit Cursor attributes:
There are four cursor attributes :
♦ %ISOPEN : It returns true if cursor is open , otherwise it returns false.
Syntax : if cursorname%isopen then
♦ %FOUND : It returns true if record was fetched properly from the cursor, otherwise it returns false.
Syntax : cursorname%found
♦ %NOTFOUND : It returns true if record is not successfully found, otherwise it returns false.
Syntax : cursorname%notfound
♦ %ROWCOUNT : It returns the no. of records processed by the cursor.
Syntax : cursorname%rowcount
Example code to illustrate cursor:
cursor empdis is SELECT * FROM emp;
if empdis%ISOPEN then
dbms_output.put_line(‘empno name salary’);
FETCH empdis into e;
EXIT WHEN empdis%notfound;
dbms_output.put_line(e.empno|| e.name|| e.sal);
dbms_output.put_line(‘Cannot open the cursor’);
These are also called as SQL cursors.
PL/SQL employs implicit cursors for following statements:
iv. SELECT(only those SELECT queries that return exactly one row.)
Subqueries,IN WHERE clause,IN FROM clause, Aliases, Expressions,bind variables can be used with
Cursor Based Records:
Cursor FOR Loops:
In a Cursor FOR Loop,a declared cursor is OPENed,FETCHed and CLOSed automatically.
Cursor FOR Loop with Parameters:
Cursor FOR Loops Using Subqueries:
Please refer to attached file for CBSE Class 12 Informatics Practices Interacting with Databases study notes