Reputation: 11
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.
Upvotes: 1
Views: 9119
Reputation: 998
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
Upvotes: 0
Reputation: 1
Option A Other options I am not sure about. But A is definitely correct.
Upvotes: 0