0
0
PostgreSQLquery~10 mins

Performing operations on cursors 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 my_cursor for selecting all rows from the employees table.

PostgreSQL
DECLARE my_cursor 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
Using a table name that does not exist.
Forgetting to specify the table after SELECT * FROM.
2fill in blank
medium

Complete the code to open the cursor named my_cursor.

PostgreSQL
[1] my_cursor;
Drag options to blanks, or click blank then click option'
ACLOSE
BFETCH
COPEN
DDECLARE
Attempts:
3 left
💡 Hint
Common Mistakes
Using FETCH instead of OPEN to start the cursor.
Trying to DECLARE the cursor again instead of opening it.
3fill in blank
hard

Fix the error in the code to fetch one row from the cursor my_cursor into the variable emp_record.

PostgreSQL
FETCH [1] my_cursor INTO emp_record;
Drag options to blanks, or click blank then click option'
ANEXT
BALL
CPRIOR
DFIRST
Attempts:
3 left
💡 Hint
Common Mistakes
Using ALL fetches all rows, which is not valid syntax here.
Using PRIOR or FIRST fetches rows in different directions, which may cause errors.
4fill in blank
hard

Fill both blanks to close the cursor and then deallocate it.

PostgreSQL
[1] my_cursor;
[2] my_cursor;
Drag options to blanks, or click blank then click option'
ACLOSE
BOPEN
CDEALLOCATE
DFETCH
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to deallocate before closing the cursor.
Using OPEN or FETCH instead of CLOSE or DEALLOCATE.
5fill in blank
hard

Fill all three blanks to declare a cursor named emp_cursor for employees with salary over 50000, open it, and fetch one row into emp_rec.

PostgreSQL
DECLARE [1] CURSOR FOR SELECT * FROM employees WHERE salary [2] 50000;
[3] [1];
FETCH NEXT [1] INTO emp_rec;
Drag options to blanks, or click blank then click option'
Aemp_cursor
B>
COPEN
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong cursor name or inconsistent names.
Using < or other operators instead of > for salary condition.
Forgetting to open the cursor before fetching.