简体   繁体   English

将Oracle时间戳更新为当前日期

[英]Update Oracle timestamp to current date

I have a TIMESTAMP(6) field in Oracle db. 我在Oracle db中有一个TIMESTAMP(6)字段。 Value of this field is in format 该字段的值以格式显示

DD/MM/YYYY HH:MM:SS.000000000 PM

How to update this value to the current timestamp? 如何将此值更新为当前时间戳?

[a link to a similar question:] update date value in oracle [类似问题的链接:] 更新oracle中的日期值

I followed this link, but following query is taking very long time to execute. 我按照这个链接,但以下查询需要很长时间才能执行。

update table_name set start_time = to_char(to_date(start_time, 'yyyy/mm/dd-hh:mi:ss:ff3'), '2012/10/10-19:30:00:00') where column='Q'

A timestamp is a point in time, it has no format. 时间戳是一个时间点,它没有格式。 To update such a field to the current timestamp, use SYSTIMESTAMP or CURRENT_TIMESTAMP (respectively the date/time of the server and the date/time of the session): 要将此字段更新为当前时间戳,请使用SYSTIMESTAMPCURRENT_TIMESTAMP (分别为服务器的日期/时间和会话的日期/时间):

UPDATE your_table 
   SET your_column = systimestamp
 WHERE ...

If the query takes an abnormal amount of time (much longer than a comparable SELECT with the same WHERE clause), the mostly likely causes are: 如果查询花费了异常的时间(比具有相同WHERE子句的类似SELECT长得多),最可能的原因是:

  1. The rows that your are updating are locked by another session (doing a SELECT FOR UPDATE NOWAIT on these rows will make sure that you have the lock). 您正在更新的行被另一个会话锁定(在这些行上执行SELECT FOR UPDATE NOWAIT将确保拥有锁)。
  2. You have triggers that perform additional work, 你有触发器执行额外的工作,
  3. You're updating a column referenced by a non-indexed foreign key. 您正在更新由非索引外键引用的列。

Why you don't just 为什么你不这样做

update table_name 
set start_date = systimestamp 
where column='Q'

If you suspect there are locks on the table, there are some tables to check: dba_locks , v$session , v$session_blockers etc. These are useful when a user blocked something with an accidental update without a commit or rollback , but you should be able to see if can exists blocking locks from the architecture of your application. 如果您怀疑表上有锁,则需要检查一些表: dba_locksv$sessionv$session_blockers等。当用户在没有commitrollback情况下阻止某些意外update时,这些表非常有用,但您应该是能够查看是否存在阻止来自应用程序体系结构的锁定。 You should just simulate on paper all the scenarios. 你应该在纸上模拟所有场景。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM