17,131
社区成员
发帖
与我相关
我的任务
分享
select myseq.nextval from user_objects 这样一下子就会用 count(*) 这么多个。
-- 4551552,下个就成了4552838
-- 这样解决就是通的。
[/quote]
结贴喽,可以确定是merge into 语句的问题了,如下这么写是有问题的:
<insert id="updateOrInsertTableName" parameterClass="HashMap">
<![CDATA[
merge into tablename using
(select count(*) count from tablename where condition1) numcount
on (numcount.count <> 0)
when matched then
UPDATE SET A=A+1 WHERE condition2
when not matched then
INSERT (ID,A,B,C,D)
VALUES(tablename_SEQUENCE.NEXTVAL, #a#, #b#, #c#, #d# )
]]>
</insert>
正确的写法是这样:
<insert id="updateOrInsertTableName" parameterClass="HashMap">
<selectKey resultClass="java.lang.Long" keyProperty="tableid">
<![CDATA[select tablename_SEQUENCE.NEXTVAL as tableid from dual]]>
</selectKey>
<![CDATA[
merge into tablename using
(select count(*) count from tablename where condition1) numcount
on (numcount.count <> 0)
when matched then
UPDATE SET A=A+1 WHERE condition2
when not matched then
INSERT (ID,A,B,C,D)
VALUES(tablename_SEQUENCE.NEXTVAL, #a#, #b#, #c#, #d# )
]]>
</insert>
虽然还不是很清楚,为什么第一种写法会造成那样的现象。。。
select myseq.nextval from user_objects 这样一下子就会用 count(*) 这么多个。
-- 4551552,下个就成了4552838
-- 这样解决就是通的。
select sequence_name, increment_by from user_sequences
-- 看看
create sequence t1;
create sequence t2;
select t1.nextval,t2.nextval from dual;
select t2.nextval from dual;
select t1.nextval from dual;
select t1.nextval,t2.nextval from dual;
select t1.nextval from dual;
select t2.nextval from dual;
看看就了解了。