oracle 將當前系統時間戳插入timestamp欄位
--insert records
insert into userlogin_his(usrname,logintime) values('test',to_timestamp(to_char(sysdate,'YYYY-MM-DD HH24:MI:SS'),'YYYY-MM-DD HH24:MI:SS'));
insert into userlogin_his(usrname,logintime) values('test1',to_timestamp(to_char(systimestamp,'YYYY-MM-DD HH24:MI:SS.FF'),'YYYY-MM-DD HH24:MI:SS.FF'));
insert into userlogin_his(usrname,logintime) values('test2',systimestamp);
insert into userlogin_his(usrname,logintime) values('test3',sysdate);
--query records
select usrname,to_char(logintime,'YYYY-MM-DD HH24:MI:SS.FF') from userlogin_his;
USRNAME TO_CHAR(LOGINTIME,'YYYY-MM-DDHH24:MI:SS.FF')
test 2017-03-30 18:09:59.000000
test1 2017-03-30 18:13:27.505000
test2 2017-03-30 18:28:16.521000
test3 2017-03-30 18:29:48.000000
從以上語句和執行結果來看,第4行程式碼是最簡潔明瞭的。推薦採用。