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
You plan to give a discount of 25% on the product price and need to display the discount amount
in the same format as the PROD_PRICE.
Which SQL statement would give the required result?
A.
SELECT TO_CHAR(prod_price* .25,’$99,999.99′)
FROM PRICE_LIST;
B.
SELECT TO_CHAR(TO_NUMBER(prod_price)* .25,’$99,999.00′)
FROM PRICE_LIST;
C.
SELECT TO_CHAR(TO_NUMBER(prod_price,’$99,999.99′)* .25,’$99,999.00′) FROM
PRICE_LIST;
D.
SELECT TO_NUMBER(TO_NUMBER(prod_price,’$99,999.99′)* .25,’$99,999.00′) FROM
PRICE_LIST;
Explanation:
Using the TO_CHAR Function
The TO_CHAR function returns an item of data type VARCHAR2. When applied to items of type
NUMBER, several formatting options are available. The syntax is as follows:
TO_CHAR(number1, [format], [nls_parameter]),
The number1 parameter is mandatory and must be a value that either is or can be implicitly
converted into a number. The optional format parameter may be used to specify numeric
formatting information like width, currency symbol, the position of a decimal point, and group (or
thousands) separators and must be enclosed in single
Syntax of Explicit Data Type Conversion
Functions
TO_NUMBER(char1, [format mask], [nls_parameters]) = num1
TO_CHAR(num1, [format mask], [nls_parameters]) = char1
TO_DATE(char1, [format mask], [nls_parameters]) = date1
TO_CHAR(date1, [format mask], [nls_parameters]) = char1
D is wrong as to make an arithmetic operation you need to convert prod_price to a proper number where you can do the operation.
B is the right one.
answer is B
C is correct.
B produces “invalid number” error as it cannot implicitly convert ‘$’ and ‘,’ into a number without format mask.
C is correct:
SELECT TO_CHAR(TO_NUMBER(‘$1,234.56’, ‘$99,999.99’) *.25, ‘$99,999.99’) FROM dual;
=> $308.64
A, B and D don’t work.
My developer is trying to persuade me to move to .net from PHP. I have always disliked the idea because of the expenses. But he’s tryiong none the less. I’ve been using Movable-type on various websites for about a year and am concerned about switching to another platform. I have heard very good things about blogengine.net. Is there a way I can transfer all my wordpress content into it? Any help would be greatly appreciated!|