Bird
0
0

Given this code snippet:

medium📝 Debug Q14 of 15
PostgreSQL - Advanced PL/pgSQL
Given this code snippet:
DECLARE cur CURSOR FOR SELECT name FROM products;
OPEN cur;
FETCH cur;
CLOSE cur;
FETCH cur;

What error will occur when running this code?
AERROR: cursor "cur" does not exist
BNo error, FETCH returns next row
CERROR: syntax error near FETCH
DERROR: cursor "cur" is not open
Step-by-Step Solution
Solution:
  1. Step 1: Analyze cursor lifecycle

    Cursor is declared and opened, then FETCH is called once, then cursor is closed.
  2. Step 2: Identify error on second FETCH

    After CLOSE, cursor is not open, so FETCH causes "cursor is not open" error.
  3. Final Answer:

    ERROR: cursor "cur" is not open -> Option D
  4. Quick Check:

    FETCH after CLOSE causes 'not open' error [OK]
Quick Trick: Cannot FETCH after CLOSE; cursor must be open [OK]
Common Mistakes:
  • Trying to FETCH after cursor is closed
  • Expecting FETCH to reopen cursor automatically
  • Confusing 'not open' with 'does not exist' error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes