Convert SQL Server recursive WITH clause to Oracle 10g


Copy paste pertanyaanku di stackoverflow.

konversi query dibawah ini ke dalam bentuk Oracle

DECLARE @INPUT INT
SET     @INPUT = 12345

;
WITH ABCD(SEQ, X, Y)
AS
(
    SELECT  1, 
            @INPUT % 10,
            @INPUT / 10

    UNION ALL

    SELECT  SEQ + 1,
            Y % 10,
            Y / 10
    FROM    ABCD
    WHERE   X > 0 OR Y > 0
)
SELECT *
FROM   ABCD
ORDER BY SEQ

hasil konversinya

WITH T AS (
	SELECT	12345 COL1 
	FROM 	DUAL
)
SELECT	LEVEL SEQ,
		TRUNC((COL1 -
			POWER(10,LEVEL) * TRUNC(COL1/(POWER(10,LEVEL)))) /
			POWER(10,LEVEL-1)) X,
		TRUNC(COL1/(POWER(10,LEVEL))) Y
FROM 	T
CONNECT BY LEVEL <= LENGTH(COL1)+1

thanks to Justin Cave

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: