Bird
0
0

What is wrong with this cursor declaration?

medium📝 Debug Q7 of 15
PostgreSQL - Advanced PL/pgSQL
What is wrong with this cursor declaration?
DECLARE mycursor CURSOR FOR SELECT id FROM orders WHERE status = 'shipped';
OPEN mycursor;
FETCH NEXT FROM mycursor;
ACursor must be declared inside a transaction block
BCursor name must not contain uppercase letters
CCursor declaration is correct; no error
DCursor declaration missing IS keyword
Step-by-Step Solution
Solution:
  1. Step 1: Recall cursor transaction rules

    In PostgreSQL, cursors must be declared inside a transaction block.
  2. Step 2: Analyze code context

    Code snippet does not show BEGIN; without transaction, cursor usage fails.
  3. Final Answer:

    Cursor must be declared inside a transaction block -> Option A
  4. Quick Check:

    Cursors require transaction block [OK]
Quick Trick: Declare cursors inside BEGIN...COMMIT block [OK]
Common Mistakes:
  • Assuming cursor names are case-sensitive
  • Expecting IS keyword in DECLARE
  • Ignoring transaction requirement

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes