我表中的日期存储为十进制年份。一个示例2003.024658翻译为January 9, 2003。 我想将十进制年份转换为Oracle的日期格式。
2003.024658
January 9, 2003
我找到了在Excel中完成此操作的人:十进制的年初至今公式?
=DATE(INT(B1),1,MOD(B1,1)*(DATE(INT(B1)+1,1,1)-DATE(INT(B1),1,1)))
但是,我不太清楚如何将逻辑转换为Oracle PL / SQL。
如果您假设小数部分是根据给 定年份中的天数 (即365或366,取决于是否是leap年)来计算的,则可以执行以下操作:
with q1 as (select 2003.024658 d from dual) ,q2 as (select d ,mod(d,1) as decimal_portion ,to_date(to_char(d,'0000')||'0101','YYYYMMDD') as jan01 from q1) ,q3 as (select q2.* ,add_months(jan01,12)-jan01 as days_in_year from q2) select d ,decimal_portion * days_in_year as days ,jan01 + (decimal_portion * days_in_year) as result from q3; d: 2003.024658 days: 9.00017 result: 10-JAN-2003 12:00am