FUNCTION to_word_i( amount IN NUMBER)
RETURN VARCHAR2
AS
v_length INTEGER := 0;
v_num2 VARCHAR2(50) := NULL;
v_amount VARCHAR2(50) := TO_CHAR( TRUNC( amount));
v_word VARCHAR2(4000) := NULL;
v_word1 VARCHAR2(4000) := NULL;
TYPE myarray IS TABLE OF VARCHAR2(255);
v_str myarray
:= myarray(
' thousand '
, ' lakh '
, ' crore '
, ' arab '
, ' kharab '
, ' shankh ');
BEGIN
IF TO_CHAR( amount) LIKE '%.%'
THEN
IF SUBSTR( amount, INSTR( amount, '.') + 1) > 0
THEN
v_num2 := SUBSTR( amount, INSTR( amount, '.') + 1);
IF LENGTH( v_num2) < 2
THEN
v_num2 := v_num2 * 10;
END IF;
v_length := LENGTH( v_num2);
v_word1 :=
' AND '
|| (TO_CHAR( TO_DATE( SUBSTR( v_num2, LENGTH( v_num2) - 1, 2), 'j'), 'Jsp'))
|| ' paise ';
END IF;
END IF;
IF v_amount = '0'
THEN
v_word := 'zero';
ELSE
IF (SUBSTR( v_amount, LENGTH( v_amount) - 2, 3) <> 0)
THEN
v_word :=
TO_CHAR( TO_DATE( SUBSTR( v_amount, LENGTH( v_amount) - 2, 3), 'J'), 'Jsp')
|| v_word;
END IF;
v_amount := SUBSTR( v_amount, 1, LENGTH( v_amount) - 3);
FOR i IN 1 .. v_str.COUNT
LOOP
EXIT WHEN v_amount IS NULL;
IF (SUBSTR( v_amount, LENGTH( v_amount) - 1, 2) <> 0)
THEN
v_word :=
TO_CHAR( TO_DATE( SUBSTR( v_amount, LENGTH( v_amount) - 1, 2), 'J'), 'Jsp')
|| v_str( i)
|| v_word;
END IF;
v_amount := SUBSTR( v_amount, 1, LENGTH( v_amount) - 2);
END LOOP;
END IF;
v_word :=
v_word
|| ' '
|| v_word1
|| ' only ';
v_word := REPLACE( RTRIM( v_word), ' ', ' ');
v_word := REPLACE( RTRIM( v_word), '-', ' ');
RETURN INITCAP( v_word);
END to_word_i;
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.