Cursors Flashcards

1
Q

What is a cursor

A

A temporary work area created in the system memory when a SQL statement is executed. Contains information on a select statement and the rows of data accessed by it

Holds more than one row but only processes one row at a time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Active Set

A

The set of rows the cursor holds

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the two types of cursors

A

Implicit Cursor

Explicit Cursor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Implicit Cursor

A

Created by default when DML statements like INSERT, UPDATE, DELETE statements are executed. Also when a select statement only returns one row is executed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Implicit cursor attributes

A

%FOUND
%NOTFOUND
%ROWCOUNT
%ISOPEN

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

EXPLICIT Cursor what is it

A

Must be created when executing a select statement that return more than one row.

Multiple rows retrieved only one process at a time is the current row.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

FETCH A ROW

A

Retrieves the first row or the current row position moves to the next row. Explicit Cursor attribute

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the 4 steps in using an Explicit Cursor

A

DECLARE - Cursor in declaration section
OPEN - Cursor in the execution section
FETCH - data from the cursor variables or records is in execution sec
CLOSED - in the execution section before you end then PL/SQL block

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a parameterized cursor

A

Passes parameters into a cursor and uses them in a query
Defines only data types and not type length
Default value assigned and are local

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Cursor with a FOR Loop

A

Not required to declare a record or variable to store the cursor values, need not open, fetch and close the cursor.

Declare
Cursor cur_emp is
Select * From emp where sal > 1000;

Begin
 For cv_emp in cur_emp
 Loop
   Statement;
 End loop;
End;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a cursor variable

A

A pointier that distinguishes the current row in a resultset from a multiple row query

Several advantages over an explicit cursor
Point to a variety of queries suitable return type explicit tied to individual query
Opened independently of being processed
Passed as parameters between application layers and server side
Reduce client-server network traffic allows serval open in a round trip

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you define a Cursor Variable

A

REF CURSOR TYPE

Define in one or two ways
STRONGLY TYPED - restricted to an individual return type using return clause. Reduces chance if run time errors. Col mismatch at compile
and overflow flexibility

WEAKLY TYPE - Return clause is omitted allowing type to reference any return type. Greater flexibility increase likely runtime errors not picked up at compile

How well did you know this?
1
Not at all
2
3
4
5
Perfectly