ORA-01810 format code appears twice solution, ora-01810 Solution

Source: Internet
Author: User

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 ';

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.