Home > database >  Oracle cycle insert date and date more than a record of a second
Oracle cycle insert date and date more than a record of a second

Time:09-22

Assuming that there is a table in the Oracle database, field simply
The create table Custom_Table (
User_id number primary key,
User_name varchar2 (20) not null,
User_birthday date not null
);
In each to insert a data, I ask which date column in the data to add a second, for example, I inserted in a record date is on the 2018-06-01 11:22:33, it should be in the next 2018-06-01 11:22:34

Assuming that the first record is:
Insert into Custom_Table values (1, 'Joanna, to_date (' 11:22:33 2018-06-01', '- dd yyyy - mm hh24: mi: ss'));
Add a second is: to_date (' 2018-06-01 11:22:33 ', '- dd yyyy - mm hh24: mi: ss') + 1/(24 * 60 * 60)
Put a 10 consecutive records,
What should be how to do?

CodePudding user response:

 
SQL>
SQL> The create table Custom_Table (
2 user_id number primary key,
3 user_name varchar2 (20) not null,
4 user_birthday date not null
5);
The Table created
SQL> Insert into Custom_Table values (
1, 2 'zhangsan,
3 (select NVL (Max (user_birthday) + 1/86400, the date '2018-06-02') from Custom_Table)
4);
1 row inserted
SQL> Insert into Custom_Table values (
2, 2 'lisi,
3 (select NVL (Max (user_birthday) + 1/86400, the date '2018-06-02') from Custom_Table)
4);
1 row inserted
SQL> The select user_id, user_name, to_char (user_birthday, 'yyyy - mm - dd hh24: mi: ss') x
2 the from Custom_Table;
USER_ID USER_NAME X
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
1 zhangsan 2018-06-02 00:00:00
Lisi 2018-06-02 00:00:01
SQL> Drop table Custom_Table purge;
Table dropped

SQL>
  • Related