oracle中的minus数据比对
1、要有唯一索引或者主键作为前提,减少数据冲突的数量,如示例标红的地方:
create table Tf_f_User_Member_CRM tablespace BD_TBS_EXP_DATA parallel 20 as
SELECT /*+ parallel(c,20) */
*
FROM TF_F_USER_MEMBER_DIFF C
WHERE EXISTS (SELECT /*+ parallel(a,10) */
a.vpn_id,a.member_role_id,a.start_date
FROM ucr_group_online.TF_F_USER_MEMBER_DIFF A
WHERE A.VPN_ID = C.VPN_ID AND A.MEMBER_ROLE_ID = C.MEMBER_ROLE_ID AND A.START_DATE = C.START_DATE);
最好不要用下面的SQL语句,因为它是等值查询,会发生笛卡尔积,导致数据成倍的增长,最终结果不准确:
create table Tf_f_User_Member_diff1 tablespace BD_TBS_EXP_DATA parallel 20 as
SELECT /*+ parallel(c,20) */ /*+ parallel(a,20) */
c.*
FROM TF_F_USER_MEMBER_DIFF C, UCR_GROUP_ONLINE.TF_F_USER_MEMBER_DIFF A
WHERE A.VPN_ID = C.VPN_ID AND A.MEMBER_ROLE_ID = C.MEMBER_ROLE_ID AND A.START_DATE = C.START_DATE;
create table Tf_f_User_Member_CRM tablespace BD_TBS_EXP_DATA parallel 20 as
SELECT /*+ parallel(c,20) */
*
FROM TF_F_USER_MEMBER_DIFF C
WHERE not EXISTS (SELECT /*+ parallel(a,10) */
a.vpn_id,a.member_role_id,a.start_date
FROM ucr_group_online.TF_F_USER_MEMBER_DIFF A
WHERE A.VPN_ID = C.VPN_ID AND A.MEMBER_ROLE_ID = C.MEMBER_ROLE_ID AND A.START_DATE = C.START_DATE);