[每日一题] OCP1z0-047 :2013-07-18 时间格式................................................................7

来源:互联网 发布:链家端口费多少 编辑:程序博客网 时间:2024/06/11 02:13

有疑问可以去itpub讨论:http://www.itpub.net/thread-1803167-1-1.html






这道题目是考时间格式,日期的存贮格式,在ORACLE内部都由如下七部分构成:世纪、年、月、日、小时、分钟、秒。

OK,我们来做个测试:

gyj@OCM> create table gyj_order(order_id int,order_date date);

Table created.

gyj@OCM> insert into gyj_order values(1,sysdate);

 

1 row created.

gyj@OCM> commit;

Commit complete.

gyj@OCM> select * from gyj_order where order_date> to_date('JUL 10  2006','MON DDYYYY');

 

  ORDER_IDORDER_DAT

---------- ---------

         116-JUL-13

说明答案A正确

 

gyj@OCM> select * from gyj_order whereto_char(order_date,'MON DD YYYY')='JUL 16 2013';

 

  ORDER_IDORDER_DAT

---------- ---------

         116-JUL-13

说明答案B正确

 

gyj@OCM> select to_char(add_months(sysdate,6),'MONDD YYYY') from dual;

 

TO_CHAR(ADD_MO

--------------

JAN 16 2014

gyj@OCM> select * from gyj_order whereorder_date> to_char(add_months(sysdate,6),'MON DD YYYY');

select * from gyj_order where order_date>to_char(add_months(sysdate,6),'MON DD YYYY')

                                          *

ERROR at line 1:

ORA-01858: a non-numeric character was found where anumeric was expected

说明答案C不正确,时间类型与字符类型不能做比较

 

gyj@OCM> select * from gyj_order where order_datein(to_date('JUL 16 2013','MON DD YYYY'),to_char('JUL 16 2013','MON DD YYYY'));

select * from gyj_order where order_datein(to_date('JUL 16 2013','MON DD YYYY'),to_char('JUL 16 2013','MON DD YYYY'))

                                                                                        *

ERROR at line 1:

ORA-01722: invalid number

 

 

gyj@OCM> select to_char('JUL 16 2013','MON DDYYYY') from dual; select to_char('JUL 16 2013','MON DD YYYY') from dual

              *

ERROR at line 1:

ORA-01722: invalid number

上面的写法是错的,已是字符就无须用to_char转化,看下面的写法才是正确的:

 

gyj@OCM> select to_char(to_date('JUL 16 2013','MONDD YYYY'),'MON DD YYYY') from dual;

 

TO_CHAR(TO_

-----------

JUL 16 2013

 

还有时间与字符类型不能直接计算,如下报错:

gyj@OCM> select * from gyj_order where order_datein(to_char(to_date('JUL 16 2013','MON DD YYYY'),'MON DD YYYY'));

select * from gyj_order where order_datein(to_char(to_date('JUL 16 2013','MON DD YYYY'),'MON DD YYYY'))

                                            *

ERROR at line 1:

ORA-01858: a non-numeric character was found where anumeric was expected

 

答案D不正确

 

最终正确答案选:AB


QQ:252803295

学习交流QQ群:
DSI&Core Search  Ⅰ 群:127149411(技术:已满)
DSI&Core Search  Ⅱ 群:177089463(技术:未满)
DSI&Core Search  Ⅲ 群:284596437(技术:未满)
DSI&Core Search  Ⅳ 群:192136702(技术:未满)
DSI&Core Search  Ⅴ 群:285030382(闲聊:未满)



MAIL:oracledba_cn@hotmail.com

BLOG: http://blog.csdn.net/guoyjoe

WEIBO:http://weibo.com/guoyJoe0218

ITPUB: http://www.itpub.net/space-uid-28460966.html

OCM:   http://education.oracle.com/education/otn/YGuo.HTM


原创粉丝点击