一、原题
二、题目翻译
三、题目解析
四、测试
SQL> select LAST_DAY(SYSDATE) from dual;
LAST_DAY(SYS
------------
31-MAY-14
SQL> select NEXT_DAY(LAST_DAY(SYSDATE),'MON') from dual;
NEXT_DAY(LAS
------------
02-JUN-14
SQL> SELECT TO_CHAR(NEXT_DAY(LAST_DAY(SYSDATE),'MON'),
2 'dd "is the first Monday for" fmmonth rrrr')
3 FROM DUAL;
TO_CHAR(NEXT_DAY(LAST_DAY(SYSDATE),'MON'),'DD"ISTHEFIRSTMONDAYFOR"FMMONTHRRRR')
--------------------------------------------------------------------------------
02 is the first Monday for june 2014
You want to display the date for the first Monday of the next month and issue the following command:
SQL>SELECT TO_CHAR(NEXT_DAY(LAST_DAY(SYSDATE),'MON'),
'dd "is the first Monday for" fmmonth rrrr')
FROM DUAL;
What is the outcome?
A. It executes successfully and returns the correct result.
B. It executes successfully but does not return the correct result.
C. It generates an error because TO_CHAR should be replaced with TO_DATE.
D. It generates an error because rrrr should be replaced by rr in the format string.
E. It generates an error because fm and double quotation marks should not be used in the format string.
答案:A
SQL>SELECT TO_CHAR(NEXT_DAY(LAST_DAY(SYSDATE),'MON'),
'dd "is the first Monday for" fmmonth rrrr')
FROM DUAL;
What is the outcome?
A. It executes successfully and returns the correct result.
B. It executes successfully but does not return the correct result.
C. It generates an error because TO_CHAR should be replaced with TO_DATE.
D. It generates an error because rrrr should be replaced by rr in the format string.
E. It generates an error because fm and double quotation marks should not be used in the format string.
答案:A
二、题目翻译
要显示下个月的第一个星期一的日期,执行下面的命令,结果是什么?
A.执行成功,并且能得出正确结果。
B.执行成功,但不能返回正确的结果。
C.报错,TO_CHAR应该用TO_DATE替换。
D.报错,格式中,rrrr应该用rr替换。
E.报错,fm和双引号不能用在格式字符串中。
A.执行成功,并且能得出正确结果。
B.执行成功,但不能返回正确的结果。
C.报错,TO_CHAR应该用TO_DATE替换。
D.报错,格式中,rrrr应该用rr替换。
E.报错,fm和双引号不能用在格式字符串中。
三、题目解析
LAST_DAY显示本月的最后一天的日期,
NEXT_DATE函数返回从第一个参数的日期开始,紧接着下来的指定星期对应的第一个日期。
NEXT_DATE函数返回从第一个参数的日期开始,紧接着下来的指定星期对应的第一个日期。
四、测试
SQL> select LAST_DAY(SYSDATE) from dual;
LAST_DAY(SYS
------------
31-MAY-14
SQL> select NEXT_DAY(LAST_DAY(SYSDATE),'MON') from dual;
NEXT_DAY(LAS
------------
02-JUN-14
SQL> SELECT TO_CHAR(NEXT_DAY(LAST_DAY(SYSDATE),'MON'),
2 'dd "is the first Monday for" fmmonth rrrr')
3 FROM DUAL;
TO_CHAR(NEXT_DAY(LAST_DAY(SYSDATE),'MON'),'DD"ISTHEFIRSTMONDAYFOR"FMMONTHRRRR')
--------------------------------------------------------------------------------
02 is the first Monday for june 2014