CREATE OR REPLACE FUNCTION Xx_Num_Convert_Words(no IN NUMBER,Curr IN CHAR,mincurr IN CHAR) RETURN CHAR AUTHID CURRENT_USER IS
word VARCHAR2(300);
no1 VARCHAR2(30);
no2 VARCHAR2(30);
BEGIN
no1 := TO_CHAR(ROUND(no,2));
no2 := TO_CHAR(TRUNC(ROUND(no,2)));
SELECT
DECODE(GREATEST(no,1),no,(DECODE(SIGN(no-TRUNC(no)),0,DECODE(SIGN(LENGTH(no1)-6),-1,Curr||' '||TO_CHAR(TO_DATE(no1,'J'),'JSP'),
DECODE(SIGN(LENGTH(no1)-8),-1,Curr||' '||TO_CHAR(TO_DATE(SUBSTR(no1,-1*LENGTH(no1),LENGTH(no1)-5),'J'),'JSP')||
' LAKHS '||DECODE(SIGN(SUBSTR(no1,-5)),1,TO_CHAR(TO_DATE(SUBSTR(no1,-5),'J'),'JSP')),
Curr||' '||TO_CHAR(TO_DATE(SUBSTR(no1,-1*LENGTH(no1),LENGTH(no1)-7),'J'),'JSP')||' CRORES '||
DECODE(SIGN(SUBSTR(no1,-7,2)),1,TO_CHAR(TO_DATE(SUBSTR(no1,-7,2),'J'),'JSP')||' LAKHS ')||
DECODE(SIGN(SUBSTR(no1,-5)),1,TO_CHAR(TO_DATE(SUBSTR(no1,-5),'J'),'JSP')))),
/*-------------*/
DECODE(SIGN(LENGTH(no2)-6),-1,Curr||' '||TO_CHAR(TO_DATE(TRUNC(no2),'J'),'JSP'),DECODE(SIGN(LENGTH(no2)-8),-1,
Curr||' '||TO_CHAR(TO_DATE(SUBSTR(no2,-1*LENGTH(no2),LENGTH(no2)-5),'J'),'JSP')||' LAKHS '||
DECODE(SIGN(SUBSTR(no2,-5)),1,TO_CHAR(TO_DATE(SUBSTR(no2,-5),'J'),'JSP')),
Curr||' '||TO_CHAR(TO_DATE(SUBSTR(no2,-1*LENGTH(no2),LENGTH(no2)-7),'J'),'JSP')||' CRORES '||
DECODE(SIGN(SUBSTR(no2,-7,2)),1,TO_CHAR(TO_DATE(SUBSTR(no2,-7,2),'J'),'JSP')||' LAKHS ')||
DECODE(SIGN(SUBSTR(no2,-5)),1,TO_CHAR(TO_DATE(SUBSTR(no2,-5),'J'),'JSP'))))
||' and '||TO_CHAR(TO_DATE(DECODE(LENGTH(SUBSTR (no1,INSTR(no1,'.')+1,2) ), 1,
(SUBSTR(no1,INSTR(no1,'.')+1,2)*10),2,
(SUBSTR(no1,INSTR(no1,'.')+1,2) )),'J'),'JSP')||' '||mincurr)||' Only ') ,(TO_CHAR(TO_DATE(DECODE(LENGTH(SUBSTR (no1,INSTR(no1,'.')+1,2) ), 1,
(SUBSTR(no1,INSTR(no1,'.')+1,2)*10),2,
(SUBSTR(no1,INSTR(no1,'.')+1,2) )),'J'),'JSP'))||' '||mincurr||' Only ')
INTO word
FROM dual;
RETURN (INITCAP(word));
END;
To Run query:
==============
select xx_num_convert_words(:CF_QTYUSPTXAMT,'','') from dual;
====================================================================
Below Code is for all currencies
CREATE OR REPLACE FUNCTION APPS.XX_AMOUNT_IN_WORDS ( l_amt IN NUMBER, l_ccode VARCHAR2)
RETURN VARCHAR2
AS
words VARCHAR2(1000);
whole VARCHAR2(500) := NULL;
frac VARCHAR2(500) := NULL;
suffix1 VARCHAR2(20);
suffix2 VARCHAR2(20);
currency NUMBER (20,3);
code VARCHAR2(200);
c2 NUMBER;
i NUMBER;
p NUMBER;
flen NUMBER;
text VARCHAR2(30);
tl NUMBER;
tl1 NUMBER;
BEGIN
IF l_ccode IN ('BHD','KWD','OMR') THEN
text := TO_CHAR(l_amt,'99999999.999');
tl1 := 1000;
ELSE
text := TO_CHAR(l_amt,'99999999.99');
tl1 := 100;
END IF;
tl := LENGTH(text);
p := INSTR(text,'.',1,1);
tl := LENGTH(SUBSTR(text,p+1,tl));
currency := TRUNC(l_amt);
c2 := l_amt - currency;
c2 := c2 * tl1 ;
code :=UPPER(l_ccode);
BEGIN
SELECT DECODE (l_ccode,'USD', 'cents',
'GBP','pences',
'SAR', 'halalat',
'QAR','dirhams',
'AED', 'fils',
'DEM', 'pfennigs',
'EURO','euro cents',
'INR','paise',
'FRF', 'centimes',
'BHD','fils',
'KWD','fils',
'OMR','baizas')
INTO suffix2
FROM DUAL;
EXCEPTION
WHEN OTHERS THEN
RAISE;
END;
BEGIN
SELECT DECODE (l_ccode,'USD', ' US Dollars',
'BHD',' Bahraini Dinars',
'GBP',' Pounds',
'KWD',' Kuwaiti Dinars',
'SAR', ' Saudi Riyals',
'QAR',' Qatari Riyals',
'AED', ' UAE Dirhams',
'DEM', ' German Marks',
'EURO',' Euros',
'INR',' Indian Rupees',
'FRF', ' French Franks',
'OMR',' Omani Rials',
'IRR', ' Iran Rials')
INTO suffix1
FROM DUAL;
EXCEPTION
WHEN OTHERS THEN
RAISE;
END;
IF (currency + c2 = 0 ) THEN
--words :='Zero '||' and Zero '||INITCAP(suffix2)||' '||'Only';
words :='Zero ' || INITCAP(suffix1) ||' and Zero '||INITCAP(suffix2)||' '||'Only';
ELSE
words :=ap_amount_utilities_pkg.ap_convert_number(currency) ||','|| ap_amount_utilities_pkg.ap_convert_number(c2) ;
p := INSTR (words,',',1,1);
whole :=whole || SUBSTR(words,1,p-1);
frac :=frac || SUBSTR(words,p+1, LENGTH(words));
-- words := INITCAP(replace(whole,'-',' '))||' and '||
--INITCAP(frac)||' '||INITCAP(suffix2)||' '||'Only';
words := INITCAP(replace(whole,'-',' '))|| INITCAP(suffix1) ||' and '||
INITCAP(frac)||' '||INITCAP(suffix2)||' '||'Only';
END IF;
RETURN words;
EXCEPTION
WHEN OTHERS THEN
words := 'UNKNOWN CURRENCY';
RETURN words;
END XX_AMOUNT_IN_WORDS;
/
====================================================================
Below Code is for all currencies
CREATE OR REPLACE FUNCTION APPS.XX_AMOUNT_IN_WORDS ( l_amt IN NUMBER, l_ccode VARCHAR2)
RETURN VARCHAR2
AS
words VARCHAR2(1000);
whole VARCHAR2(500) := NULL;
frac VARCHAR2(500) := NULL;
suffix1 VARCHAR2(20);
suffix2 VARCHAR2(20);
currency NUMBER (20,3);
code VARCHAR2(200);
c2 NUMBER;
i NUMBER;
p NUMBER;
flen NUMBER;
text VARCHAR2(30);
tl NUMBER;
tl1 NUMBER;
BEGIN
IF l_ccode IN ('BHD','KWD','OMR') THEN
text := TO_CHAR(l_amt,'99999999.999');
tl1 := 1000;
ELSE
text := TO_CHAR(l_amt,'99999999.99');
tl1 := 100;
END IF;
tl := LENGTH(text);
p := INSTR(text,'.',1,1);
tl := LENGTH(SUBSTR(text,p+1,tl));
currency := TRUNC(l_amt);
c2 := l_amt - currency;
c2 := c2 * tl1 ;
code :=UPPER(l_ccode);
BEGIN
SELECT DECODE (l_ccode,'USD', 'cents',
'GBP','pences',
'SAR', 'halalat',
'QAR','dirhams',
'AED', 'fils',
'DEM', 'pfennigs',
'EURO','euro cents',
'INR','paise',
'FRF', 'centimes',
'BHD','fils',
'KWD','fils',
'OMR','baizas')
INTO suffix2
FROM DUAL;
EXCEPTION
WHEN OTHERS THEN
RAISE;
END;
BEGIN
SELECT DECODE (l_ccode,'USD', ' US Dollars',
'BHD',' Bahraini Dinars',
'GBP',' Pounds',
'KWD',' Kuwaiti Dinars',
'SAR', ' Saudi Riyals',
'QAR',' Qatari Riyals',
'AED', ' UAE Dirhams',
'DEM', ' German Marks',
'EURO',' Euros',
'INR',' Indian Rupees',
'FRF', ' French Franks',
'OMR',' Omani Rials',
'IRR', ' Iran Rials')
INTO suffix1
FROM DUAL;
EXCEPTION
WHEN OTHERS THEN
RAISE;
END;
IF (currency + c2 = 0 ) THEN
--words :='Zero '||' and Zero '||INITCAP(suffix2)||' '||'Only';
words :='Zero ' || INITCAP(suffix1) ||' and Zero '||INITCAP(suffix2)||' '||'Only';
ELSE
words :=ap_amount_utilities_pkg.ap_convert_number(currency) ||','|| ap_amount_utilities_pkg.ap_convert_number(c2) ;
p := INSTR (words,',',1,1);
whole :=whole || SUBSTR(words,1,p-1);
frac :=frac || SUBSTR(words,p+1, LENGTH(words));
-- words := INITCAP(replace(whole,'-',' '))||' and '||
--INITCAP(frac)||' '||INITCAP(suffix2)||' '||'Only';
words := INITCAP(replace(whole,'-',' '))|| INITCAP(suffix1) ||' and '||
INITCAP(frac)||' '||INITCAP(suffix2)||' '||'Only';
END IF;
RETURN words;
EXCEPTION
WHEN OTHERS THEN
words := 'UNKNOWN CURRENCY';
RETURN words;
END XX_AMOUNT_IN_WORDS;
/
No comments:
Post a Comment