oracle 如何在plsql中获取当前日期时间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/53644486/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get the current date time in plsql?
提问by ktaro
My Code:
我的代码:
DECLARE
BEGIN
-- outputs 06-DEC-18
dbms_output.put_line(sysdate);
-- also outputs 18-DEC-06
dbms_output.put_line(to_date(sysdate,'yyyy-mm-dd hh24:mi:ss'));
END;
/
The output only shows the date. I want to get also the time.
输出仅显示日期。我也想得到时间。
采纳答案by Kaushik Nayak
SYSDATE
does have a time component. The first one outputs06-DEC-18
because your session's parameter NLS_DATE_FORMAT
is set to DD-MON-YY
.
SYSDATE
确实有时间成分。第一个输出06-DEC-18
是因为您的会话参数NLS_DATE_FORMAT
设置为DD-MON-YY
.
You have these options.
你有这些选择。
use TO_CHAR
用 TO_CHAR
dbms_output.put_line(TO_CHAR(SYSDATE,'yyyy-mm-dd hh24:mi:ss'));
Modify NLS_DATE_FORMAT
to show time.
修改NLS_DATE_FORMAT
以显示时间。
ALTER SESSION SET NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss';
BEGIN
dbms_output.put_line(SYSDATE);
END;
/
Or use SYSTIMESTAMP
to show higher precision of time like milliseconds.
或用于SYSTIMESTAMP
显示更高的时间精度,如毫秒。
BEGIN
dbms_output.put_line(SYSTIMESTAMP);
END;
/
回答by Mihawk
You can use SYSTIMESTAMP
您可以使用 SYSTIMESTAMP
SELECT SYSTIMESTAMP
FROM DUAL