简体   繁体   中英

Rowcount of an implicit cursor in sql

I attempted a test of SQL in which I got this question:

Choose one or more correct statements:
A. ROWCOUNT of an implicit cursor gives the total number of rows matched by the query
B. ROWCOUNT of an explicit cursor gives the total number of rows fetched so far
C. ROWCOUNT of an implicit cursor gives the total number of rows fetched so far
D. ROWCOUNT of an explicit cursor gives the total number of rows matched by the query

I have no idea what should be the correct option(s) for the above questions.

Please help me to find correct ans for above question.

Thank You.

Option A Other options I am not sure about. But A is definitely correct.

A + B are correct.

You can find the solution in the link in comment .

Here you will find the following information:

Implicit Cursors

PL/SQL declares a cursor implicitly for all SQL data manipulation statements... The value of the SQL%ROWCOUNT attribute refers to the most recently executed SQL statement from PL/SQL.

Example:

BEGIN
   UPDATE tbl1 SET col1 = 1 WHERE col2 = 1;
   DBMS_OUTPUT.PUT_LINE (SQL%ROWCOUNT);
   
   UPDATE tbl1 SET col1 = 2 WHERE col2 = 2;
   DBMS_OUTPUT.PUT_LINE (SQL%ROWCOUNT);
END;
/

Returns:

1
1

Explicit Cursors

When its cursor or cursor variable is opened, %ROWCOUNT is zeroed. Before the first fetch, %ROWCOUNT yields 0. Thereafter, it yields the number of rows fetched so far.

Example:

DECLARE
   CURSOR cur IS SELECT col1 FROM tbl1;
   l_result tbl1.col1%TYPE;
BEGIN
   OPEN cur;
   LOOP
      FETCH cur INTO l_result;
      EXIT WHEN cur%NOTFOUND;
      DBMS_OUTPUT.PUT_LINE('Rowcount: ' || cur%ROWCOUNT);
   END LOOP;
   CLOSE cur;
END;
/

Returns:

Rowcount: 1
Rowcount: 2
Rowcount: 3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM