Oracle, Web, Script, SQLserver, Tips & Trick

February 7, 2014

Decimal with comma (,) or dot (.) conversion to number Oracle

Filed under: oracle — sikathabis @ 9:17 am
Tags: ,

/** source code **/

Create or Replace FUNCTION RET_NUMBER (ntext VARCHAR2) RETURN number IS
vnum number;
c number(1);
s varchar2(1):=null;
begin
–cari karakter desimal dulu
select instr(ntext,’,’) into c    from dual;
if c = 0 then
select instr(ntext,’.’) into c from dual;
end if;
–jika ketemu ambil karakternya
if c > 0 then
s:= substr(ntext,c,1);
end if;
begin
select to_number(ntext) into vnum from dual;
exception when others then
begin
–jika error maka replace karakternya dari . menjadi , atau sebaliknya
select to_number(replace(ntext,s,decode(s,’,’,’.’,’,’))) into vnum from dual;
exception when others then
–jika masih salah maka munculkan error
RAISE_APPLICATION_ERROR(-20001, ‘Error konversi number ‘||ntext||’, cek BARIS KE atau kolom angka’);
end;
end;
return vnum;
end;

/** example **/

select ‘number with dot=’|| ret_number(‘500.1′) ||’, number with coma ‘ || ret_number(‘252,25’) from dual;

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

Create a free website or 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: