当我尝试插入日期和日期时出现ORA-01843到甲骨文的时间
我有字符串格式的 A anb B
A = 14/01/2007
B = 22:10:39
我尝试插入日期和时间:
SQL = "insert into MyTbl(Tdate,Ttime) value ('" + Convert.ToDateTime(A) + "','" + Convert.ToDateTime(B) + "')";
我收到 ORA-01843 错误,我能做什么?
提前致谢
I have A anb B in String format
A = 14/01/2007
B = 22:10:39
I try to insert date and time:
SQL = "insert into MyTbl(Tdate,Ttime) value ('" + Convert.ToDateTime(A) + "','" + Convert.ToDateTime(B) + "')";
i got ORA-01843 error, what I can do ?
thank's in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不要使用原始 SQL 插入值。请改用参数化查询。以正常方式将字符串解析为 .NET
DateTime
(或DateTimeOffset
)和TimeSpan
值,然后使用类似以下内容:(显然要调整为您实际字段的类型。)
Don't use raw SQL to insert values. Use a parameterized query instead. Parse your strings into .NET
DateTime
(orDateTimeOffset
) andTimeSpan
values in the normal way, and then use something like:(Obviously adjust for the types of your actual fields.)
错误是由于月份引起的,请尝试:
TO_DATE(A, 'DD/MM/YYYY')
The error is due to the month, try:
TO_DATE(A, 'DD/MM/YYYY')
请记住,Oracle 没有仅时间字段。
您正在尝试将仅时间字段插入到日期时间中。我的猜测是,CLR 正在将 B 转换为 00/00/00 22:10:39,这不是有效的 Oracle 日期。例如:
无论哪种方式,Convert.ToDateTime(B) 可能都没有返回正确的结果。
另外,这个:
应该是这个:
...但我猜这只是一个错字。
Remember that Oracle doesn't have a time-only field.
You're trying to insert a time-only field into a datetime. My guess is that the CLR is turning B into 00/00/00 22:10:39, which isn't a valid oracle date. For example:
Either way, Convert.ToDateTime(B) probably isn't returning the right thing.
Also, this:
should be this:
...but I'm guessing that's just a typo here.
然而我尝试了乔恩的方法,它对我来说对于日期和时间都不起作用。所以我找到了这个日期时间方法。也许这对未来的某个人也有帮助。
However i tried Jon method, it didnt work for me for date also time. So i found this method for datetime. Maybe that helps someone in next future too.