0
970views
cursor and types of cursor
1 Answer
0
3views

Cursor :

  • A cursor is a temporary work. once created in system memory where a SQL statement is executed.

  • This temporary work are used to store the retired from the database and manipulate this data.

  • A cursor can held more than row but can process any one at a time.

Types of cursor:

1] Implicit cursor.

The cursor are created data set when DML statement like insert, update and delete are executed.

  • SQL provides few attributes so these cursors as.

% found : If DML statement returns at-least one zero the value is true.

% Not found : If DML statement retrieve at-least one row the value is false.

Row count : Return the number of row affected of DML operation.

Example :

Begin

update customer.

SET Salary = Salary + bonus

where id = 20

if sal % not found then.

dbms output pulline (No customer);

end if

end

Above cursor will display the merge, if none of row is updated after execution of update statement.

2] Explicit cursor :

These cursor created when we are executing a select statement that return more than one row :

Following steps are followed :

  • Declare the cursor.

  • Open the cursor.

  • Fetch the data.

  • Close the cursor.

Creation.

cursor cursorname is

select statement opening

open cursorname

fetching

fetch cursor into varl, var 2

closing

close cursor name

Example

Declare

cid customer id% type

name customer name % type

cursor is

select id, name from

customer

Begin

open cust

Loop

fetch cust into cid

exist when cust % not found

dbms.output.putline (% d=)

end loop

close cust

end

Please log in to add an answer.