1Z0-909 · Question #21
Examine this statement: DECLARE not_found CONDITION FOR SQLSTATE '02000'; In which two statements can not found be used?
The correct answer is C. in a while loop E. in a signal statement. The stated correct answer of C and E appears to be incorrect based on MySQL documentation. The actual correct answer should be D and E. A named CONDITION (like not_found) declared with DECLARE ... CONDITION FOR SQLSTATE can only be referenced in two specific contexts: a HANDLER…
Question
Examine this statement:
DECLARE not_found CONDITION FOR SQLSTATE '02000'; In which two statements can not found be used?
Options
- Ain a leave statement to exit a loop
- Bin an if statement
- Cin a while loop
- Din a handler declaration
- Ein a signal statement
How the community answered
(22 responses)- A9% (2)
- C86% (19)
- D5% (1)
Explanation
The stated correct answer of C and E appears to be incorrect based on MySQL documentation. The actual correct answer should be D and E.
A named CONDITION (like not_found) declared with DECLARE ... CONDITION FOR SQLSTATE can only be referenced in two specific contexts: a HANDLER declaration (DECLARE CONTINUE HANDLER FOR not_found ...) to trap the condition and execute recovery logic, and a SIGNAL statement (SIGNAL not_found) to explicitly raise that condition. These are the two grammatically valid places MySQL allows a condition name to appear.
Why the distractors are wrong:
- A (LEAVE):
LEAVEexits a labeled loop or block using a label name, not a condition name - these are unrelated constructs. - B (IF statement):
IFevaluates a boolean expression; a condition name is not a boolean and cannot appear there. - C (WHILE loop): Same reason as
IF- aWHILEcondition must be a boolean expression, not a declared condition name.
Memory tip: Think of a named CONDITION as a label for an error code - you can catch it (HANDLER) or throw it (SIGNAL). Anywhere else, MySQL doesn't recognize it syntactically.
If this question appeared on an official exam, flag it - the answer key likely has a typo swapping C for D.
Topics
Community Discussion
No community discussion yet for this question.