Bird
0
0

Which of the following is the correct syntax to declare a cursor named cur_emp for selecting all rows from employees table?

easy📝 Syntax Q12 of 15
PostgreSQL - Advanced PL/pgSQL
Which of the following is the correct syntax to declare a cursor named cur_emp for selecting all rows from employees table?
ACREATE CURSOR cur_emp AS SELECT * FROM employees;
BOPEN cur_emp CURSOR SELECT * FROM employees;
CDECLARE cur_emp CURSOR FOR SELECT * FROM employees;
DFETCH cur_emp FROM employees;
Step-by-Step Solution
Solution:
  1. Step 1: Recall cursor declaration syntax

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

    DECLARE cur_emp CURSOR FOR SELECT * FROM employees; matches this exactly; others use incorrect keywords or order.
  3. Final Answer:

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

    DECLARE + CURSOR + FOR + query = correct syntax [OK]
Quick Trick: Use DECLARE ... CURSOR FOR ... to declare [OK]
Common Mistakes:
  • Using OPEN instead of DECLARE for declaration
  • Confusing FETCH with DECLARE
  • Using CREATE CURSOR which is invalid syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes