3i Infotech Placement: Sample Questions 227 - 227 of 1245

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 227

Question

MCQ▾

Which of the following is not correct about Cursor?

Choices

Choice (4)

a.

Cursor holds temporary results

b.

Cursor is used for retrieving multiple rows

c.

Cursor is a named Private SQL area

d.

SQL uses implicit Cursors to retrieve rows

Answer

a.

Explanation

Define Cursor and Its Types

Cursor

  • Used for retrieving set of rows.
  • Essentially formed by assigning a name to a SELECT statement and manipulate the information within SQL statement.
  • Contains information on a select statement and rows of data accessed by it.
  • Holds more than one row, but it can process only one row at a time.
  • Multiple rows that the cursor holds form the active set.

Two types of cursors:

  • Implicit Cursors
  • Explicit Cursor
Two Types of Cursors

Implicit Cursors

  • Automatically generated by oracle when an SQL statement is executed.
  • Created to process the statement when DML statements like INSERT, UPDATE, and DELETE etc. are executed.

Provide some attribute:

  • % FOUND
    • Return value is TRUE if DML statements like INSERT, DELET and Update at least one or more rows and return one or more rows.
  • % NOTFOUND
    • Return value is TRUE if DML statement like INSERT, DELETE and UPDATE affect no row, or a SELECT INTO statement returns no row.
    • It is a opposite of % FOUND.
  • % ISOPEN
    • Returns FALSE for implicit cursor, because the SQL cursor automatically closes after execution.
  • % ROWCOUNT
    • Returns the number of rows affected by DML statement like INSERT, UPDATE, DELETE.
Provide Some Attribute

Explicit Cursors

  • Defined by programmers to gain more control on the context area.
  • Declaration section of the PL/SQL block.
  • Created on a SELECT statement which returns more than one row.

Syntax:

CURSOR cursor_name IS select_statement; ;

Steps of Creating Explicit cursor:

Declare the cursor:

  • Define name of cursor with a name and associated with SELECT statementSyntax:

    CURSOR name IS

    SELECT statement;

  • Open the Cursor

  • Allocate memory for the cursor to fetch the rows returned by the SQL statement. Syntax:

    OPEN cursor_name;

  • Fetch the Cursor

  • Access one row at a time. We can fetch row from the above-opened cursor. Syntax:

    FETCH cursor_name INTO variable_list;

  • Close the Cursor

  • Release the allocated memory

Syntax

Close cursor_name;

Developed by: