반응형
WITH V1 AS
(
SELECT NULL NO FROM DUAL UNION ALL
SELECT NULL NO FROM DUAL UNION ALL
SELECT NULL NO FROM DUAL UNION ALL
SELECT NULL NO FROM DUAL UNION ALL
SELECT NULL NO FROM DUAL UNION ALL
SELECT NULL NO FROM DUAL UNION ALL
SELECT NULL NO FROM DUAL UNION ALL
SELECT NULL NO FROM DUAL UNION ALL
SELECT NULL NO FROM DUAL UNION ALL
SELECT NULL NO FROM DUAL
)
SELECT CASE WHEN RND_P = 0 THEN 0 ELSE ((V_RND - RND_P_S_L) * (1/TCNT) / RND_P) + RT_L END AS V_RND2
, A.*
FROM (
SELECT B.V_RND
, A.*
, LAG(RND_P_S,1,0) OVER (ORDER BY NO) AS RND_P_S_L
, MAX(NO) OVER () AS NO_MAX
FROM (
SELECT A.*
, SUM(RND_P) OVER (ORDER BY NO) AS RND_P_S
FROM (
SELECT A.*
, LAG(RT,1,0) OVER (ORDER BY NO) AS RT_L
, SUM(RND) OVER (ORDER BY NO) AS RND_S
, RND / SUM(RND) OVER () AS RND_P
FROM (
SELECT ROWNUM AS NO
, COUNT(*) OVER () AS TCNT
, DBMS_RANDOM.VALUE AS RND
, ROWNUM / COUNT(*) OVER () AS RT
FROM V1,V1
) A
) A
) A
, (SELECT 0.9 AS V_RND FROM DUAL) B
--WHERE A.RND_P_S <= B.V_RND
) A
--WHERE NO = NO_MAX
;
'전산Tip > Oracle' 카테고리의 다른 글
[ORACLE] 테이블 레코드값 INSERT 쿼리 자동 생성 (0) | 2011.11.18 |
---|---|
[ORACLE] 난수 생성 (0) | 2011.11.04 |
[ORACLE] 테이블스페이스 DATAFILE 확장하기 (1) | 2011.09.28 |