Oracle Database SQL (1Z0-071) Practice Questions

Oracle Database SQL (1Z0-071) exam preparation

Oracle Database SQL (1Z0-071) practice questions in English: 180 questions with explanations. The mock exam has 78 questions and 120 minutes.

Oracle Database SQL (1Z0-071) free question 6 / 10 · Domain 4: Using Single-Row Functions to Customize Output

Which is the result of the following SELECT statement? SELECT TRIM('0' FROM '0450890') FROM dual;

  1. '450890': LEADING is the default, so the leading 0 goes
  2. '45089': both end 0s are removed; the middle 0 stays
  3. '0450890': unchanged, because TRIM works on blanks, not on 0
  4. '4589': the 0 in the middle is removed along with the ends
Show the answer and explanation

Answer: B

Why this is correct
TRIM in the SQL Language Reference says that, if you specify BOTH or none of the three, Oracle removes leading and trailing characters equal to trim_character. The 0 at both ends of 0450890 is removed, and the 0 in the middle (between 45 and 89) remains, so the result is 45089.

Why the other options are wrong
"'450890': LEADING is the default, so the leading 0 goes" … This reads LEADING as the default. If you specify none of LEADING, TRAILING, and BOTH, the behavior is the same as BOTH, so the trailing 0 is removed as well.
"'4589': the 0 in the middle is removed along with the ends" … This reads TRIM as a function that deletes every 0 in the string, like REPLACE. TRIM removes only the characters that are consecutive at the two ends, and the 0 in the middle remains.
"'0450890': unchanged, because TRIM works on blanks, not on 0" … This reads TRIM as able to remove only spaces. A space is removed only as the default when trim_character is omitted. If you specify 0, the 0 at both ends is removed.

Key takeaway
The trim_character of TRIM is a single character, and a space is used if you omit it. If trim_source is NULL, the result is also NULL. To replace characters inside a string, use REPLACE.

Go to the Oracle Database SQL (1Z0-071) practice app (10 free questions; purchase unlocks all questions)

See the full practice set