Oracle查询默认的null和更新current_timestamp

时间:2015-04-16 13:51:43

标签: sql oracle plsql oracle11g

给出以下mysql查询:

alter table foo_data
add ts timestamp NULL
default current_timestamp on update current_timestamp;

有人可以帮我写上述plsql查询的mysql查询等效内容吗?

1 个答案:

答案 0 :(得分:2)

在Oracle中,您必须使用触发器来更新更新时的时间戳。 ddl(假设你的意思是字段不为空):

alter table foo_data
add ts timestamp default systimestamp not null;

如果您需要每次更新行时更新时间戳,您必须使用如下触发器:

create trigger foo_data_update_ts_trigger
before update on foo_data
for each row
begin
    select systimestamp into :new.ts from dual;
end;
/