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 TO POSTGRESS FUNCTION WTHOUT ANY ERROR