Ext.: http://chwshuang.iteye.com/blog/933926
In development, it is often necessary to write a SQL statement to insert information into a table, insert the data if the field is a date type, you must convert the date type to a string literal in the SQL statement to insert the database. This is the only method of my field, if there is an expert please another enlighten!
My solution is to use the To_date () method in Oracle to see the following example
Inserting a date data code in Oracle
- INSERT INTO News (Id,msg,send_time,timer)
Inserting a date data code in Oracle
- VALUES (20110101,' Hello ', to_date (' 2011-2-28 15:42:56 ',' yyyy-mm-dd hh24:mi:ss '), sysdate);
When inserting a send_time, the To_date () method is used, the preceding argument is the string to be converted, is of type strings, followed by the previous date table Form, and Oracle uses the following format to parse the preceding string to generate the date type in the database.
Description: The ID field is a number type in the database, that is, type int, MSG is a string type is also a varchar2 type, Send_time is a date type, the timer is a date type, followed by a function in Oracle, Sysdate , the current date of a date type is automatically generated.
SQL statement How to insert data of date type in Oracle