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