0
0
PostgreSQLquery~10 mins

Cursor declaration and usage in PostgreSQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a cursor named mycursor for selecting all rows from the employees table.

PostgreSQL
DECLARE mycursor CURSOR FOR SELECT * FROM [1];
Drag options to blanks, or click blank then click option'
Aemployees
Bdepartments
Csalaries
Dprojects
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a table unrelated to employees.
Misspelling the table name.
2fill in blank
medium

Complete the code to open the cursor named mycursor.

PostgreSQL
OPEN [1];
Drag options to blanks, or click blank then click option'
Acur_emp
Bcursor1
Cmycursor
Demp_cursor
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different cursor name than declared.
Forgetting to open the cursor before fetching.
3fill in blank
hard

Fix the error in the FETCH statement to retrieve the next row from the cursor.

PostgreSQL
FETCH [1] FROM mycursor;
Drag options to blanks, or click blank then click option'
Anext
Bfirst
Cprevious
Dlast
Attempts:
3 left
💡 Hint
Common Mistakes
Using FETCH FIRST or FETCH LAST which do not fetch the next row.
Using FETCH PREVIOUS which moves backward.
4fill in blank
hard

Fill both blanks to declare and open a cursor named emp_cursor selecting employee_id and name from employees.

PostgreSQL
DECLARE [1] CURSOR FOR SELECT employee_id, name FROM employees;
OPEN [2];
Drag options to blanks, or click blank then click option'
Aemp_cursor
Bmycursor
Ccursor_emp
Demployee_cur
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for declaration and opening.
Misspelling the cursor name.
5fill in blank
hard

Fill all three blanks to fetch the first row from cursor emp_cursor into variables emp_id and emp_name.

PostgreSQL
FETCH [1] FROM emp_cursor INTO [2], [3];
Drag options to blanks, or click blank then click option'
Anext
Bemp_id
Cemp_name
Dfirst
Attempts:
3 left
💡 Hint
Common Mistakes
Using FETCH NEXT instead of FETCH FIRST.
Swapping variable names or using undeclared variables.