[每日一题] 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
- [每日一题] OCP1z0-047 :2013-07-18 时间格式................................................................7
- [每日一题] OCP1z0-047 :2013-07-29 视图――别名..........................................................18
- [每日一题] OCP1z0-047 :2013-08-28 DELETE..........................................................160
- [每日一题] OCP1z0-047 :2013-08-29 NULL............................................................168
- [每日一题] OCP1z0-047 :2013-07-13 oracle 10g正则表达式 REGEXP_LIKE 用法.....................................2
- [每日一题] OCP1z0-047 :2013-07-12 多表插入................................................................1
- [每日一题] OCP1z0-047 :2013-07-14 正则表达式...............................................................3
- [每日一题] OCP1z0-047 :2013-07-15 drop column.........................................................4
- [每日一题] OCP1z0-047 :2013-07-16 主键与唯一索引.............................................................5
- [每日一题] OCP1z0-047 :2013-07-20 序列MINVALUE的默认值是多少?.....................................9
- [每日一题] OCP1z0-047 :2013-07-23 CONNECT BY PRIOR层次查询.....................................12
- [每日一题] OCP1z0-047 :2013-07-22 group by 子句........................................................11
- [每日一题] OCP1z0-047 :2013-07-24 相关子查询定义......................................................13
- [每日一题] OCP1z0-047 :2013-07-25 权限――角色与对象权限.............................................14
- [每日一题] OCP1z0-047 :2013-07-31 扩展GROUP BY分组――ROLLUP..............................20
- [每日一题] OCP1z0-047 :2013-08-07 SELECT---PRODUCT_INFORMATION...................27
- [每日一题] OCP1z0-047 :2013-07-17 基本概念:同义词、动态性能视图、数据字典视图............6
- [每日一题] OCP1z0-047 :2013-07-19 Rules of Precedence――括号的使用.................8
- mini2440裸机之I2C
- 微软面试题:3,3,8,8,四个数字任意加减乘除使之最后等于24的编程解决方法
- 新版IKEEPER去除广告
- 配置cocos2d-iphone
- 黑马程序员 Java 正则表达式中的数量词
- [每日一题] OCP1z0-047 :2013-07-18 时间格式................................................................7
- 【Java】单例设计模式Singleton
- 堆栈链式实现入栈出栈等操作(C)
- 2013-7-18_SSH的开发_JSP调用ACTION的值一些错误
- 深度学习( Deep Learning )软件资源列表
- EasyUI datagrid使用JS删除多行rows的解决方案
- 多媒体开发指南
- padding和margin的异同点
- 让代码飞一会儿,超级有用的CSS编码工具集