当前位置: 代码迷 >> SQL >> PL/SQL 将小写的金额变换为大写
  详细解决方案

PL/SQL 将小写的金额变换为大写

热度:75   发布时间:2016-05-05 14:58:41.0
PL/SQL 将小写的金额转换为大写

CREATE OR REPLACE FUNCTION SMALLTOBIG(SMALLMONEY IN VARCHAR2)  RETURN VARCHAR2 IS  DOTPLACE   NUMBER(2); --小数点位置  UPPERCASE  VARCHAR2(60); --大写方式  RMB        VARCHAR2(3); --RMB的单位  BIGNUM     VARCHAR2(2); --大写数字  MONEYPLACE NUMBER(2); --数字的位置  MONEYNUM   NUMBER(14); --人民币的位数  MONEYLEN   NUMBER(14); --数字位数  MYEXCEPTION EXCEPTION; --自定义异常BEGIN  /*确定小数点的位置*/  DOTPLACE := INSTR(SMALLMONEY, '.');  MONEYLEN := LENGTH(SMALLMONEY);  IF MONEYLEN > 14 OR (MONEYLEN > 12 AND DOTPLACE = 0) THEN    RAISE MYEXCEPTION; --抛出自定义异常  END IF;  /**确定人民币的精度*/  IF DOTPLACE = 0 THEN    MONEYPLACE := 0;  ELSE    MONEYPLACE := DOTPLACE - MONEYLEN;  END IF;  FOR MONEYNUM IN REVERSE 1 .. MONEYLEN LOOP    IF MONEYNUM <> DOTPLACE THEN      CASE SUBSTR(SMALLMONEY, MONEYNUM, 1)        WHEN '1' THEN          BIGNUM := '壹';        WHEN '2' THEN          BIGNUM := '贰';        WHEN '3' THEN          BIGNUM := '叁';        WHEN '4' THEN          BIGNUM := '肆';        WHEN '5' THEN          BIGNUM := '伍';        WHEN '6' THEN          BIGNUM := '陆';        WHEN '7' THEN          BIGNUM := '柒';        WHEN '8' THEN          BIGNUM := '捌';        WHEN '9' THEN          BIGNUM := '玖';      END CASE;      /*计算精度*/      CASE MONEYPLACE        WHEN '-2' THEN          RMB := '分';        WHEN '-1' THEN          RMB := '角';        WHEN '0' THEN          RMB := '元';        WHEN '1' THEN          RMB := '拾';        WHEN '2' THEN          RMB := '百';        WHEN '3' THEN          RMB := '仟';        WHEN '4' THEN          RMB := '万';        WHEN '5' THEN          RMB := '拾';        WHEN '6' THEN          RMB := '百';        WHEN '7' THEN          RMB := '仟';        WHEN '8' THEN          RMB := '亿';        WHEN '9' THEN          RMB := '拾';        WHEN '10' THEN          RMB := '百';        WHEN '11' THEN          RMB := '仟';      END CASE;      MONEYPLACE := MONEYPLACE + 1;      IF BIGNUM IS NULL THEN        UPPERCASE := BIGNUM || RMB;      ELSE        UPPERCASE := BIGNUM || RMB || UPPERCASE;      END IF;    END IF;  END LOOP;  DBMS_OUTPUT.PUT_LINE(UPPERCASE);  RETURN UPPERCASE;END;
?
  相关解决方案