Wednesday, September 10, 2008

PL/SQL digits to words in Lithuanian

A PL/SQL function to convert numbers to words in Lithuanian, may be adjusted to your language rules. Maximum number 999999,99; decimal sign is ",". Execution example:

select EBA_OLS_DIG_TO_WORD('Lt 999999,99') from dual;

Result:

devyni šimtai devyniasdešimt devyni tūkstančiai devyni šimtai devyniasdešimt devyni Lt. 99 ct.

Code:

create or replace function "EBA_OLS_DIG_TO_WORD"
(num in VARCHAR2)
return VARCHAR2
is
word VARCHAR2(1022); -- result variable
work VARCHAR2(20); -- given number converted to char
k NUMBER := 0; -- length
n1 VARCHAR2(20) := 'vienas'; -- digits
n2 VARCHAR2(20) := 'du';
n3 VARCHAR2(20) := 'trys';
n4 VARCHAR2(20) := 'keturi';
n5 VARCHAR2(20) := 'penki';
n6 VARCHAR2(20) := 'šeši';
n7 VARCHAR2(20) := 'septyni';
n8 VARCHAR2(20) := 'aštuoni';
n9 VARCHAR2(20) := 'devyni';
n0 VARCHAR2(20) := 'dešimt'; -- tens and thousands
nh VARCHAR2(20) := 'šimtas';
nhd VARCHAR2(20) := 'šimtai';
nt VARCHAR2(20) := 'tūkstantis';
ntd VARCHAR2(20) := 'tūkstančiai';
ntu VARCHAR2(20) := 'tūkstančių';
ty VARCHAR2(20) := 'asdešimt'; -- endings
c VARCHAR2(1); -- loop digit value
d VARCHAR2(1); -- 4th digit in 5 digit number (for ...teen numbers)
n NUMBER := 0; -- number variable, for other use cases
suf VARCHAR2(6) := ''; -- suffix value for cents (hundreds of money)
skip4 BOOLEAN := false; -- flag for skipping 4th digit in 5 digit number
BEGIN
work := substr(num,4); -- prefix "LT_" (3 digits, adjust if needed)
k := length(work); -- length
n := instr(work,','); -- looking for decimal
if (n > 0) then
suf := substr(work, n+1, k-n+1); -- reading cents
if (length(suf)=1) then -- ,8 to ,80 correction
suf:=suf'0';
end if;
work := substr(work, 1, n-1); -- number corection, skipping cents
k := length(work); -- length adjustment
end if;
FOR i IN 1..k -- loop
LOOP
c:=substr(work,i,1); -- next digit
if (skip4 = false) then -- skip this part for 4th digit in 5 digit number
case c
when '1' then if ((k-i+1 != 2)and(k-i+1 != 5)and(skip4 = false)) then word:=wordn1; end if;
when '2' then if ((k-i+1 != 2)and(k-i+1 != 5)) then word:=wordn2; else word:=word'dvi'; end if;
when '3' then if ((k-i+1 != 2)and(k-i+1 != 5)) then word:=wordn3; end if;
when '4' then word:=wordn4; -- gramma mess with 1,2 and 3 digits
when '5' then word:=wordn5;
when '6' then word:=wordn6;
when '7' then word:=wordn7;
when '8' then word:=wordn8;
when '9' then word:=wordn9;
--when '0' then word:=wordn0;
else null;
end case;
end if;
word:=word' '; -- space btw words

case (k-i+1) -- lets take a digits position
when 6 then begin -- X*****
if (c = 1) then -- singular
word:=wordnh' ';
elsif (c = 0) then -- nothing
null;
else
word:=wordnhd' '; -- plural
end if;
end;
when 5 then begin -- *X**** (difficult digit, may have teen numbers)
if (c = 1) then -- if its teen number (1*)
d := substr(work,i+1,1); -- next digit in teen numbers
case d
when '0' then word:=wordn0;
when '1' then word:=word'vienuolika';
when '2' then word:=word'dvylika';
when '3' then word:=word'trylika';
when '4' then word:=word'keturiolika';
when '5' then word:=word'penkiolika';
when '6' then word:=word'šešiolika';
when '7' then word:=word'septyniolika';
when '8' then word:=word'aštuoniolika';
when '9' then word:=word'devyniolika';
else null;
end case;
skip4:=true; -- skip 4th digit on the next loop
--exit; -- dont exit the loop
elsif (c = 0) then -- if its zero, do nothing
null;
elsif (c = 2) then -- gramma for "2*"
word:=trim(word);
word:=wordn0' ';
elsif (c = 3) then -- gramma for "3*"
word:=word'tris'n0' ';
else -- default thounsands
word:=trim(word);
word:=wordty' ';
end if;
end;
when 4 then begin -- **X***
if (skip4=true) then -- plural on teen numbers in 5th & 4th place
word:=wordntu' ';
elsif (c = 1) then -- singular
word:=wordnt' ';
elsif (c = 0) then -- plural
word:=wordntu' ';
else -- plural
word:=wordntd' ';
end if;
skip4:=false; -- stop skipping 4th digit
end;
when 3 then begin -- ***X**
if (c = 1) then -- singular
word:=wordnh' ';
elsif (c = 0) then -- nothing
null;
else -- plural
word:=wordnhd' ';
end if;
end;
when 2 then begin -- ****X* (same problem as with 5th digit)
if (c = 1) then -- if its teen number (1*)
d := substr(work,i+1,1); -- next digit in teen numbers
case d
when '0' then word:=wordn0;
when '1' then word:=word'vienuolika';
when '2' then word:=word'dvylika';
when '3' then word:=word'trylika';
when '4' then word:=word'keturiolika';
when '5' then word:=word'penkiolika';
when '6' then word:=word'šešiolika';
when '7' then word:=word'septyniolika';
when '8' then word:=word'aštuoniolika';
when '9' then word:=word'devyniolika';
else null;
end case;
exit; -- no more digits left, exit loop
elsif (c = 0) then -- nothing
null;
elsif (c = 2) then -- gramma with "2*"
word:=trim(word);
word:=wordn0' ';
elsif (c = 3) then -- gramma with "3*"
word:=word'tris'n0' ';
else
word:=trim(word); -- others
word:=wordty' ';
end if;
end;
else null;
end case;
END LOOP;
word:=word' Lt.'; -- add currency if needed
if (n > 0) then -- condition for suffix numbers
--word:=word' 'EBA_OLS_DIG_TO_WORD('ct 'suf)' ct.'; -- convert cents to words if preffered
word:=word' 'suf' ct.'; -- dont convert cents
end if;
return word; -- return
END;

