ORA-30926: 无法在源表中获得一组稳定的行
org.springframework.jdbc.UncategorizedSQLException:
### Error updating database. Cause: java.sql.SQLException: ORA-30926: 无法在源表中获得一组稳定的行
### The error may involve package.class.method-Inline
### The error occurred while setting parameters
### SQL: MERGE INTO ...
### Cause: java.sql.SQLException: ORA-30926: 无法在源表中获得一组稳定的行
; uncategorized SQLException for SQL []; SQL state [99999]; error code [30926]; ORA-30926: 无法在源表中获得一组稳定的行
; nested exception is java.sql.SQLException: ORA-30926: 无法在源表中获得一组稳定的行
问题复现:假设ID为UUID且是主键
MERGE INTO tableName t1 USING (
SELECT
? AS ID, ? AS XUEHAO, ? AS NAME
FROM
dual UNION
SELECT
? AS ID, ? AS XUEHAO, ? AS NAME
FROM
dual UNION
SELECT
? AS ID, ? AS NAME
FROM
dual
) t2 ON ( t1.XUEHAO = t2.XUEHAO )
WHEN MATCHED THEN
UPDATE
SET t1.NAME = t2.NAME
,t1.XUEHAO = t2.XUEHAO
WHEN NOT MATCHED THEN
INSERT ( ID, XUEHAO, NAME )
VALUES
( t2.ID, t2.XUEHAO, t2.NAME )
分情况说明:
1、如果第3行和第7行的数据完全相同,只会存入一条数据
2、如果第3行和第7行的数据XUEHOA相同,会存入两条数据,如果你想让学号唯一,需加唯一索引
3、如果第3行和第7行的数据XUEHOA相同,会存入两条数据,当再次执行这条sql的时候,就会报上面的错误:> ORA-30926: unable to get a stable set of rows in the source tables
4、第11行会报错:ORA-01789: 查询块具有不正确的结果列数
5、第18行会报错:ORA-38104: 无法更新 ON 子句中引用的列: "T1"."XUEHAO"
更多推荐
所有评论(0)