0
0
MySQLquery~10 mins

Cursors for row iteration in MySQL - 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 'cur' for selecting all rows from the 'employees' table.

MySQL
DECLARE [1] CURSOR FOR SELECT * FROM employees;
Drag options to blanks, or click blank then click option'
Acursor
Bcur1
Ccur
Dmycursor
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cursor' as the cursor name which is a keyword.
Forgetting to declare the cursor before using it.
2fill in blank
medium

Complete the code to open the cursor named 'cur'.

MySQL
OPEN [1];
Drag options to blanks, or click blank then click option'
Acur
Bcur1
Ccursor
Dmycursor
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to open a cursor with a different name than declared.
Missing the semicolon at the end.
3fill in blank
hard

Fix the error in the FETCH statement to retrieve data into the variable 'emp_name'.

MySQL
FETCH [1] INTO emp_name;
Drag options to blanks, or click blank then click option'
Acur
Bcursor
Ccur1
Dmycursor
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong cursor name in FETCH.
Not declaring the variable before FETCH.
4fill in blank
hard

Fill both blanks to declare a handler for NOT FOUND condition and close the cursor named 'cur'.

MySQL
DECLARE CONTINUE HANDLER FOR [1] SET done = TRUE;
CLOSE [2];
Drag options to blanks, or click blank then click option'
ANOT FOUND
BSQLSTATE '02000'
Ccur
Ddone
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong condition name in handler.
Closing a cursor with a wrong name.
5fill in blank
hard

Fill all three blanks to fetch rows from cursor 'cur', check for done, and leave the loop if done.

MySQL
FETCH [1] INTO emp_name;
IF [2] THEN
  LEAVE [3];
END IF;
Drag options to blanks, or click blank then click option'
Acur
Bdone
Cloop_label
Demp_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong cursor name in FETCH.
Checking wrong variable for done condition.
Leaving a loop with wrong label.