Multiple choice technology

You need to extract details of those products in the SALES table where the PROD_ID column contains the string '_D123'. Which WHERE clause could be used in the SELECT statement to get the required output?

  1. WHERE prod_id LIKE '%D123%' ESCAPE ''

  2. WHERE prod_id LIKE '%_D123%' ESCAPE ''

  3. WHERE prod_id LIKE '%D123%' ESCAPE '%'

  4. WHERE prod_id LIKE '%_D123%' ESCAPE '_'

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The LIKE operator with '%_D123%' would match any string containing '_D123', but underscore is a wildcard matching any single character. To search for a literal underscore, you need to escape it using the ESCAPE clause. Option B correctly uses backslash as the escape character (ESCAPE '\') and prefixes the underscore with backslash (_) to treat it as a literal character. Options A and C are incorrect because they don't properly escape the underscore. Option D incorrectly uses '_' as the escape character instead of '\'.