oracle创建主键自增可以采取两种方式
方式一:创建序列
create sequence OCR_TEMPLATE_seq --序列名
increment by 1 --自增基数
start with 1 --从1开始自增
nomaxvalue --无最大值
nominvalue --无最小值
nocycle --累加 不循环
nocache; --无缓存
方式二:创建触发器
create or replace trigger OCR_TEMPLATE_seq
before insert on OCR_TEMPLATE for each row
begin
select OCR_TEMPLATE_seq.nextval into :new.id from dual;
end;
对应的mybatisMapper
<insert id="insertSelective" parameterType="test.model.OcrTemplate">
<!--@mbg.generated-->
<selectKey keyProperty="id" resultType="java.math.BigDecimal" order="BEFORE">
SELECT OCR_TEMPLATE_SEQ.NEXTVAL
FROM DUAL
</selectKey>
insert into OCR_TEMPLATE
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="ocrCode != null and ocrCode != ''">
OCR_CODE,
</if>
<if test="ocrTemplateName != null and ocrTemplateName != ''">
OCR_TEMPLATE_NAME,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="ocrCode != null and ocrCode != ''">
#{ocrCode,jdbcType=VARCHAR},
</if>
<if test="ocrTemplateName != null and ocrTemplateName != ''">
#{ocrTemplateName,jdbcType=VARCHAR},
</if>
</trim>
</insert>