Wednesday, September 3, 2008

Chrome vs Apex: old issues

When first popular Oracle ApEx versions (like 1.6, 2.0) came out, they had problems with displaying SQL Workshop Object Browser windows on some FF versions, just dont remember which exactly (imho 2.2). Here we are again having the same problem: red screen. This time its new Google browser Chrome. The same problem can be found on ApEx versions 3.0, 3.1 and 3.1.2, havent tested this on others. The common solution back then was to add a few directives to Oracle HTTP_Server's configuration file httpd.conf:
AddType text/xml xbl
AddType text/x-component htc
No luck this time. Anyway, Chrome is just beta, hoping to have a better functionality soon.

Chrome myth

Just downloaded new fancy G browser Chrome. It actualy uses more memory than FF does. Chrome just divides it between processess. My FF has 48 tabs opened, it uses 148M RAM, get your calculator and calc this image below, only 24 tabs...

Thursday, June 19, 2008

Life v 1.1


Im a glider pilot now. Wohooooo. Yesterday received the Glider Pilot license from CAA.
Next week im going to Italy, wgc2008, im going as a crew member, but maybe some day you'll see me in the grid as a pilot :)
To get the license was much easier then pass Oracle exams, someday i'll post my Oracle license in a post Life v 1.2.

Lithuania rulez

Hi guys, you know, i'm proud to be Lithuanian, because we download Firefox and we download it gooooooooooooood. When the day started, i downloaded FF3 to all my PCs in the office (7), and didnt use the same copy to install, just downloaded a new one each time. Spread the news to many of my friends in messaging lists. And when i came home, i pushed it to all my PCs at home (4).
Of course the final results look a bit unbelievable, i think its a small trick, you can write a 3 line code in shell to have a perfect downloader... I guess that some downloads from some IP addresses will be discarded. Anyways, world, can you be that cool like we are?
Anyways the FF3 isnt that good, and overall FF is not that user friendly. The best browser to work really intense is... ...Opera, the only feature that it lacks is page search toolbar the FF has. Opera has many fast tricks, like "g search", alt+space, quick dial, tabs on the side. I ussualy work with 20-30 pages, so to have the tabs on the side, its faster to find page you need. On a quick dial page i put MRTG pages of my servers. Opera is a better tool to do intensive work. The other FF problem is RAM usage... ...just checked: 114MB ram + 134MB swap. wtf ff?

Wednesday, May 7, 2008

Lost and Found

Haven't been in funeral for more than 18 years. Just successfully no one that i know died. But today i said goodbye to my ex-coworker. I young man just had a heart attack, and thats it. I was looking at him, he was like alive, his lips where smiling. He left two boys and loving wife.
When people push themselves to risk on daily basis - its not so shocking to read in newspaper that some speed junkie, hill climber, sky diver or test pilot died. But this time, i was looking at man, to whom i spoke a week ago. He was just a good father, how risky can that be? Of course, you can say thats life, well it is!
When someone close dies, it takes away your time you spent doing something together. That feels empty. And today i feel empty too. Rest happily dear friend.

Sunday, March 2, 2008

Oil change

Yo! Did an oil change today. Have you seen IT administrator doing that? Oh, what the hell, its an adventure. There is a show on Discovery - a man tries to find tough jobs and try them out. Ok. Very funny retardation. If you are normal human, you can do any job like being a soldier, builder, maker, drawer, constructor, designer, stunt man. Well you do need some knowledge, but these jobs are intuitive. Hey man, try to be a scientist, surgeon or at least an IT admin (doh). There are jobs that can be made only by trained human beings that spent 10-30 years trying to understand how stuff works.
Anyways, missed my point. So i did an oil change, hurray, one more happy milestone towards becoming a decent man. What would be the tips for the future? Well.. 1) use a bigger funnel, first flow of motor oil will need at least 2-3 cm of pipe 2) prepare more light sources 3) don't use good shoes, this rule is common to all the garage work 4) think of some tool to remove an oil filter, this time few holes and a screw driver did the job 5) get some beer with you ;) burp.
And remembering to "The Earth" theme - i went to a gas station and put used oil to special containers they have for this purpose.