nerdexam
Oracle

1Z0-909 · Question #19

Examine this statement which executes successfully: SET @ir := 2; Which query updates the value of @r to 0?

The correct answer is D. SELECT 'Car' RLIKE 'Ca?' INTO @r. Note: There appears to be an error in the provided answer key. Based on MySQL behavior, C is actually the option that sets @r to 0, not D. Here's the accurate breakdown: Why C is the correct answer (returns 0): 'Car' LIKE 'Ca?' returns 0 because MySQL's LIKE only recognizes %…

Advanced SQL

Question

Examine this statement which executes successfully:

SET @ir := 2; Which query updates the value of @r to 0?

Options

  • ASELECT 'Car' REGEXP('Ca?') >= 0 INTO @r;
  • BSELECT STRCMP(`Car'/Ca?') >= 0 INTO @r;
  • CSELECT 'Car' LIKE 'Ca?' INTO @r;
  • DSELECT 'Car' RLIKE 'Ca?' INTO @r;

How the community answered

(41 responses)
  • A
    7% (3)
  • B
    15% (6)
  • C
    2% (1)
  • D
    76% (31)

Explanation

Note: There appears to be an error in the provided answer key. Based on MySQL behavior, C is actually the option that sets @r to 0, not D. Here's the accurate breakdown:

Why C is the correct answer (returns 0): 'Car' LIKE 'Ca?' returns 0 because MySQL's LIKE only recognizes % (any sequence) and _ (single char) as wildcards - ? is treated as a literal character. Since 'Car' doesn't equal 'Ca?', the result is 0.

Why the distractors (and D) are wrong:

  • A - 'Car' REGEXP 'Ca?' returns 1 (match found), so 1 >= 0 evaluates to 1, not 0.
  • B - STRCMP('Car', 'Ca?') returns 1 because 'r' (ASCII 114) > '?' (ASCII 63), so 1 >= 0 = 1.
  • D - RLIKE is a synonym for REGEXP. The pattern Ca? (C followed by optional 'a') does match the substring 'Ca' inside 'Car', so this returns 1, not 0 - meaning D does not set @r to 0.

Memory tip: Think "LIKE = Literal symbols, _ and %" - anything not _ or % in a LIKE pattern is literal. REGEXP/RLIKE uses real regex where ? means "zero or one of the preceding character." These two behave oppositely with ?.

If your exam source marks D as correct, verify with your instructor - this appears to be a question error.

Topics

#string matching operators#regular expressions#LIKE vs RLIKE#pattern matching

Community Discussion

No community discussion yet for this question.

Full 1Z0-909 Practice