日期:2014-05-17 浏览次数:20892 次
WITH T AS( SELECT '1' A,'2' B,'3' C,'4' D,'5' E FROM dual UNION ALL SELECT '21', '2', '3', '4', '5' FROM dual UNION ALL SELECT '1', '2', '3', NULL, NULL FROM dual UNION ALL SELECT '1', '2', NULL, NULL, NULL FROM dual UNION ALL SELECT '2', '1', '3', '4', '5' FROM dual UNION ALL SELECT '2', '1', '3', '4', NULL FROM dual ) SELECT * FROM (SELECT '@'||RTRIM(NVL2(A,A,'')||'@'||NVL2(B,B,'')||'@'||NVL2(C,C,'')||'@'||NVL2(D,D,'')||'@'||NVL2(E,E,''),'@')||'@' ALLSTR,A,B,C,D,E FROM T) T1, (SELECT '@'||RTRIM(NVL2(A,A,'')||'@'||NVL2(B,B,'')||'@'||NVL2(C,C,'')||'@'||NVL2(D,D,'')||'@'||NVL2(E,E,''),'@')||'@' ALLSTR FROM T) T2 WHERE T1.ALLSTR <> T2.ALLSTR AND INSTR(T2.ALLSTR,T1.ALLSTR) = 1 ;
------解决方案--------------------
WITH T AS( SELECT '1' A,'2' B,'3' C,'4' D,'5' E FROM dual UNION ALL SELECT '21', '2', '3', '4', '5' FROM dual UNION ALL SELECT '1', '2', '3', NULL, NULL FROM dual UNION ALL SELECT '1', '2', NULL, NULL, NULL FROM dual UNION ALL SELECT '1', NULL, NULL, '4', NULL FROM dual UNION ALL SELECT '2', '1', '3', '4', '5' FROM dual UNION ALL SELECT '2', '1', '3', '4', NULL FROM dual ) SELECT * FROM (SELECT '@'||RTRIM(NVL2(A,A,'(.*)')||'@'||NVL2(B,B,'(.*)')||'@'||NVL2(C,C,'(.*)')||'@'||NVL2(D,D,'(.*)')||'@'||NVL2(E,E,'(.*)'),'@')||'@' ALLSTR,A,B,C,D,E FROM T) T1, (SELECT '@'||RTRIM(NVL2(A,A,'')||'@'||NVL2(B,B,'')||'@'||NVL2(C,C,'')||'@'||NVL2(D,D,'')||'@'||NVL2(E,E,''),'@')||'@' ALLSTR FROM T) T2 WHERE T1.ALLSTR <> T2.ALLSTR AND REGEXP_LIKE(T2.ALLSTR,T1.ALLSTR) ;