SQL语句报错(一)

SQL语句报错(一)


1、具体报错如下:

     ORA-01861:文字格式字符串不匹配

     01861. 00000 - "literal does not match format string"

     *Cause:Literals in the put must be the same length as literals in the format string

                    (with the exception of leading whitespace).

                    If the "FX" modifier has been toggled on,the literal must match exactly,with

                    no extra whitespace.

     *Action:Correct the format string to match the literal.


2、错误原因

        sb.append(" and t.date >= ? and t.date <= ?  ");

        由于date这个字段在数据库中的数据类型是Date,而我给date传的参数是字符串类型的,而字符串是不能比较大小的,所以会报个错误


3、解决办法

     sb.append(" and t.date >= to_date(?,'yyyymmdd')  and t.date <= to_date(?,'yyyymmdd')  ");

原文地址:https://www.cnblogs.com/hzcya1995/p/13315207.html