且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

创建一个函数以在 oracle 中返回当前日期和时间

更新时间:2023-11-23 21:45:40

作为一个实际的函数你可以这样做:

As an actual function you could do:

create or replace function getSysdate
return date is

  l_sysdate date;

begin

  select sysdate
    into l_sysdate
    from dual;

  return l_sysdate;

end;
/

你可以在 SQLPlus 中测试如下:

Which you could test in SQLPlus as:

TEST>select getSysdate() from dual;

GETSYSDATE
----------
2010-01-04

不知道为什么你会想要这个而不是仅仅在你的代码中使用 sysdate.Oracle 日期数据类型包括时间部分.

Not sure why you would want this versus just having sysdate in your code. The Oracle date datatype includes the time portion.