在 oracle 中使用 getDate() 更新行时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11566799/
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
ERROR when using getDate() in oracle to update rows
提问by Adrian
I have a table with a column called STREAM_TIME of DATE type.
I'm trying to update all rows for that column to today's date. The database used is oracle.
我有一个表,其中有一列名为 STREAM_TIME 的 DATE 类型。
我正在尝试将该列的所有行更新为今天的日期。使用的数据库是oracle。
My query:
我的查询:
update bns_bess_messages SET stream_time=getDate();
Oracle comes back with this error:
Oracle 返回此错误:
SQL Error: ORA-00904: "GETDATE": invalid identifier
00904. 00000 - "%s: invalid identifier"
How can I update STREAM_TIME to today's date?
如何将 STREAM_TIME 更新为今天的日期?
Thanks
谢谢
回答by Andrew Logvinov
You can do it the following way:
您可以通过以下方式执行此操作:
update bns_bess_messages set stream_time = trunc(sysdate);
Or if you want to get the exact time:
或者,如果您想获得确切的时间:
update bns_bess_messages set stream_time = sysdate;
To check you can use the following query:
要检查您可以使用以下查询:
select sysdate from dual;
回答by Pranay Rana
getDate() is part of sql server function for oracle use one of below
getDate() 是 oracle 使用以下之一的 sql server 函数的一部分
make use of
利用
select current_date
from dual;
update bns_bess_messages SET stream_time=current_date
or
或者
The built-in function SYSDATE returns a DATE value containing the current date and time on your system. For example,
内置函数 SYSDATE 返回一个 DATE 值,其中包含系统上的当前日期和时间。例如,
select to_char(sysdate, 'Dy DD-Mon-YYYY HH24:MI:SS') as "Current Time"
from dual;
update bns_bess_messages SET stream_time=sysdate
回答by Holger Brandt
Oracle uses sysdate
instead of getDate()
Oracle 使用sysdate
代替getDate()
update bns_bess_messages SET stream_time=sysdate;