ORA-01810 format code appears twice solution, ora-01810 Solution
When you make a query page this morning, you need to query the spans of two time ranges. Use the TO_DATE function and write it at the beginning
SQL code
TO_DATE ('2017-08-04 00:00:00 ', 'yyyy-MM-DD HH: mm: ss ')
The result reported that the ORA-01810 format code had two errors. After the query, it was found that there was a problem with the formatting string,
The format should not be repeated twice. Otherwise, Oracle does not know which placeholder range to resolve the field,
The correct format should be like this. MI is used to represent minutes.
Correct SQL code:
TO_CHAR ('2017-08-04 00:00:00 ', 'yyyy-MM-DD HH: MI: ss ')
If HH does not support the 24-hour format, you can write the following format:
SQL code:
TO_CHAR ('2017-08-04 00:00:00 ', 'yyyy-MM-DD HH24: MI: ss ')
Formatting strings in ORACLE are case insensitive
A small problem (java date type stored in oracle Database)
Reply: Sorry, java. SQL. date () must be used somewhere. It seems that values can be set directly when Hibernate is used. Now, we can only use the to_date function instead of Hibernate to change it to the following !!
Import java. util. Date; import the Date class under the util package for later use of to_date
SimpleDateFormat sdf = new SimpleDateFormat ("yy-MM-dd hh: mm: ss ");
String nowdate = sdf. format (new Date ());
System. out. println (nowdate );
SQL = "insert into tablename (colname) values (to_date ('" + nowdate + "', 'yy-MM-dd hh: mm: ss '))";
Statement.exe cute (SQL );
Oracle query statement, time range
1. if time is in the format of 'yyyy-MM-dd-hh-mm-ss, di and d2 are in the format of 'yyyy-MM-dd-hh-mm-ss. The statement can be written as follows:
SQL: = 'select * from table1 where time between d1 and d2 ';
2. if time is of the date type, it should be in the format of '2017-9-8 18:55:00 'or '08-August-12 08.50.45, di and d2 are in the format of 'yyyy-MM-dd-hh-mm-ss. The statement can be written as follows:
SQL: = 'select * from table1 where to_char (time, '| chr (39) | 'yyyy-mm-dd-hh-mm-ss' |
Chr (39) | ') between d1 and d2 ';