ORACLE/PLSQL: FOR LOOP – ORACLE FOR

FOR loop_counter IN [REVERSE] lowest_number..highest_number
LOOP
{…statements…}
END LOOP;

Something like this šŸ˜‰
————–

FOR x IN 1..7
LOOP
SELECT (CASE
WHEN TO_CHAR(DECODE(SUBSTR (MOBIL_GUN, x, 1),1,x,0)) = 1 THEN ‘ONE’
WHEN TO_CHAR(DECODE(SUBSTR (MOBIL_GUN, x, 1),1,x,0)) = 2 THEN ‘TWO’
WHEN TO_CHAR(DECODE(SUBSTR (MOBIL_GUN, x, 1),1,x,0)) = 3 THEN ‘THREE’
WHEN TO_CHAR(DECODE(SUBSTR (MOBIL_GUN, x, 1),1,x,0)) = 4 THEN ‘FOUR’
WHEN TO_CHAR(DECODE(SUBSTR (MOBIL_GUN, x, 1),1,x,0)) = 5 THEN ‘FIVE’
WHEN TO_CHAR(DECODE(SUBSTR (MOBIL_GUN, x, 1),1,x,0)) = 6 THEN ‘SIX’
END) into v_mobil
FROM DUAL;

IF(v_mobil IS NOT NULL) THEN
v_tmpMobil := v_tmpMobil|| ‘,’||v_mobil;
END IF;

END LOOP;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: