oracle mysql的序列的新增、删除、修改及使用
序列的使用
1.序列介绍
有时候需要修改序列初始值,有以下几种方法:
CREATE SEQUENCE [ schema. ]sequence
   [ { INCREMENT BY | START WITH } integer
   | { MAXVALUE integer | NOMAXVALUE }
   | { MINVALUE integer | NOMINVALUE }
   | { CYCLE | NOCYCLE }
   | { CACHE integer | NOCACHE }
   | { ORDER | NOORDER }
   ];
ALTER SEQUENCE [ schema. ]sequence
  { INCREMENT BY integer
  | { MAXVALUE integer | NOMAXVALUE }
  | { MINVALUE integer | NOMINVALUE }
  | { CYCLE | NOCYCLE }
  | { CACHE integer | NOCACHE }
  | { ORDER | NOORDER }
  };
2)结论二:第一次NEXTVAL初始化之后才能使用CURRVAL取值;
3)结论三:可以在一条SQL语句中同时得到nextval和currval值;
4)结论四:从上面的alter sequence的语法看,可以得到这样一个结论,无法使用alter语句修改序列的当前值。
<insert id="insert" parameterType="com.test.domain.Student"
   useGeneratedKeys="true" keyProperty="Id">
	 <selectKey resultType="int" order="BEFORE" keyProperty="Id">
		select SEQ_STUDENT_ID.nextval from dual
	 </selectKey>
	insert into student
	<trim prefix="(" suffix=")" suffixOverrides=",">
		<if test="id!= null">
			ID,
		</if>
		<if test="name!= null">
			NAME,
		</if>
	</trim>
	<trim prefix="values (" suffix=")" suffixOverrides=",">
		<if test="id != null">
			#{id,jdbcType=INTEGER},
		</if>
		<if test="name != null">
			#{name,jdbcType=INTEGER},
		</if>
	</trim>
</insert>
 
                    
                 
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号