How to use GETDATE() in Oracle to find number of days between Current Date and some specified date? -


suppose have table called projects , has columns projectid, startdate , enddate. startdate of each project specified , enddate specified projects finished. ongoing projects, enddate null. have perform task :

find project id , duration of each project. if project has not finished, report execution time of now. [hint: getdate() gives current date]

for wrote code,

select projectid, case when enddate null getdate() - startdate else enddate - startdate end "duration" projects; 

but giving me

ora-00904: "getdate": invalid identifier 00904. 00000 -  "%s: invalid identifier" *cause:     *action: error @ line: 113 column: 27 

the line 113, column 27 position of getdate().

so way use getdate() here?

getdate() function tsql. want use instead current_date. also, improved query bit using coalesce.

select projectid, coalesce(enddate,current_date) - startdate  "duration" projects; 

you may want refine result using floor() exact days.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -