CREATE OR REPLACE FUNCTION F_WORDS_USD( p_number IN NUMBER) RETURN VARCHAR2 AS TYPE myArray IS TABLE OF VARCHAR2 (255); l_str myArray := myArray ('', 'thousand', 'million', 'billion', 'trillion', 'quadrillion', 'quintillion', 'sextillion', 'septillion', 'octillion', 'nonillion', 'decillion', 'undecillion', 'duodecillion'); l_num VARCHAR2 (50) DEFAULT TRUNC (p_number); l_return VARCHAR2 (4000); l_decimal NUMBER ; l_return_decimal VARCHAR2 (4000); BEGIN SELECT (CAST(p_number AS DECIMAL(38,2))-l_num) INTO l_decimal FROM dual; FOR i IN 1 .. l_str.COUNT LOOP EXIT WHEN l_num IS NULL; IF (SUBSTR (l_num, LENGTH (l_num) - 2, 3) <> 0) THEN l_return := TO_CHAR (TO_DATE (SUBSTR (l_num, LENGTH (l_num) - 2, 3), 'J'), 'Jsp') || ' ' || l_str (i) || CASE WHEN i!=1 THEN ' ' ELSE '' END || l_return; END IF; l_num := SUBSTR (l_num, 1, LENGTH (l_num) - 3); END LOOP; IF l_return IS NOT NULL THEN l_return := l_return || ' US Dollar '; END IF; -- IF l_decimal !=0 THEN l_decimal := l_decimal *100; IF (SUBSTR (l_decimal, LENGTH (l_decimal) - 2, 3) <> 0) THEN l_return_decimal := TO_CHAR (TO_DATE (SUBSTR (l_decimal, LENGTH (l_decimal) - 2, 3), 'J'), 'Jsp'); END IF; l_return := l_return || ' and ' || l_return_decimal || ' Cents '; END IF; IF l_return IS NOT NULL THEN l_return :=l_return || 'Only'; END IF; RETURN l_return; END; Convert the above function in postgress