我如何编写以下内容以便它同时适用于 SQL Server 和 Oracle(也就是说,无需注释或取消注释,具体取决于环境):
SELECT col1, col2
FROM table
WHERE -- anytime today
-- date_requested = TRUNC(SYSDATE) -- Oracle
date_requested = CONVERT(date, GETDATE()) -- SQL Server
我需要比较
date_requested
与今天的日期(没有时间)。
最佳答案
在oracle中创建一个函数getDate:
create or replace function getDate
return date is
l_sysdate date;
begin
select sysdate
into l_sysdate
from dual;
return l_sysdate;
end;
/
你可以这样使用它:
select getdate() from dual
关于sql - 在 SQL Server 和 Oracle 中获取今天日期的兼容语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36173308/