Oracle, Web, Script, SQLserver, Tips & Trick

July 26, 2016

Contoh PL/SQL pengambilan nama dari separator koma (,)

Filed under: oracle — sikathabis @ 7:59 pm
Tags: ,

Contoh:

DECLARE
KALIMAT varchar2(100):=’DD_MASTER,LN_MASTER_AUDIT,TRAN_HIST,TASPEN’;
kata varchar2(100):=null;
c number:=0;
BEGIN
FOR i in 1..length(KALIMAT)
LOOP
if substr(kalimat,i,1)=’,’ then
c:=c+1;
end if;
END LOOP;

FOR i in 1..c
LOOP
kata:= substr(KALIMAT,1,instr(KALIMAT,’,’)-1);
kalimat := replace(kalimat,kata||’,’,”);
if i=c then
dbms_output.put_line(‘kata=’||kata);
dbms_output.put_line(‘kalimat=’||kalimat);
else
dbms_output.put_line(‘kata=’||kata);
end if;
END LOOP;
END;

 

Output:

kata=DD_MASTER
kata=LN_MASTER_AUDIT
kata=TRAN_HIST
kalimat=TASPEN

Script diatas berlaku jika datanya normal, tapi apabila terdapat data null sebagai Contoh

DECLARE
KALIMAT varchar2(100):=’DD_MASTER,,TRAN_HIST,TASPEN’;
kata varchar2(100):=null;
c number:=0;
BEGIN
FOR i in 1..length(KALIMAT)
LOOP
if substr(kalimat,i,1)=’,’ then
c:=c+1;
end if;
END LOOP;

–Maka ada perubahan di script yang ditebalkan

FOR i in 1..c
LOOP
kata:= substr(KALIMAT,1,instr(KALIMAT,’,’)-1);
if kata||’,’=”||’,’ then
       kalimat := substr(kalimat,2,length(kalimat));
    else   
       kalimat := substr(kalimat,length(kata||’,’)+1,length(kalimat));
    end if;
if i=c then
dbms_output.put_line(‘kata=’||kata);
dbms_output.put_line(‘kalimat=’||kalimat);
else
dbms_output.put_line(‘kata=’||kata);
end if;
END LOOP;
END;

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

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

Blog at WordPress.com.

Teknologi Pendidikan

Just another WordPress.com weblog

KATAKAMI

Jurnalisme Yang Dapat Dipercaya

Tonk Kosonk Baonk Bunyinya

Penampungan Serapah Tanpa Sumpah

Qey050489's Blog

Ayo Bangkit sobat..!!!!!

B. S. Totoraharjo

Orang Bodoh Yang Tak Kunjung Pandai

culturekitchen foodlab

New Food and Art in Yogyakarta

Wahyu Catur Wibowo

Musafir Dunia Maya

SQL.... Still Learning

My Reference on SQL Server

neinframe

Street Photography is like a box of a chocolates, you're never know what you're gonna get - Thomas Leuthard -

Keluarga Andrivito

-- Andrivito's Journal --

DRK™

This site is about Latest NEWS, Articles, Videos, Books, Course, Presentations, Tips & Tricks related to I.T Pro's

Gaurav Saxena

|| तत् त्वम् असि ||

Be a good Moeslim

Menuju Pribadi Muslim Sejati yang Bertaqwa

TuanSUFI

Manajemen Sholat, renungan spiritual, Teknologi Informasi

Pelangi di khatulistiwa....

Mari berbagi kebaikan, pengalaman dan senyum denganku

angkasa13

Ceritanya saya, Pikirannya saya, Hatinya saya

sikathabis

sikathabis semua informasi disini

%d bloggers like this: