CREATE OR REPLACE FUNCTION fn_money_convert(p_money IN NUMBER)
/*小写金额转化成大写(汉字)*/
RETURN VARCHAR2
IS
TYPE myarray IS TABLE OF VARCHAR2(255);
n_str myarray := myarray('壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌',
'玖', '零');
u_str myarray := myarray('分', '角', '圆', '拾', '佰', '仟', '万', '拾',
'佰', '仟', '亿', '拾', '佰', '仟');
signal VARCHAR2(2) := NULL;
cur_digit NUMBER(1) := 0;
pre_digit NUMBER(1) := 0;
str_length NUMBER(2) := 0;
w_cash VARCHAR2(20);
l_return VARCHAR2(200);
BEGIN
IF p_money < 0
THEN
signal := '负';
END IF;
w_cash := to_char(abs(p_money) * 100);
str_length := length(w_cash);
FOR i IN 1 .. str_length
LOOP
cur_digit := to_number(substr(w_cash, str_length - i + 1, 1));
IF i = 3
AND l_return IS NULL
THEN
l_return := '整';
END IF;
IF i > 2
OR cur_digit <> 0
THEN
IF cur_digit = 0
THEN
IF i = 3
OR i = 7
OR i = 11
THEN
l_return := u_str(i) || l_return;
ELSIF pre_digit <> 0
THEN
l_return := '零' || l_return;
END IF;
ELSE
l_return := n_str(cur_digit) || u_str(i) || l_return;
END IF;
END IF;
pre_digit := cur_digit;
END LOOP;
IF instr(l_return, '万', 1) - instr(l_return, '亿', 1) = 1
THEN
l_return := REPLACE(l_return, '万', NULL);
END IF;
l_return := signal || l_return;
RETURN(l_return);
END;
阅读(1177) | 评论(0) | 转发(0) |