数据库添加自增序列

1.在数据库添加自增序列
CREATE SEQUENCE "LCM"."TOPICSTAT_ID" MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 242 NOCACHE NOORDER NOCYCLE NOPARTITION ;

2.引用自增序列
CREATE TABLE "LCM"."TOPICSTAT"
( "ID" NUMBER NOT NULL ENABLE,
"VIN" NVARCHAR2(100) NOT NULL ENABLE,
"LANG" NVARCHAR2(100) NOT NULL ENABLE,
"NO" NVARCHAR2(100) NOT NULL ENABLE,
"COUNTTIME" DATE NOT NULL ENABLE
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "USERS" ;

COMMENT ON COLUMN "LCM"."TOPICSTAT"."COUNTTIME" IS '点击时间';

3.插入数据
String sql = "insert into TOPICSTAT values(TOPICSTAT_ID.nextval,'"+vin+"','"+lang+"','"+page+"',to_date('"+countTime+"','yyyy-mm-dd hh24:mi:ss'))";

你可能感兴趣的:(数据库添加自增序列)