oracle日期数据类型问题 - 我遇到错误的格式,结果表格
我需要将带日期数据类型的列设置为to_timestamp,以纠正格式,以将一些数据与合并插入声明中。
table.column = settings.data 插入值为例如:'28 .01.2022 14:07' 但是列设置为时间戳(6)格式。 因此,需要它插入:'28 .01.2022 14:07:00,000000'
DECLARE
PROCEDURE settings_import
(
in_id IN NUMBER
in_data IN TIMESTAMP
)
IS
BEGIN
MERGE INTO settings a
using (select in_id AS ID, in_data AS data from dual) b
on (a.ID = b.ID)
when not matched
then
INSERT into settings (ID, data) values (ID, data)
when matched
update set a.data = b.data
END settings_import;
BEGIN
settings_import (12, '28.01.2022 14:07');
END;
/
当我尝试此内容时,我会在该条目中获取列数据,但这是错误的:28.01.2020 22:14:07,000000 权利应为:'28 .01.2022 14:07:00,000000'
当我尝试值时(b.id,to_timestamp(b.data,'dd.mm.m.yyyy hh24:mi:mi:ss.ff') 我会收到此错误: ORA-01830:日期格式图片结束,然后再转换整个输入字符串
如何解决此问题?谢谢你!
I need to set a column with date data type TO_TIMESTAMP to correct format to insert some data with merge into declaration.
The table.column = settings.data
The insert value as example: '28.01.2022 14:07'
But column is set as TIMESTAMP(6) format.
So need this to insert as: '28.01.2022 14:07:00,000000'
DECLARE
PROCEDURE settings_import
(
in_id IN NUMBER
in_data IN TIMESTAMP
)
IS
BEGIN
MERGE INTO settings a
using (select in_id AS ID, in_data AS data from dual) b
on (a.ID = b.ID)
when not matched
then
INSERT into settings (ID, data) values (ID, data)
when matched
update set a.data = b.data
END settings_import;
BEGIN
settings_import (12, '28.01.2022 14:07');
END;
/
When I try this I get in column data this entry, but it's wrong: 28.01.2020 22:14:07,000000
right should be: '28.01.2022 14:07:00,000000'
When I try in the values (b.ID, TO_TIMESTAMP(b.data, 'DD.MM.YYYY HH24:MI:SS.FF')
I get this error: ORA-01830: date format picture ends before converting entire input string
How can I fix this? thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的代码有许多很多语法错误(缺少逗号,缺少半柱,缺少关键字,额外关键字)...如果修复了这些
错误
Timestamp
数据类型它是字符串文字。要么使用
timestamp
文字:或明确使用
to_timestamp
:如果您有表格:
两者都会给出一个带有值的表(使用
nls_timestamp_format 的代码> YYYY-MM-DD HH24:MI:SS.FF
):db< Noreferrer“>此处
Your code has many, many syntax errors (missing commas, missing semi-colons, missing keywords, extra keywords)... If you fix those then:
'28.01.2022 14:07'
is not aTIMESTAMP
data type it is a string literal.Either use a
TIMESTAMP
literal:Or explicitly use
TO_TIMESTAMP
:Which, if you have the table:
Both will give a table with the value (with the
NLS_TIMESTAMP_FORMAT
ofYYYY-MM-DD HH24:MI:SS.FF
):db<>fiddle here
我有一些语法错误,因为我想简化代码以更好地理解我的代码,对不起,请参阅下面的校正代码,该代码现在有效。
感谢PMDBA&amp; MT0!
I've had some syntax error as I wanted to simplify my code for better understanding, sorry, see below the corrected code which now works.
Thanks pmdba & MT0!