SQL statement: how to insert data of the date type in Oracle

Source: Internet
Author: User

During development, you often need to write an SQL statement to insert information into the table. If the inserted data field is of the date type, you must convert the date type to the string type and insert it into the database using SQL statements. This is the only method of my field. If you have any questions, please kindly advise!

My solution is to use the to_date () method in Oracle. For more information, see the example below.

 

Insert Date data in OracleCode  

    1. Insert into news (ID, MSG, send_time, timer)
Insert Date data code in Oracle
    1. Values (20110101, '', To_date ('2017-2-28 15:42:56', 'yyyy-mm-dd hh24: MI: ss'), sysdate );

When you insert send_time, The to_date () method is used. The preceding parameter is the string to be converted. It is of the string type, followed by the date table format, oracle parses the preceding string in the following format to generate the date type in the database.

Note: The ID field is of the number type in the database, that is, int type. MSG is of the string type, varchar2 type, send_time is of the date type, and timer is also of the date type, A function in Oracle, sysdate, is used to automatically generate the current date of the date type.

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.