Compatible syntax for retrieving dates today in both SQL Server and Oracle

How can I write the following to make it work for both SQL Server and Oracle (that is, without the need to comment or uncomment depending on the environment):

SELECT col1, col2
FROM table
WHERE -- anytime today
    -- date_requested = TRUNC(SYSDATE) -- Oracle
    date_requested = CONVERT(date, GETDATE()) -- SQL Server

I need to compare date_requestedwith today's date (no time).

+4
source share
1 answer

create getDate function in oracle:

create or replace function getDate
return date is

  l_sysdate date;

begin

  select sysdate
    into l_sysdate
    from dual;

  return l_sysdate;

end;
/

you can use it as follows: select getdate() from dual

0
source

All Articles