Oracle数据库不像MySQL一样,可以在表结构中设置id键增,但是可以通过序列+SQL来设置id键自增
- 首先,新建序列,设置id从1开始自增
序列名: SEQ_CUST_INCOME_REPORT
-- Create sequence
create sequence SEQ_CUST_INCOME_REPORT
minvalue 1
maxvalue 9999999999999999999999999999
start with 1
increment by 1
cache 100;
2,mybatis中SQL写法:
<insert id="addIncomeReport" parameterType="com.grand.incomereport.entity.CustIncome">
<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="ID">
SELECT SEQ_CUST_INCOME_REPORT.CURRVAL AS ID from DUAL
</selectKey>
INSERT INTO cust_income_report
(ID,CIS,WORKERNO,BANKNO,CREATE_TIME,INCOME_REPORT)
VALUES
(SEQ_CUST_INCOME_REPORT.NEXTVAL,
#{custIncome.cis,jdbcType=VARCHAR},
#{custIncome.workerNo,jdbcType=VARCHAR},
#{custIncome.bankNo,jdbcType=VARCHAR},
SYSDATE,
#{custIncome.incomeReport,jdbcType=VARCHAR})
</insert>
这样就会发现,每次新增操作的时候,id都是自增的了。