如何在Oracle中将字符串值转换为日期数据类型

huangapple go评论48阅读模式
英文:

How to convert string value in to date datattype in oracle

问题

我正在从Excel文件中获取日期值,例如 '2015.08','2015.09' 等。我正在使用C#代码读取这些Excel文件,现在我想将它们插入到包含数据类型 DATE 的Oracle表中的 manufacturedate 字段中。我如何将值 '2015.08' 转换为Oracle数据类型 'DATE'?

英文:

I am getting date value from excel file as '2015.08',2015.09 etc.I am reading these excel file by using c# code and now i want to insert in to oracle table contains field 'manufacturedate' which of datatype DATE.How i can convert value '2015.08' in to oracle datatype 'DATE'

答案1

得分: 1

你应该在你的代码中执行这部分,并将它传递到数据库作为日期。

DateTime oDate = DateTime.ParseExact(iString, "yyyy.MM", null);

或者你可以在数据库层面进行转换(但不应该这样做)。

insert into my_table (manufacturedate)
values (to_date(:p_not_real_date, 'yyyy.mm'))
英文:

You should do in your code, and pass it to database as date

DateTime oDate = DateTime.ParseExact(iString, "yyyy.MM",null);

Or you can convert it at db level (but shouldn't)

insert into my_table (manufacturedate)
values (to_date(:p_not_real_date, 'yyyy.mm'))

huangapple
  • 本文由 发表于 2023年3月31日 04:46:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/75892866.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定