QuestionQ30

VerifiedUsing Conversion Functions and Conditional Expressions

Examine the structure of the transactions table:

Question Image

You want to display the date, time, and transaction amount for transactions completed before 12 noon. Display zero for transactions for which no transaction amount was entered. Which query produces the required result?

Question Image

Explanation

TO_CHAR formats a TIMESTAMP using the supplied datetime format model and formats a NUMBER using the supplied number format model. HH24 yields the 24-hour clock hour, so values below 12 represent transactions before noon. NVL(TO_CHAR(trans_amt, '$99999999D99'), 0) substitutes zero when TRANS_AMT is null; because the first expression is character data, Oracle converts the zero to character data for the result.

Learn more

Community Discussion

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