1Z0-909 · Question #41
Examine these statement which execute successfully: Now, examine the statements executed in the mysqi command-line client: What is true? A. B. C. D.
The correct answer is C. Statement 1 displays: +-----+-----+-----+ | p1 | p2 | p3 | +-----+-----+-----+ | 10 | NULL| 30 | +-----+-----+-----+ Statement 2 displays: +-----+-----+-----+ | @p1 | @p2 | @p3 | +-----+-----+-----+ | 10 | 2 | 3 | +-----+-----+-----+. Option C is correct because MySQL OUT parameters are always initialized to NULL inside a stored procedure, regardless of the value held by the user-defined variable passed as the argument - so p2 is NULL even though the caller may have passed a non-null @p2. Meanwhile, IN…
Question
Examine these statement which execute successfully:
Now, examine the statements executed in the mysqi command-line client:
What is true? A. B. C. D.
Exhibit
Options
- AStatement 1 displays: +-----+-----+-----+ | p1 | p2 | p3 | +-----+-----+-----+ | 10 | 20 | 30 | +-----+-----+-----+ Statement 2 displays: +-----+-----+-----+ | @p1 | @p2 | @p3 | +-----+-----+-----+ | 1 | 2 | 3 | +-----+-----+-----+
- BStatement 1 displays: +-----+-----+-----+ | p1 | p2 | p3 | +-----+-----+-----+ | NULL| NULL| NULL| +-----+-----+-----+ Statement 2 displays: +-----+-----+-----+ | @p1 | @p2 | @p3 | +-----+-----+-----+ | 1 | 2 | 3 | +-----+-----+-----+
- CStatement 1 displays: +-----+-----+-----+ | p1 | p2 | p3 | +-----+-----+-----+ | 10 | NULL| 30 | +-----+-----+-----+ Statement 2 displays: +-----+-----+-----+ | @p1 | @p2 | @p3 | +-----+-----+-----+ | 10 | 2 | 3 | +-----+-----+-----+
- DStatement 1 displays: +-----+-----+-----+ | p1 | p2 | p3 | +-----+-----+-----+ | 10 | NULL| NULL| +-----+-----+-----+ Statement 2 displays: +-----+-----+-----+ | @p1 | @p2 | @p3 | +-----+-----+-----+ | 10 | 20 | 30 | +-----+-----+-----+
How the community answered
(44 responses)- A18% (8)
- B5% (2)
- C70% (31)
- D7% (3)
Explanation
Option C is correct because MySQL OUT parameters are always initialized to NULL inside a stored procedure, regardless of the value held by the user-defined variable passed as the argument - so p2 is NULL even though the caller may have passed a non-null @p2. Meanwhile, IN parameters (p1 and p3) correctly receive the values supplied at call time (10 and 30), and session variables (@p1, @p2, @p3) retain their pre-call values unless explicitly overwritten by an OUT/INOUT assignment within the procedure body.
Why the distractors fail:
- A is wrong because it shows
p2 = 20inside the procedure -OUTparameters never inherit the caller's value; they always beginNULL. - B is wrong because it shows all three local params as
NULL, ignoring thatINparameters (p1,p3) do receive their passed values of 10 and 30. - D is wrong because it shows
p3 = NULLinside the procedure (anINparam would hold its passed value, 30) and incorrectly shows@p1/@p2/@p3 = 10/20/30outside.
Memory tip: Think of OUT as "output only" - the procedure produces the value, it never receives one, so it always enters the procedure as NULL. Contrast with IN (read-only copy of the caller's value) and INOUT (gets the caller's value AND can write back).
Topics
Community Discussion
No community discussion yet for this question.
