91. View the Exhibit and examine the structure of the PROMOTIONS table.
Which two SQL statements would execute successfully? (Choose two.)
A. UPDATE promotions
SET promo_cost = promo_cost+ 100
WHERE TO_CHAR(promo_end_date, 'yyyy') > '2000';
B. SELECT promo_begin_date
FROM promotions
WHERE TO_CHAR(promo_begin_date,'mon dd yy')='jul 01 98';
C. UPDATE promotions
SET promo_cost = promo_cost+ 100
WHERE promo_end_date > TO_DATE(SUBSTR('01-JAN-2000',8));
D. SELECT TO_CHAR(promo_begin_date,'dd/month')
FROM promotions
WHERE promo_begin_date IN (TO_DATE('JUN 01 98'), TO_DATE('JUL 01 98'));
Answer: AB
答案解析:
A答案:
sh@TEST0924> UPDATE promotions
2 SET promo_cost = promo_cost+ 100
3 WHERE TO_CHAR(promo_end_date, 'yyyy') > '2000';
42 rows updated.
B答案:
sh@TEST0924> SELECT promo_begin_date
2 FROM promotions
3 WHERE TO_CHAR(promo_begin_date,'mon dd yy')='jul 01 98';
PROMO_BEG
---------
01-JUL-98
01-JUL-98
01-JUL-98
01-JUL-98
01-JUL-98
01-JUL-98
6 rows selected.
C答案:格式不匹配,需要使用格式符转换
sh@TEST0924> UPDATE promotions
2 SET promo_cost = promo_cost+ 100
3 WHERE promo_end_date > TO_DATE(SUBSTR('01-JAN-2000',8));
WHERE promo_end_date > TO_DATE(SUBSTR('01-JAN-2000',8))
*
ERROR at line 3:
ORA-01861: literal does not match format string
sh@TEST0924> select SUBSTR('01-JAN-2000',8) from dual;
SUBS
----
2000
sh@TEST0924> UPDATE promotions
2 SET promo_cost = promo_cost+ 100
3 WHERE promo_end_date > TO_DATE(SUBSTR('01-JAN-2000',8),'yyyy');
84 rows updated.
D答案:TO_DATE转换的日期如果与默认格式不一样,需要使用格式符转换
h@TEST0924> SELECT TO_CHAR(promo_begin_date,'dd/month')
2 FROM promotions
3 WHERE promo_begin_date IN (TO_DATE('JUN 01 98'), TO_DATE('JUL 01 98'));
WHERE promo_begin_date IN (TO_DATE('JUN 01 98'), TO_DATE('JUL 01 98'))
*
ERROR at line 3:
ORA-01858: a non-numeric character was found where a numeric was expected
sh@TEST0924> SELECT TO_CHAR(promo_begin_date,'dd/month')
2 FROM promotions
3 WHERE promo_begin_date IN (TO_DATE('JUN 01 98','mon dd yy'),TO_DATE('JUL 01 98','mon dd yy'));
no rows selected