nerdexam
Oracle

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…

Stored Programs

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)
  • A
    9% (2)
  • C
    86% (19)
  • D
    5% (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): LEAVE exits a labeled loop or block using a label name, not a condition name - these are unrelated constructs.
  • B (IF statement): IF evaluates a boolean expression; a condition name is not a boolean and cannot appear there.
  • C (WHILE loop): Same reason as IF - a WHILE condition 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

#DECLARE CONDITION#Stored Procedures#Exception Handling#SQLSTATE

Community Discussion

No community discussion yet for this question.

Full 1Z0-909 Practice