问题
how can I select Julian day of year in Oracle database?
I tried: select to_char(sysdate, 'J') from dual; Which gives me the number of days since January 1, 4712 BC. But I would need the number of days since 1.1. of current year.
回答1:
If you check the TO_CHAR (datetime) documentation you get a link to "Format Models" with a comprehensive list of available formats. I guess you want this:
DDD
Day of year (1-366)
回答2:
SELECT TO_CHAR(SYSDATE, 'DDD') from DUAL;
回答3:
One way would be to use:
select sysdate - trunc(sysdate,'yyyy') from dual
'Trunc' cuts everything except the year and returns 01/01/2014, subtracted by the sysdate returns numbers of days since 1st of january.
回答4:
Use sql select trunc(sysdate)+1 - trunc(sysdate,'yyyy') from dual
. you will get an even number
来源:https://stackoverflow.com/questions/24775362/oracle-julian-day-of-year