Cursors Flashcards

1
Q

What are the two types of cursors?

A
  • Implicit cursors

- Explicit cursors

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

What are implicit cursors?

A

Automatically created by Oracle whenever an SQL statement is executed, when there is no explicit cursor for the statement.

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

What are explicit cursors?

A

Programmer-defined cursors for gaining more control over the context area

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

What is the syntax for creating an explicit cursor?

A

CURSOR cursor_name IS select_statement;

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

What are the steps when working with an explicit cursor?

A
  • Declaring the cursor for initializing the memory
  • Opening the cursor for allocating the memory
  • Fetching the cursor for retrieving the data
  • Closing the cursor to release the allocated memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you declare a cursor?

A

CURSOR name IS SELECT col1, col2 FROM table;

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

How do you open a cursor?

A

OPEN name;

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

How do you fetch a cursor?

A

FETCH name INTO c_col1, c_col2;

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

How do you close a cursor?

A

CLOSE name;

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

How do you close a cursor?

A

CLOSE name;

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

What are the attributes for implicit cursors?

A
  • %FOUND
  • %NOTFOUND
  • %ISOPEN
  • %ROWCOUNT
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is %FOUND?

A

Returns TRUE if an INSERT, UPDATE, or DELETE statement affected one or more rows or a SELECT INTO statement returned one or more rows. Otherwise, it returns FALSE.

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

What is %NOTFOUND?

A

Returns TRUE if an INSERT, UPDATE, or DELETE statement affected no rows, or a SELECT INTO statement returned no rows. Otherwise, it returns FALSE.

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

What is %ISOPEN?

A

If a cursor is open, cursor_name%ISOPEN returns TRUE; otherwise, it returns FALSE.

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

What is %ROWCOUNT?

A

Returns the number of rows affected by an INSERT, UPDATE, or DELETE statement, or returned by a SELECT INTO statement.

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

How do you loop through a cursor?

A

FOR elementName IN cursorName LOOP
– Code here
END LOOP;