oracle插入,更新自動設定當前時間

2022-07-23 17:57:16 字數 536 閱讀 6019

1.建表語句

create table userinfo(

id varchar2(32) not null primary key,

name varchar2(200) ,

age int ,

create_time date default sysdate,

modify_time date default sysdate

)

insert 時可以自動更新 create_time 字段,update時需要設定觸發器,才能自動更新時間。

2.利用觸發器設定更新時間

create or replace trigger userinfo_trigger

before update on userinfo for each row

begin

:new.modify_time := sysdate;

end;

userinfo:是表名

modify_time:執行update需要自動更新的字段

ORACLE 資料插入或者更新

在寫入資料的時候有時候需要根據資料庫中是否含有該條資料來判斷資料是插入還是更新,以下為oracle插入更新語法 單條資料錄入 select sys seq.nextval as id from dual merge into sys token a using select as id,as use...

MySQL 自動插入 更新時間戳

在 mysql 中,要做到自動出入當前時間戳,只要在定義 時將字段的預設值設定為current timestamp 即可。如 create table if not exists my table creation date datetime default current timestamp ot...

ORACLE自動插入當前時間

oracle沒有date 函式,sysdate函式的值是包括時分秒的,要實現插入當前時間預設值還真麻煩.只好自己寫儲存過程,而字段預設值裡面又不能呼叫儲存過程,還得寫個觸發器 而儲存過程裡面取出來的sysdate前幾位的只卻變成17 11月 07的格式了,不是自己想要的,2007 11 17的格式,...