MM테이블을 원본데이터로 보고
테스트로 10까지 채번하는 기준으로 잡았습니다.
뭐 꼼수죠.. ^^
WITH MM AS( SELECT 1 SN FROM DUAL UNION ALL SELECT 3 SN FROM DUAL UNION ALL SELECT 5 SN FROM DUAL UNION ALL SELECT 8 SN FROM DUAL UNION ALL SELECT 9 SN FROM DUAL ) SELECT AA.SN, AA.RN, BB.RDOM FROM ( SELECT SN, ROWNUM RN FROM ( SELECT ROWNUM SN FROM DUAL CONNECT BY LEVEL <= 10 ) SS WHERE NOT EXISTS (SELECT SN FROM MM WHERE SN=SS.SN ) ) AA , (SELECT ROUND(DBMS_RANDOM.VALUE(1, (SELECT 10-COUNT(*) FROM MM))) RDOM FROM DUAL ) BB WHERE AA.RN = BB.RDOM ;