更新时间:2023-11-30 12:29:04
假设
date
,因为这是保留字date
而不是number
date
since that is a reserved worddate
rather than as a number
您可以为列定义默认值.
you can define a default value for the column.
SQL> ed
Wrote file afiedt.buf
1 create table products (
2 id number not null,
3 dt date default sysdate not null
4* )
SQL> /
Table created.
SQL>
SQL> insert into products( id ) values( 1 );
1 row created.
SQL> select * from products;
ID DT
---------- ---------
1 20-NOV-12
如果要在UPDATE
行时修改dt
列,则需要一个触发器
If you want to modify the dt
column when you UPDATE
the row, you would need a trigger
CREATE OR REPLACE TRIGGER trg_products
BEFORE INSERT OR UPDATE ON products
FOR EACH ROW
BEGIN
:new.dt := sysdate;
END;
触发器将覆盖作为dt
列的INSERT
或UPDATE
语句的一部分传递的任何值.默认值不会.
A trigger will override any value passed in as part of the INSERT
or UPDATE
statement for the dt
column. A default value will not.