select * from HOSPITAL_GATHERING WHERE 病人标识='2[吴永昌]253123727531.25' and to_date(归档时间 ,'yyyy-mm-dd hh24:mi:ss')=to_date('2008/1/8 15:55:05','yyyy-mm-dd hh24:mi:ss') 运行时出错:文字与格式字符串不匹配
调试欢乐多
-- 前后要一致撒!
-- 同理:to_date(归档时间 ,'yyyy-mm-dd hh24:mi:ss') 这一部分,
-- 你的“归档时间”字段是用字符串表示日期的?
-- 那么你的字串日期格式也要与你后面的'yyyy-mm-dd hh24:mi:ss'相一致!
-- 日期字段存储在数据库中的格式是一样的,只是你看到的有“斜杠”(2005/10/17 9:24:51) 这只是个显示问题,有个修改当前会话日期显示格式的参数: nls_date_format(这样的问题回答过无数遍啦!),
-- 请看如下操作:C:\Documents and Settings\Administrator>sqlplus /nologSQL*Plus: Release 10.2.0.1.0 - Production on 星期四 8月 25 09:39:56 2011Copyright (c) 1982, 2005, Oracle. All rights reserved.idle> conn scott/bee56915
已连接。
scott@TBWORA> select sysdate from dual;SYSDATE
-------------------
2011-08-25 09:40:06scott@TBWORA> alter session set nls_date_format='yyyy-mm-dd';会话已更改。scott@TBWORA> select sysdate from dual;SYSDATE
----------
2011-08-25scott@TBWORA> alter session set nls_date_format='yyyy-mm-dd hh24';会话已更改。scott@TBWORA> select sysdate from dual;SYSDATE
-------------
2011-08-25 09scott@TBWORA> alter session set nls_date_format='yyyy-mm-dd hh24:mi';会话已更改。scott@TBWORA> select sysdate from dual;SYSDATE
----------------
2011-08-25 09:40scott@TBWORA> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';会话已更改。scott@TBWORA> select sysdate from dual;SYSDATE
-------------------
2011-08-25 09:41:00
WHERE 病人标识='2[吴永昌]253123727531.25'
and 归档时间=to_date('2008/1/8 15:55:05','yyyy/mm/dd hh24:mi:ss');
-------------------
2011-08-01 21:23:57scott@TBWORA> alter session set nls_date_format='yyyy/mm/dd';会话已更改。scott@TBWORA> select * from t;CDATE
----------
2011/08/01
-- 无所谓存储格式问题(也就是说:所有的Date类型,在数据库里存储格式是一样的),
-- 只是个显示格式问题:你想要他怎么显示,
-- 你就可以用 to_char(date_column, DATE_NLS_FORMAT ) 去显示!
-- 其中:DATE_NLS_FORMAT是你要指定的日期格式,
-- 例如:'YYYY-MM-DD'、'MM-DD-YYYY'、'YYYY/MM/DD'、'yyyy-mm-dd hh24:mi:ss'-- 你还不明白,就是猪啦!