QuestionQ29

VerifiedUsing Conversion Functions and Conditional Expressions

Examine the structure and data in the PRICE_LIST table:

| Name | Null? | Type |

|---|---|---|

| PROD_ID | NOT NULL | NUMBER(3) |

| PROD_PRICE | | VARCHAR2(10) |

| PROD_ID | PROD_PRICE |

|---:|---|

| 100 | $234.55 |

| 101 | $6,509.75 |

| 102 | $1,234 |

in the same format as PROD_PRICE. Which SQL statement would produce the required result?

Explanation

A formatted currency value stored in VARCHAR2 must be parsed with TO_NUMBER using a number format model that accommodates the dollar sign, comma group separator, and decimal point before multiplying it by .25. TO_CHAR with a currency format model then returns the calculated value as formatted character data. Oracle documents that TO_NUMBER converts character expressions to NUMBER and that TO_CHAR converts a NUMBER to VARCHAR2 using a number format model.

Learn more

Community Discussion

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