Tuesday, 10 May 2011

Function to display Amount in Word


function XXSPELLNUMBER( p_number in number )
  return varchar2
  as
    v_to_words varchar2(20000);
  begin
SELECT  initcap(decode(sign(((trunc(p_number)) - mod(trunc(p_number),10000000)) / 10000000),
                -1, ' ',
                 0,' ',
   to_char(to_date(lpad(substr(to_char(((trunc(p_number)) - mod(trunc(p_number),10000000)) /10000000),1,4),4,'0'),'yyyy'),'YEAR') || ' CRORE ') ||
         decode(((mod(trunc(p_number), 10000000) - mod(trunc(p_number),100000)) / 100000),
                 0, '',
   to_char(to_date(lpad(substr(to_char((mod(trunc(p_number),10000000) -
  mod(trunc(p_number),100000)) /100000),1,2),4,'0'),'yyyy'),
                 'YEAR') || ' LAKH ') ||
         decode(((mod(trunc(p_number), 100000) - mod(trunc(p_number),1000)) / 1000),
                 0, '', to_char(to_date(lpad(substr(to_char((mod(trunc(p_number),100000) - mod(trunc(p_number),1000)) /
1000),1,2),4,'0'),'yyyy'),'YEAR') || ' THOUSAND ') ||
         decode(((mod(trunc(p_number), 1000) - mod(trunc(p_number),100)) /100),
                 0, '', to_char(to_date(lpad(substr(to_char
               ((mod(trunc(p_number),1000) - mod(trunc(p_number),100)) /100),1,1),4,'0'),'yyyy'),
                 'YEAR') || ' HUNDRED ') ||
         decode(((mod(trunc(p_number), 100) - mod(trunc(p_number),1)) / 1),
                 0, '', to_char(to_date(lpad(substr(to_char
               ((mod(trunc(p_number),100) - mod(trunc(p_number),1)) /1),1,2),4,'0'),'yyyy'),
                 'YEAR')) ||
    decode((p_number * 100 - trunc(p_number) * 100),0,' ',', AND PAISE '||
               to_char(to_date(lpad(substr(to_char(p_number * 100 -trunc(p_number) * 100),1,2),4,'0'),'yyyy'),'YEAR')
               )) || ' only ' final
 INTO v_to_words
 FROM dual;
 return (v_to_words);
 end;

No comments:

Post a Comment