您能帮我在 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 18:26:13  来源:igfitidea点击:

Can you help me in Oracle to insert only time (hh:mi) sent as VARCHAR2 parameter to a procedure into a DATE field?

oracle

提问by

While writing a procedure, I am stuck at how to insert a VARCHAR2(which holds only hours and minutes) in a DATEcolumn (which has to store my time for future reference).

在编写程序时,我被困在如何VARCHAR2DATE列(必须存储我的时间以供将来参考)中插入 a (仅包含小时和分钟)。

回答by akf

In your insertstatement, for your timefield, 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'.