加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Oracle创建带有自增序列的表和字符串转日期的问题

发布时间:2020-12-12 15:28:04 所属栏目:百科 来源:网络整理
导读:创建Oracle表的sql语句如下: --创建tm_productcreate table tm_product( pid number(8) primary key not null,productId number(20) not null,productName varchar2(500) not null,price number(10) not null,upTime date not null,downTime date not null,

创建Oracle表的sql语句如下:

--创建tm_product
create table tm_product(
       pid number(8) primary key not null,productId number(20)  not null,productName varchar2(500) not null,price number(10) not null,upTime date not null,downTime date not null,remark varchar2(500)
 );
--说明
comment on table tm_product is '产品表';
comment on column tm_product.pid is '主键ID';
comment on column tm_product.productId is '产品ID';
comment on column tm_product.productName is '产品名称';
comment on column tm_product.price is '低消金额(元)';
comment on column tm_product.upTime is '上架时间';
comment on column tm_product.downTime is '下架时间';
comment on column tm_product.remark is '说明';
--创建序列
create sequence seq_tm_product
minvalue 1
nomaxvalue
start with 1
increment by 1
nocycle   --一直累加,不循环
--nocache;  --不缓存
cache 10; --缓存10条
--创建触发器,如果insert语句不指定ID自动插入增长值
CREATE OR REPLACE TRIGGER tr_tm_product
BEFORE INSERT ON tm_product FOR EACH ROW WHEN (new.pid is null)
begin
select seq_tm_product.nextval into:new.pid from dual;
end;

在这里日期转换是个问题,即在后代如何将字符串变成日期格式呢,我在sql语句做文章:
INSERT INTO tm_product(productId,productName,price,upTime,downTime,remark) VALUES (?,?,to_date(?,'YYYY-MM-dd'),?)
不然在后台很容易出现 java.sql.Date和java.util.Date的冲突!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读