Insert operation for Oracle Date

Source: Internet
Author: User

How to Insert date-time type data in Oracle, as shown in the data table below
CREATE TABLE T (mydate date);
Sql> INSERT into T values (to_date (' 2015-1-30 12:20:33 ', ' yyyy-mm-dd HH24:MI:SS '));
Sql> Select To_char (mydate, ' Yyyy-mm-dd HH24:MI:SS ') from T;

To_char (mydate, ' YYY
-------------------
2015-01-30 12:20:33

Sql> INSERT into T values (to_date (' 2015-1-30 12:20 ', ' yyyy-mm-dd hh24:mi '));
1 rows have been created.
Sql> Select To_char (mydate, ' Yyyy-mm-dd HH24:MI:SS ') from T;

To_char (mydate, ' YYY
-------------------
2015-01-30 12:20:33
2015-01-30 12:20:00

Sql> INSERT into T values (to_date (' 2015-1-30 ', ' yyyy-mm-dd HH24 '));
1 rows have been created.

Sql> Select To_char (mydate, ' Yyyy-mm-dd HH24:MI:SS ') from T;


To_char (mydate, ' YYY
-------------------
2015-01-30 12:20:33
2015-01-30 12:20:00
2015-01-30 13:00:00

Sql> INSERT into T values (to_date (' 2015-1-30 ', ' yyyy-mm-dd '));


1 rows have been created.

Sql> Select To_char (mydate, ' Yyyy-mm-dd HH24:MI:SS ') from T;

To_char (mydate, ' YYY
-------------------
2015-01-30 12:20:33
2015-01-30 12:20:00
2015-01-30 13:00:00
2015-01-30 00:00:00

Sql> INSERT into T values (to_date (' 2015-1 ', ' yyyy-mm '));

1 rows have been created.


Sql> Select To_char (mydate, ' Yyyy-mm-dd HH24:MI:SS ') from T;

To_char (mydate, ' YYY
-------------------
2015-01-30 12:20:33
2015-01-30 12:20:00
2015-01-30 13:00:00
2015-01-30 00:00:00
2015-01-01 00:00:00

Sql> INSERT into T values (to_date (' n ', ' YYYY '));

1 rows have been created.

Sql> Select To_char (mydate, ' Yyyy-mm-dd HH24:MI:SS ') from T;

To_char (mydate, ' YYY
-------------------
2015-01-30 12:20:33
2015-01-30 12:20:00
2015-01-30 13:00:00
2015-01-30 00:00:00
2015-01-01 00:00:00
2015-01-01 00:00:00

6 rows have been selected.
Oracle uses 00 as the default value when omitting input parameters corresponding to HH, MI, and SS.
If the date data entered ignores the time portion, Oracle will set the time, minute, and second portions to 0, which means rounding to day.
Similarly, when the DD parameter is omitted, Oracle takes 1 as the default value for the day, which means that it is rounded to the month.
But it is strange to use the Select *from T, just query to date of the information, the second and second data can not see, but from the above data to see should be some ah, look at the master pointing.
Sql> select * from T;
MyDate
--------------
30月-January-15
30月-January-15
30月-January-15
30月-January-15
January-January-15
January-January-15
6 rows have been selected.
Instead of using select To_char (mydate, ' Yyyy-mm-dd HH24:MI:SS ') from T;
To_char (mydate, ' YYY
-------------------
2015-01-30 12:20:33
2015-01-30 12:20:00
2015-01-30 13:00:00
2015-01-30 00:00:00
2015-01-01 00:00:00
2015-01-01 00:00:00

Insert operation for Oracle Date

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.