100. View the Exhibit and examine the structure of the PROMOTIONS table.
Which SQL statements are valid? (Choose all that apply.)
A. SELECT promo_id, DECODE(NVL(promo_cost,0), promo_cost,
promo_cost * 0.25, 100) "Discount"
FROM promotions;
B. SELECT promo_id, DECODE(promo_cost, 10000,
DECODE(promo_category, 'G1', promo_cost *.25, NULL),
NULL) "Catcost"
FROM promotions;
C. SELECT promo_id, DECODE(NULLIF(promo_cost, 10000),
NULL, promo_cost*.25, 'N/A') "Catcost"
FROM promotions;
D. SELECT promo_id, DECODE(promo_cost, >10000, 'High',
<10000, 'Low') "Range"
FROM promotions;
C不正确,因为把’N/A’隐式转换成数值时不成功。D语法不正确。
DECODE(expr,search1,result1[,search2,result2……,default]):比较expr与search,如果等于search1则返回result1,如果等于search2则返回result2,依次类推,如果都不等于,如果有default则返回default,否则返回NULL.
ORACLE在比较之前,会自动把expr和每一个search隐式转换成第一个search(search1)的数据类型。自动把返回值转换成第一个result(result1)的数据类型。如果第一个result的数据类型为CHAR或者值是null,则Oracle转换返回值为VARCHAR2.
在DECODE函数中,NULL是相等的,如果expr为空,则Oracle将会返回第一个为NULL的search所对应的result。DECODE列表中的最大表达式个数为255个。