您能帮我在 Oracle 中仅将作为 VARCHAR2 参数发送到过程的时间 (hh:mi) 插入到 DATE 字段中吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1027718/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can you help me in Oracle to insert only time (hh:mi) sent as VARCHAR2 parameter to a procedure into a DATE field?
提问by
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).
在编写程序时,我被困在如何VARCHAR2
在DATE
列(必须存储我的时间以供将来参考)中插入 a (仅包含小时和分钟)。
回答by akf
In your insert
statement, for your time
field, use:
在您的insert
声明中,对于您的time
领域,请使用:
to_date(yourInputParam, 'hh:mi')
回答by Jeffrey Kemp
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:00pm”),请将日期格式更改为'HH:MIpm'
.