1、navicate建表
//T_USER表建立序列T_USER_SQ
CREATE SEQUENCE T_USER_SQ INCREMENT BY 1 NOMAXVALUE NOCYCLE CACHE 10;
//语句 select T_USER_SQ.nextval from dual insert into T_USER(USER_ID,USER_NAME,USER_AGE) values(T_USER_SQ.nextval,'zhangjinjie','20');
2、mybatis写法
<insert id="addNote" parameterType="com.sunyard.bigdata.pojo.Note"> <selectKey keyProperty="userId" resultType="int" order="BEFORE"> select T_USER_SQ.nextval from dual </selectKey> insert into T_USER(USER_ID,USER_NAME,USER_AGE) values(#{userId},#{userName},#{userAge}) </insert> <insert id="addNote1" parameterType="com.sunyard.bigdata.pojo.Note"> <selectKey keyProperty="userId" resultType="int" order="AFTER"> select T_USER_SQ.CURRVAL AS USER_ID from dual </selectKey> insert into T_USER(USER_ID,USER_NAME,USER_AGE) values(T_USER_SQ.NEXTVAL,#{userName},#{userAge}) </insert>