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;
答案:AB
解析:
decode(expr,search,result[,search,result,...,default]),比较expr和search,如果匹配返回result,如果都不匹配返回default
如果没有default那么返回null,oracle会将expr和匹配到的search,或者default自动转换为第一个result的类型,如果第一个result为char类型,那么返回varchar2类型
A:正确
B:正确
C:错误,如果NULLIF(promo_cost, 10000)返回不是null,那么最后结果应该是'N/A',他应该转换为第一个result,也就是promo_cost*.25,转换失败
D:错误,decode 里面 >100这个错误