This question already has an answer here:
这个问题在这里已有答案:
- How to store only time; not date and time? 5 answers
如何只存储时间;不是日期和时间? 5个答案
While writing a procedure, I am stuck at how to insert a VARCHAR2
(which holds only hours and minutes) in a DATE
column (which has to store my time for future reference).
在编写过程时,我陷入了如何在DATE列(必须存储我的时间以供将来参考)中插入VARCHAR2(仅包含小时和分钟)的情况。
2 个解决方案
#1
If the input uses the 24-hour clock (e.g. "22:00"):
如果输入使用24小时制(例如“22:00”):
INSERT INTO desttable (thedate)
SELECT TO_DATE(thevarchar, 'HH24:MI')
FROM sourcetable;
If the input uses a 12-hour clock (e.g. "10:00pm") change the date format to 'HH:MIpm'
.
如果输入使用12小时制(例如“晚上10点”),则将日期格式更改为“HH:MIpm”。
#2
In your insert
statement, for your time
field, use:
在插入语句中,对于您的时间字段,请使用:
to_date(yourInputParam, 'hh:mi')
#1
If the input uses the 24-hour clock (e.g. "22:00"):
如果输入使用24小时制(例如“22:00”):
INSERT INTO desttable (thedate)
SELECT TO_DATE(thevarchar, 'HH24:MI')
FROM sourcetable;
If the input uses a 12-hour clock (e.g. "10:00pm") change the date format to 'HH:MIpm'
.
如果输入使用12小时制(例如“晚上10点”),则将日期格式更改为“HH:MIpm”。
#2
In your insert
statement, for your time
field, use:
在插入语句中,对于您的时间字段,请使用:
to_date(yourInputParam, 'hh:mi')