“PostgreSQL wiki sayfasından alınan ve özelleştirilmiş içeriktir”
Kaynak: https://wiki.postgresql.org/wiki/Numeric_to_English
CREATE OR REPLACE FUNCTION spell_numeric_value_tl(pValue numeric) RETURNS text AS $BODY$ DECLARE _lira bigint = trunc(pValue)::text; _kurus int = ((pValue - trunc(pValue)) * 100)::int; _spelledAmount text = '' ; _brokenOut int[] ; _pos integer = 0; _word text ; _tempVal int = 0 ; BEGIN -- Sayıyı 3 basamaklı maksimum değerler içeren ayrı elemanlara böler. -- 23321456 sayısı {456, 321, 23} şeklinde bir diziye dönüştürülür. WHILE _lira > 0 loop _brokenOut = array_append(_brokenOut, (_lira % 1000)::int); _lira = trunc(_lira / 1000); _pos = _pos + 1; End Loop; -- 1 ila 999 arasındaki sayıları Türkçe kelimelere dönüştürür ve ardından dizideki -- sonraki sayılar kümesine geçer. Dizi, son elemanın en yüksek değeri olduğu şekilde -- ters yüklenir. Bu, binlerce, milyonlar, milyarlar... gibi kelimelerin her 10^3'te -- bir ortaya çıkacağını varsayar. while _pos > 0 loop _tempVal = _brokenOut[_pos]; -- Diziyi doğrudan kullanmak büyük performans kaybına neden olduğu için _tempVal üzerinde çalışın. if _tempVal > 99 then IF _tempVal > 899 THEN _spelledAmount = _spelledAmount || 'DokuzYüz' ; elsif _tempVal > 799 THEN _spelledAmount = _spelledAmount || 'SekizYüz' ; elsif _tempVal > 699 THEN _spelledAmount = _spelledAmount || 'YediYüz' ; elsif _tempVal > 599 THEN _spelledAmount = _spelledAmount || 'AltıYüz' ; elsif _tempVal > 499 THEN _spelledAmount = _spelledAmount || 'BeşYüz' ; elsif _tempVal > 399 THEN _spelledAmount = _spelledAmount || 'DörtYüz' ; elsif _tempVal > 299 THEN _spelledAmount = _spelledAmount || 'ÜçYüz' ; elsif _tempVal > 199 THEN _spelledAmount = _spelledAmount || 'İkiYüz' ; elsif _tempVal > 99 THEN _spelledAmount = _spelledAmount || 'Yüz' ; end if; end if; if _tempVal % 100 = 10 THEN _spelledAmount = _spelledAmount || 'On'; elsif _tempVal % 100 = 11 THEN _spelledAmount = _spelledAmount || 'On Bir'; elsif _tempVal % 100 = 12 THEN _spelledAmount = _spelledAmount || 'On İki'; elsif _tempVal % 100 = 13 THEN _spelledAmount = _spelledAmount || 'On Üç'; elsif _tempVal % 100 = 14 THEN _spelledAmount = _spelledAmount || 'On Dört'; elsif _tempVal%100 = 15 THEN _spelledAmount = _spelledAmount || 'On Beş'; elsif _tempVal % 100 = 16 THEN _spelledAmount = _spelledAmount || 'On Altı'; elsif _tempVal % 100 = 17 THEN _spelledAmount = _spelledAmount || 'On Yedi'; elsif _tempVal % 100 = 18 THEN _spelledAmount = _spelledAmount || 'On Sekiz'; elsif _tempVal % 100 = 19 THEN _spelledAmount = _spelledAmount || 'On Dokuz'; elsif _tempVal / 10 % 10 = 2 THEN _spelledAmount = _spelledAmount || 'Yirmi'; elsif _tempVal / 10 % 10 = 3 THEN _spelledAmount = _spelledAmount || 'Otuz' ; elsif _tempVal / 10 % 10 = 4 THEN _spelledAmount = _spelledAmount || 'Kırk' ; elsif _tempVal / 10 % 10 = 5 THEN _spelledAmount = _spelledAmount || 'Elli' ; elsif _tempVal / 10 % 10 = 6 THEN _spelledAmount = _spelledAmount || 'Altmış' ; elsif _tempVal / 10 % 10 = 7 THEN _spelledAmount = _spelledAmount || 'Yetmiş' ; elsif _tempVal / 10 % 10 = 8 THEN _spelledAmount = _spelledAmount || 'Seksen' ; elsif _tempVal / 10 % 10 = 9 THEN _spelledAmount = _spelledAmount || 'Doksan' ; End if; if _tempVal % 100 < 10 or _tempVal % 100 > 20 then if _tempVal % 10 = 1 THEN _spelledAmount = _spelledAmount || 'Bir'; elsif _tempVal % 10 = 2 THEN _spelledAmount = _spelledAmount || 'İki'; elsif _tempVal % 10 = 3 THEN _spelledAmount = _spelledAmount || 'Üç'; elsif _tempVal % 10 = 4 THEN _spelledAmount = _spelledAmount || 'Dört'; elsif _tempVal % 10 = 5 THEN _spelledAmount = _spelledAmount || 'Beş'; elsif _tempVal % 10 = 6 THEN _spelledAmount = _spelledAmount || 'Altı'; elsif _tempVal % 10 = 7 THEN _spelledAmount = _spelledAmount || 'Yedi'; elsif _tempVal % 10 = 8 THEN _spelledAmount = _spelledAmount || 'Sekiz'; elsif _tempVal % 10 = 9 THEN _spelledAmount = _spelledAmount || 'Dokuz'; end if; end if; -- Dizideki elemana göre hangi kelimeyi kullanacağımıza karar verir. -- Dizi en yüksek değerli elemanın en yüksek olduğu şekilde yüklenir. -- Daha yüksek değerler için daha fazla elsif ifadesi eklemeye devam etmek yeterlidir. If _pos = 2 then _spelledAmount = _spelledAmount || 'Bin'; elsif _pos = 3 then _spelledAmount = _spelledAmount || 'Milyon'; elsif _pos = 4 then _spelledAmount = _spelledAmount || 'Milyar'; elsif _pos = 5 then _spelledAmount = _spelledAmount || 'Trilyon'; elsif _pos = 6 then _spelledAmount = _spelledAmount || 'Katrilyon'; elsif _pos = 7 then _spelledAmount = _spelledAmount || 'Kentilyon'; else _spelledAmount = _spelledAmount || ''; end if; _pos = _pos - 1; end loop; -- Fonksiyonun temel amacı çeklerde tutarı yazmaktır. -- Bunu ihtiyacınız olmayan bir şey olarak düşünebilirsiniz. if pvalue <= 0.0001 then _spelledAmount = _spelledAmount || 'Sıfır Lira '; else _spelledAmount = _spelledAmount || ' TL '; end if ; if _kurus = 0 then _spelledAmount = _spelledAmount || 'Sıfır Kuruş'; else _spelledAmount = _spelledAmount || ''; IF _kurus >= 10 and _kurus < 20 THEN _spelledAmount = _spelledAmount || 'On'; ELSE IF _kurus/10 = 2 THEN _spelledAmount = _spelledAmount || 'Yirmi'; ELSIF _kurus/10 = 3 THEN _spelledAmount = _spelledAmount || 'Otuz'; ELSIF _kurus/10 = 4 THEN _spelledAmount = _spelledAmount || 'Kırk'; ELSIF _kurus/10 = 5 THEN _spelledAmount = _spelledAmount || 'Elli'; ELSIF _kurus/10 = 6 THEN _spelledAmount = _spelledAmount || 'Altmış'; ELSIF _kurus/10 = 7 THEN _spelledAmount = _spelledAmount || 'Yetmiş'; ELSIF _kurus/10 = 8 THEN _spelledAmount = _spelledAmount || 'Seksen'; ELSIF _kurus/10 = 9 THEN _spelledAmount = _spelledAmount || 'Doksan'; END IF ; END IF ; IF _kurus%10 = 1 THEN _spelledAmount = _spelledAmount || 'Bir'; ELSIF _kurus%10 = 2 THEN _spelledAmount = _spelledAmount || 'İki'; ELSIF _kurus%10 = 3 THEN _spelledAmount = _spelledAmount || 'Üç'; ELSIF _kurus%10 = 4 THEN _spelledAmount = _spelledAmount || 'Dört'; ELSIF _kurus%10 = 5 THEN _spelledAmount = _spelledAmount || 'Beş'; ELSIF _kurus%10 = 6 THEN _spelledAmount = _spelledAmount || 'Altı'; ELSIF _kurus%10 = 7 THEN _spelledAmount = _spelledAmount || 'Yedi'; ELSIF _kurus%10 = 8 THEN _spelledAmount = _spelledAmount || 'Sekiz'; ELSIF _kurus%10 = 9 THEN _spelledAmount = _spelledAmount || 'Dokuz'; END IF ; _spelledAmount = _spelledAmount || ' Kuruş'; end if ; return _SpelledAmount; END; $BODY$ LANGUAGE 'plpgsql' VOLATILE COST 100;