Bir zamanlar yazmış olduğum, firebird veritabanı üzerinde sayıları yazıya çeviren procedure.
Kullanım: SELECT p.TUTARYAZI FROM YAZIYLA(111023.03) p TUTARYAZI --------- YÜZONBİRBİNYİRMİÜÇ YTL ÜÇ YKR
Kaynak kodları…
SET TERM ^ ; CREATE PROCEDURE BASAMAKYAZI( BASAMAK Integer, RAKAM Integer ) RETURNS ( YAZI Varchar(20) ) AS BEGIN YAZI= case basamak when 1 then case rakam when 1 then 'BİR' when 2 then 'İKİ' when 3 then 'ÜÇ' when 4 then 'DÖRT' when 5 then 'BEŞ' when 6 then 'ALTI' when 7 then 'YEDİ' when 8 then 'SEKİZ' when 9 then 'DOKUZ' end when 2 then case rakam when 1 then 'ON' when 2 then 'YİRMİ' when 3 then 'OTUZ' when 4 then 'KIRK' when 5 then 'ELLİ' when 6 then 'ALTMIŞ' when 7 then 'YETMİŞ' when 8 then 'SEKSEN' when 9 then 'DOKSAN' end when 3 then case rakam when 1 then 'YÜZ' when 2 then 'İKİYÜZ' when 3 then 'ÜÇYÜZ' when 4 then 'DÖRTYÜZ' when 5 then 'BEŞYÜZ' when 6 then 'ALTIYÜZ' when 7 then 'YEDİYÜZ' when 8 then 'SEKİZYÜZ' when 9 then 'DOKUZYÜZ' end end; SUSPEND; END^ SET TERM ; ^ SET TERM ^ ; CREATE PROCEDURE YAZIYLA ( TUTAR Numeric(18,2) ) RETURNS ( TUTARYAZI Varchar(300) ) AS DECLARE VARIABLE tutarstr VARCHAR(50); DECLARE VARIABLE yazi VARCHAR(50); DECLARE VARIABLE len integer; DECLARE VARIABLE tamsayistr VARCHAR(50); DECLARE VARIABLE tamsayiuz integer; DECLARE VARIABLE kesirstr VARCHAR(2); DECLARE VARIABLE i integer; DECLARE VARIABLE rakam integer; DECLARE VARIABLE basamak integer; DECLARE VARIABLE uclubasamak integer; BEGIN tutarstr=tutar; len = 0; TUTARYAZI = ''; len= CHAR_LENGTH(tutarstr); IF (len = 0) THEN BEGIN TUTARYAZI = 'SIFIR'; END tamsayiuz = len-3; tamsayistr = SUBSTRING(tutarstr FROM 1 FOR tamsayiuz); kesirstr = SUBSTRING(tutarstr FROM len-1 FOR 2); i = 1; uclubasamak = tamsayiuz; WHILE (uclubasamak>3) DO BEGIN uclubasamak = uclubasamak-3; END -- Tam kısmı WHILE (i<=tamsayiuz) DO BEGIN rakam = SUBSTRING(tamsayistr FROM i FOR 1); basamak = tamsayiuz-i+1; IF ((tamsayiuz=1) AND rakam=0) THEN TUTARYAZI = 'SIFIR'; IF (( rakam>0 ) and (not ( tamsayiuz = 4 and basamak = 4 and rakam = 1 ))) THEN BEGIN -- 1111 EXECUTE PROCEDURE BASAMAKYAZI(:uclubasamak,:rakam) RETURNING_VALUES :YAZI; TUTARYAZI = TUTARYAZI || TRIM(YAZI); END IF ((BASAMAK=4) AND (TUTARYAZI not like '%MİLYON' and TUTARYAZI not like '%MİLYAR')) THEN TUTARYAZI = TUTARYAZI||'BİN' ; IF ((BASAMAK=7) AND ( TUTARYAZI not like '%MİLYAR' )) THEN TUTARYAZI = TUTARYAZI || 'MİLYON'; IF (BASAMAK=10) THEN TUTARYAZI = TUTARYAZI || 'MİLYAR'; i = i + 1; uclubasamak = uclubasamak - 1; IF (uclubasamak = 0) THEN uclubasamak = 3; END TUTARYAZI = TUTARYAZI||' TL '; -- Kuruş Kısmı IF (CAST (kesirstr AS INTEGER)>0) THEN BEGIN rakam = SUBSTRING(kesirstr FROM 1 FOR 1); IF ( rakam > 0 ) THEN BEGIN EXECUTE PROCEDURE BASAMAKYAZI(2,:rakam) RETURNING_VALUES :YAZI; TUTARYAZI= TUTARYAZI||TRIM(YAZI); END rakam = SUBSTRING(kesirstr FROM 2 FOR 1); IF ( rakam > 0 ) THEN BEGIN EXECUTE PROCEDURE BASAMAKYAZI(1,:rakam) RETURNING_VALUES :YAZI; TUTARYAZI= TUTARYAZI||TRIM(YAZI); END TUTARYAZI= TUTARYAZI||' KR'; END SUSPEND; END^ SET TERM ; ^