Bird
0
0

You need to process a large table sales in chunks of 50 rows using a cursor. Which code snippet correctly fetches 50 rows at a time?

hard📝 Application Q8 of 15
PostgreSQL - Advanced PL/pgSQL
You need to process a large table sales in chunks of 50 rows using a cursor. Which code snippet correctly fetches 50 rows at a time?
AOPEN cur; FETCH 50 ROWS FROM cur;
BOPEN cur; FETCH NEXT FROM cur LIMIT 50;
COPEN cur; FETCH ALL FROM cur WHERE rowcount=50;
DOPEN cur; FETCH FORWARD 50 FROM cur;
Step-by-Step Solution
Solution:
  1. Step 1: Understand FETCH syntax

    FETCH FORWARD n FROM cursor fetches n rows forward.
  2. Step 2: Analyze options

    OPEN cur; FETCH FORWARD 50 FROM cur; uses correct syntax to fetch 50 rows at once.
  3. Step 3: Incorrect options

    Options B, C, and D use invalid or unsupported syntax.
  4. Final Answer:

    OPEN cur; FETCH FORWARD 50 FROM cur; -> Option D
  5. Quick Check:

    FETCH FORWARD n fetches n rows [OK]
Quick Trick: Use FETCH FORWARD n to get n rows [OK]
Common Mistakes:
  • Using LIMIT inside FETCH
  • Assuming FETCH ALL can limit rows
  • Using unsupported FETCH syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes