Connected TO:
Oracle DATABASE 12c Enterprise Edition RELEASE 12.1.0.2.0 - 64bit Production
WITH the Partitioning, OLAP, Advanced Analytics AND REAL Application Testing options
SQL> WITH n AS (SELECT ROWNUM - 1 r FROM dual CONNECT BY LEVEL <= 10),
nnn AS (SELECT n1.r r1, n2.r r2, n3.r r3, n1.r * 100 + n2.r * 10 + n3.r num,
TO_CHAR((n1.r * 100 + n2.r * 10 + n3.r) * 2) num2str
FROM n n1, n n2, n n3
WHERE n1.r > 0 AND n1.r < 5 AND n1.r <> n2.r AND n2.r <> n3.r AND n1.r <> n3.r),
nnn2 AS (SELECT r1, r2, r3, num, num2str, SUBSTR(nnn.num2str, 1, 1) n2d1, SUBSTR(nnn.num2str, 2, 1) n2d2, SUBSTR(nnn.num2str, 3, 1) n2d3
FROM nnn)
SELECT *
FROM nnn2
WHERE n2d1 <> n2d2 AND n2d1 <> n2d3 AND n2d2 <> n2d3
AND (r1 + r2 + r3) = (n2d1 + n2d2 + n2d3) * 2;
R1 R2 R3 NUM NUM2STR N N N
---------- ---------- ---------- ---------- ---------------------------------------- - - -
1 0 5 105 210 2 1 0
1 5 6 156 312 3 1 2