Bird
0
0

Which of the following is the correct syntax to declare a cursor named cur1 for a SELECT query in PostgreSQL?

easy📝 Syntax Q12 of 15
PostgreSQL - Advanced PL/pgSQL
Which of the following is the correct syntax to declare a cursor named cur1 for a SELECT query in PostgreSQL?
AOPEN cur1 CURSOR FOR SELECT * FROM employees;
BDECLARE cur1 CURSOR FOR SELECT * FROM employees;
CFETCH cur1 CURSOR FOR SELECT * FROM employees;
DCREATE CURSOR cur1 FOR SELECT * FROM employees;
Step-by-Step Solution
Solution:
  1. Step 1: Recall cursor declaration syntax

    In PostgreSQL, cursors are declared using DECLARE cursor_name CURSOR FOR query.
  2. Step 2: Match syntax with options

    DECLARE cur1 CURSOR FOR SELECT * FROM employees; matches the correct DECLARE syntax; others misuse OPEN, FETCH, or CREATE.
  3. Final Answer:

    DECLARE cur1 CURSOR FOR SELECT * FROM employees; -> Option B
  4. Quick Check:

    DECLARE cursor FOR query [OK]
Quick Trick: Use DECLARE to define cursor before OPEN or FETCH [OK]
Common Mistakes:
  • Using OPEN instead of DECLARE to define cursor
  • Trying to FETCH during declaration
  • Using CREATE CURSOR which is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes