微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

创建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的冲突!

原文地址:https://www.jb51.cc/oracle/210922.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