QuestionQ121

VerifiedUsing Conversion Functions and Conditional Expressions

Review the data in the PROMO_BEGIN_DATE column of the promotions table:

Question Image

You want to show how many promotions began in 1999 and in 2000. Which query produces the correct output?

Question Image

Explanation

With the displayed DD-MON-RR-style date representation, SUBSTR(promo_begin_date, 8) returns the two-character year suffix because no length is specified. DECODE returns 1 for the matching suffix and 0 otherwise, so SUM counts two promotions for 1999 and two for 2000. TO_CHAR with the YYYY format model produces four-digit years, so it cannot match '99' or '00'; moreover, COUNT counts non-null zero values.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!