表:userlogin_his
字段:usrname nvarchar2(10),logintime timestamp(6)
1 --insert records 2 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')); 3 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')); 4 insert into userlogin_his(usrname,logintime) values('test2',systimestamp); 5 insert into userlogin_his(usrname,logintime) values('test3',sysdate); 6 7 --query records 8 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行代码是最简洁明了的。推荐采用。