一、原题
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;
答案:C
二、题目翻译
下面是查看 PRICE_LIST表的结构和数据
现在计划给product price打折25%,并使用与PROD_PRICE相同格式显示打折后的值
下面哪句SQL能给出所需的结果?
三、题目解析
因为PROD_PRICE是vachar2(10)类型,所以不能直接运算,需要先TO_NUMBER转换成数据型后才能进行计算,然后再TO_CHAR转换成字符型显示。