Oracle创建带有自增序列的表和字符串转日期的问题
生活随笔
收集整理的這篇文章主要介紹了
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'), to_date(?,'YYYY-MM-dd'), ?) 不然在后臺很容易出現 java.sql.Date和java.util.Date的沖突!
總結
以上是生活随笔為你收集整理的Oracle创建带有自增序列的表和字符串转日期的问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 用Ext-4.2简单实现分页效果
- 下一篇: ext-4.2之grid的高级应用:增删