Oracle date insertion

Source: Internet
Author: User

Oracle date insertion
How to insert data of the date and time type in Oracle:
Create table t (mydate date );
SQL> insert into t values (to_date ('2017-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
-------------------
12:20:33

SQL> insert into t values (to_date ('2017-1-30 ', 'yyyy-MM-DD HH24: MI '));
One row has been created.
SQL> select to_char (mydate, 'yyyy-MM-DD HH24: MI: ss') from t;

TO_CHAR (MYDATE, 'yyy
-------------------
12:20:33
12:20:00

SQL> insert into t values (to_date ('1970-1-30 13 ', 'yyyy-MM-DD hh24 '));
One row has been created.

SQL> select to_char (mydate, 'yyyy-MM-DD HH24: MI: ss') from t;

TO_CHAR (MYDATE, 'yyy
-------------------
12:20:33
12:20:00
13:00:00

SQL> insert into t values (to_date ('2017-1-30 ', 'yyyy-MM-DD '));

One row has been created.

SQL> select to_char (mydate, 'yyyy-MM-DD HH24: MI: ss') from t;

TO_CHAR (MYDATE, 'yyy
-------------------
12:20:33
12:20:00
13:00:00
00:00:00

SQL> insert into t values (to_date ('1970-1 ', 'yyyy-mm '));

One row has been created.

SQL> select to_char (mydate, 'yyyy-MM-DD HH24: MI: ss') from t;

TO_CHAR (MYDATE, 'yyy
-------------------
12:20:33
12:20:00
13:00:00
00:00:00
00:00:00

SQL> insert into t values (to_date ('201312', 'yyyy '));

One row has been created.

SQL> select to_char (mydate, 'yyyy-MM-DD HH24: MI: ss') from t;

TO_CHAR (MYDATE, 'yyy
-------------------
12:20:33
12:20:00
13:00:00
00:00:00
00:00:00
00:00:00

You have selected 6 rows.
When the input parameters corresponding to HH, MI, and SS are omitted, Oracle uses 00 as the DEFAULT value.
If the input date data ignores the time part, Oracle sets the hour, minute, and second part to 0, that is, it will take the whole day.
Similarly, if the DD parameter is ignored, Oracle uses 1 as the default value of the day, that is, it takes the entire month.
However, the strange thing is that the select * from t is used to query the information of the year, month, and day, but the data in the hour and minute cannot be seen, but from the data above, it should be there. Please click it with a high finger.
SQL> select * from t;
MYDATE
--------------
30-1 month-15
30-1 month-15
30-1 month-15
30-1 month-15
01-1 month-15
01-1 month-15
You have selected 6 rows.
And use select to_char (mydate, 'yyyy-MM-DD HH24: MI: ss') from t; format only
TO_CHAR (MYDATE, 'yyy
-------------------
12:20:33
12:20:00
13:00:00
00:00:00
00:00:00
00:00:00

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.