0
0
SQLquery~10 mins

CURSOR concept and usage in SQL - 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.

SQL
DECLARE [1] CURSOR FOR SELECT * FROM employees;
Drag options to blanks, or click blank then click option'
Amy_cursor
Bcursor1
Ccur
Demp_cursor
Attempts:
3 left
💡 Hint
Common Mistakes
Using a keyword instead of a valid cursor name.
Forgetting to name the cursor.
2fill in blank
medium

Complete the code to open the cursor named my_cursor.

SQL
OPEN [1];
Drag options to blanks, or click blank then click option'
Aemp_cursor
Bcursor1
Ccur
Dmy_cursor
Attempts:
3 left
💡 Hint
Common Mistakes
Opening a cursor with a wrong or undefined name.
Forgetting the semicolon at the end.
3fill in blank
hard

Fix the error in the FETCH statement to get data from my_cursor.

SQL
FETCH [1] INTO employee_name, employee_id;
Drag options to blanks, or click blank then click option'
Amy_cursor
Bcursor1
Ccur
Demp_cursor
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different cursor name than declared.
Forgetting to open the cursor before fetching.
4fill in blank
hard

Fill both blanks to correctly close and deallocate the cursor named my_cursor.

SQL
CLOSE [1];
DEALLOCATE [2];
Drag options to blanks, or click blank then click option'
Amy_cursor
Bcursor1
Cemp_cursor
Dcur
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names in CLOSE and DEALLOCATE.
Forgetting to deallocate after closing.
5fill in blank
hard

Fill all three blanks to declare, open, and fetch from a cursor named emp_cur.

SQL
DECLARE [1] CURSOR FOR SELECT name, id FROM employees;
OPEN [2];
FETCH [3] INTO emp_name, emp_id;
Drag options to blanks, or click blank then click option'
Aemp_cur
Bmy_cursor
Ccursor1
Dcur
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing different cursor names in the statements.
Forgetting to open the cursor before fetching.