<insertid="insertOrUpdate"parameterType="ArrayList"> merge into P_MAP_TENANT_USER r using ( <foreachcollection="pMapTenantUsers"index="index"item="item"open=""close=""separator="union"> select #{item.tenantId} as TENANT_ID, #{item.userId} as USER_ID, #{item.roleType} as ROLE_TYPE from dual </foreach> )tmp on ( tmp.TENANT_ID = r.TENANT_ID and tmp.USER_ID = r.USER_ID ) when matched THEN update <set> r.ROLE_TYPE = tmp.ROLE_TYPE, </set> when not matched THEN insert <trimprefix="("suffix=")"suffixOverrides="," > TENANT_ID , USER_ID , ROLE_TYPE </trim> <trimprefix="values ("suffix=")"suffixOverrides=","> tmp.TENANT_ID, tmp.USER_ID, tmp.ROLE_TYPE </trim> </insert>