oracle-插入到数据库中为日期

oracle中创建一个表,其中一个字段为date,当我们进行插入操作

 1 create table xf_allsalestotal
 2 (
 3    xf_txdate  date not null,
 4    xf_storecode   varchar(20) not null,
 5    xf_storename   varchar(50) not null,
 6    xf_clothes    number(16,4)  default(0),
 7    xf_craft    number(16,4) default(0) ,
 8    xf_jewelry    number(16,4) default(0),
 9    xf_totalsale  number(16,4) default(0) 
10 )

 

1 insert into xf_allsalestotal(xf_txdate,xf_storecode,xf_storename,xf_clothes,xf_craft,xf_jewelry)
2 values(sysdate,'SZ01','深圳店',1000,2000,30000);

得到的结果是这样

 如果我们不需要后面的时间只需要日期的话,一种就是通过to_char(sysdate,'YYYY/MM/DD') 编程字符串,但是在我们这个例子中

xf_txdate中date类型,显然不合适;我们采取另一种方法,直接通过trunc函数,就直接可以达到这个效果
1 insert into xf_allsalestotal(xf_txdate,xf_storecode,xf_storename,xf_clothes,xf_craft,xf_jewelry)
2 values(trunc(sysdate),'SZ01','深圳店',1000,2000,30000);

 

 

 

                                                                                                            

posted on 2017-02-06 11:52  我就要超鬼  阅读(568)  评论(0编辑  收藏  举报

导航