SQL> create table t("date" date);表已创建。SQL> begin
  2  for x in 1..6 loop
  3  insert into t values(sysdate+x);
  4  end loop;
  5  commit;
  6  end;
  7  /PL/SQL 过程已成功完成。SQL> select * from t;date
-------------------
2005-07-20 16:29:33
2005-07-21 16:29:33
2005-07-22 16:29:33
2005-07-23 16:29:33
2005-07-24 16:29:33
2005-07-25 16:29:33已选择6行。SQL> select t."date" from t where "date">'2005-07-22 16:29:33';date
-------------------
2005-07-23 16:29:33
2005-07-24 16:29:33
2005-07-25 16:29:33已选择3行。

解决方案 »

  1.   

    select t."date" from t 执行正确
    不过
    SQL> select t."date" from t where "date">'2005-07-22 16:29:33';
    select t."date" from t where "date">'2005-07-22 16:29:33'
                                        *
    ERROR 位于第 1 行:
    ORA-01861: 文字与格式字符串不匹配
    -----------
    这又是怎么回事呢?
      

  2.   

    数据类型的问题。一般使用以下方式:select t."date" from t where "date">to_date('2005-07-22 16:29:33','yyyy-mm-dd hh24:mi:ss');
      

  3.   

    select t."date" from t where "date">to_date('2005-07-22 16:29:33','yyyy-mm-dd hh24:mi:ss');
      

  4.   

    我在先前设置过会话环境:
    alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';设置了会话环境后,日期比较就可以省掉to_date()函数调用了,就不会报错了。