标签:des style blog http io color ar os for
ORACLE数字转换人民币大写
示例.
数字 : 183066999230.68
人民币大写 : 壹仟捌佰参拾亿零陆仟陆佰玖拾玖万玖仟贰佰参拾圆陆角捌分
数字 : 999900000000
人民币大写 : 玖仟玖佰玖拾玖亿圆整
Step 1. Create Lookups: CUX_CNY_FORMAT
(N) Application Developer > Application > Lookups > Application Object Library
Application Object Library Lookups | ||||||||||
Type | CUX_CNY_FORMAT |
| Access Level
|
| ||||||
Meaning | CUX_CNY_FORMAT | |||||||||
Application | Application Object Library | |||||||||
Description | 数字转换人民币大写 | |||||||||
|
Code | Meaning | Description | Tag | From | To | Enabled | [ ] |
0 | 零 |
|
|
|
| * |
|
1 | 壹 |
|
|
|
| * |
|
2 | 贰 |
|
|
|
| * |
|
3 | 参 |
|
|
|
| * |
|
4 | 肆 |
|
|
|
| * |
|
5 | 伍 |
|
|
|
| * |
|
6 | 陆 |
|
|
|
| * |
|
7 | 染 |
|
|
|
| * |
|
8 | 捌 |
|
|
|
| * |
|
9 | 玖 |
|
|
|
| * |
|
Step 2. Create Lookups: CUX_CNY_UNIT
(N) Application Developer > Application > Lookups > Application Object Library
Application Object Library Lookups | ||||||||||
Type | CUX_CNY_UNIT |
| Access Level
|
| ||||||
Meaning | CUX_CNY_UNIT | |||||||||
Application | Application Object Library | |||||||||
Description | 数字位数长度决定人民币大写的单位 | |||||||||
|
Code | Meaning | Description | Tag | From | To | Enabled | [ ] |
-2 | 分 | 小数单位 |
|
|
| * |
|
-1 | 角 | 小数单位 |
|
|
| * |
|
0 | 整 | 整数补充单元 |
|
|
| * |
|
1 | 圆 | 基本单元 |
|
|
| * |
|
2 | 拾 | 整数基础单位 |
|
|
| * |
|
3 | 佰 | 整数基础单位 |
|
|
| * |
|
4 | 仟 | 整数基础单位 |
|
|
| * |
|
5 | 万 | 特别计量单位 |
|
|
| * |
|
6 | 拾万 | 特别去重计量单位 |
|
|
| * |
|
7 | 佰万 | 特别去重计量单位 |
|
|
| * |
|
8 | 仟万 | 特别去重计量单位 |
|
|
| * |
|
9 | 亿 | 特别计量单位 |
|
|
| * |
|
10 | 拾亿 | 特别去重计量单位 |
|
|
| * |
|
11 | 佰亿 | 特别去重计量单位 |
|
|
| * |
|
12 | 仟亿 | 特别去重计量单位 |
|
|
| * |
|
Step 3. Create Lookups: CUX_CNY_SPECIAL_ZERO
(N) Application Developer > Application > Lookups > Application Object Library
Application Object Library Lookups | ||||||||||
Type | CUX_CNY_SPECIAL_ZERO |
| Access Level
|
| ||||||
Meaning | CUX_CNY_SPECIAL_ZERO | |||||||||
Application | Application Object Library | |||||||||
Description | 人民币大写连续零定位规则 | |||||||||
|
Code | Meaning | Description | Tag | From | To | Enabled | [ ] |
12 | 零零零零零零零零零零零零 | 零 |
|
|
| * |
|
11 | 零零零零零零零零零零零 | 零 |
|
|
| * |
|
10 | 零零零零零零零零零零 | 零 |
|
|
| * |
|
9 | 零零零零零零零零零 | 零 |
|
|
| * |
|
8 | 零零零零零零零零 | 零 |
|
|
| * |
|
7 | 零零零零零零零 | 零 |
|
|
| * |
|
6 | 零零零零零零 | 零 |
|
|
| * |
|
5 | 零零零零零 | 零 |
|
|
| * |
|
4 | 零零零零 | 零 |
|
|
| * |
|
3 | 零零零 | 零 |
|
|
| * |
|
2 | 零零 | 零 |
|
|
| * |
|
Step 4. Create Package: CUX_CONVERTER_CNY_PKG
Content List:
l CONVERTER_CNY
l CONVERTER_CNY_FORMAT
l CONVERTER_CNY_UNIT
l CNY_SPECIAL_ZERO
l CNY_DUPLICATE_UNIT
CREATE OR REPLACE PACKAGE APPS.CUX_CONVERTER_CNY_PKG
AS
FUNCTION CONVERTER_CNY (NUM IN NUMBER)
RETURN VARCHAR2;
FUNCTION CONVERTER_CNY_FORMAT (NUM IN NUMBER)
RETURN VARCHAR2;
FUNCTION CONVERTER_CNY_UNIT (LEN IN NUMBER)
RETURN VARCHAR2;
FUNCTION CNY_SPECIAL_ZERO (NUM IN VARCHAR2, LEN IN NUMBER)
RETURN VARCHAR2;
FUNCTION CNY_DUPLICATE_UNIT (NUM IN VARCHAR2)
RETURN VARCHAR2;
END;
/
CREATE OR REPLACE PACKAGE BODY APPS.CUX_CONVERTER_CNY_PKG
AS
FUNCTION CONVERTER_CNY (NUM IN NUMBER)
RETURN VARCHAR2
IS
L_LEN NUMBER;
L_CNY_LEN NUMBER;
L_CUR_POS NUMBER;
L_NUM VARCHAR2 (100) := NUM;
L_LAST_NUM VARCHAR2(100);
L_ZERO VARCHAR2 (10);
L_CUR_NUM VARCHAR2 (10);
L_CNY VARCHAR2 (10);
L_UNIT VARCHAR2 (10);
L_INTEGER VARCHAR2 (100);
L_DECIMAL VARCHAR2(20);
L_CONVERTER_CNY VARCHAR2 (100);
EXCEPTION_ZERO EXCEPTION;
BEGIN
--Special number
IF (L_NUM = ‘0‘)
THEN
RAISE EXCEPTION_ZERO;
END IF;
--Checking decimal fraction
IF (MOD(L_NUM, 1) <> 0) THEN
L_DECIMAL := SUBSTR(MOD(ROUND(L_NUM, 2),1), 2);
L_INTEGER := ROUND(L_NUM, 2) - MOD(ROUND(L_NUM, 2),1);
ELSIF (MOD(L_NUM, 1) = 0) THEN
L_DECIMAL := NULL;
L_INTEGER := L_NUM;
END IF;
--Integer transaction
IF (L_INTEGER IS NOT NULL) THEN
L_NUM := L_INTEGER;
L_INTEGER := NULL;
L_LEN := LENGTH (L_NUM);
L_CNY_LEN := L_LEN;
FOR L IN 1 .. L_LEN
LOOP
L_CUR_NUM := SUBSTR (L_NUM, L, 1);
L_CUR_POS := (L_LEN - L + 1);
--Converter each number cny format
L_CNY := CUX_CONVERTER_CNY_PKG.CONVERTER_CNY_FORMAT (L_CUR_NUM);
--Search each number unit
IF (L_CUR_NUM = ‘0‘) THEN
L_UNIT := NULL;
ELSIF (L_CUR_POS = 1) THEN
L_UNIT := NULL;
ELSIF (L_CUR_NUM <> ‘0‘) THEN
L_UNIT := CUX_CONVERTER_CNY_PKG.CONVERTER_CNY_UNIT (L_CUR_POS);
END IF;
L_INTEGER := L_INTEGER || (L_CNY || L_UNIT);
END LOOP;
L_ZERO := CUX_CONVERTER_CNY_PKG.CONVERTER_CNY_FORMAT (0);
LOOP
L_LAST_NUM := SUBSTR(L_INTEGER, -1, 1);
IF (L_LAST_NUM = L_ZERO) THEN
L_INTEGER := SUBSTR(L_INTEGER, 1, LENGTH(L_INTEGER)-1);
END IF;
EXIT WHEN L_LAST_NUM <> L_ZERO;
END LOOP;
L_INTEGER := L_INTEGER || CUX_CONVERTER_CNY_PKG.CONVERTER_CNY_UNIT (1);
END IF;
--Decimal transaction
IF (L_DECIMAL IS NOT NULL) THEN
L_NUM := L_DECIMAL;
L_DECIMAL := NULL;
L_LEN := LENGTH (L_NUM);
L_CNY_LEN := L_CNY_LEN + L_LEN;
FOR L IN 1 .. L_LEN
LOOP
L_CUR_NUM := SUBSTR (L_NUM, L, 1);
L_CUR_POS := (- L);
--Converter each number cny format
L_CNY := CUX_CONVERTER_CNY_PKG.CONVERTER_CNY_FORMAT (L_CUR_NUM);
--Search each number unit
IF (L_CUR_NUM = ‘0‘) THEN
L_UNIT := NULL;
--ELSIF (L_CUR_POS = 1) THEN
-- L_UNIT := NULL;
ELSIF (L_CUR_NUM <> ‘0‘) THEN
L_UNIT := CUX_CONVERTER_CNY_PKG.CONVERTER_CNY_UNIT (L_CUR_POS);
END IF;
L_DECIMAL := L_DECIMAL || (L_CNY || L_UNIT);
END LOOP;
END IF;
IF (L_INTEGER IS NOT NULL AND L_DECIMAL IS NULL) THEN
--Linking Integer and unit
L_UNIT := CUX_CONVERTER_CNY_PKG.CONVERTER_CNY_UNIT (0);
L_CONVERTER_CNY := L_INTEGER || L_UNIT;
ELSE
--Linking Integer and unit
L_UNIT := NULL;
L_CONVERTER_CNY := L_INTEGER || L_DECIMAL;
END IF;
--Merge concatenation Zero
L_CONVERTER_CNY := CUX_CONVERTER_CNY_PKG.CNY_SPECIAL_ZERO (L_CONVERTER_CNY, L_CNY_LEN);
--Fixed duplicate unit
L_CONVERTER_CNY := CUX_CONVERTER_CNY_PKG.CNY_DUPLICATE_UNIT (L_CONVERTER_CNY);
RETURN L_CONVERTER_CNY;
EXCEPTION
WHEN EXCEPTION_ZERO
THEN
FND_FILE.PUT_LINE (FND_FILE.OUTPUT, ‘EXCEPTION_ZERO‘);
FND_FILE.PUT_LINE (FND_FILE.OUTPUT, ‘You can‘‘t input the zero !‘);
WHEN OTHERS
THEN
FND_FILE.PUT_LINE (FND_FILE.OUTPUT, SQLCODE);
FND_FILE.PUT_LINE (FND_FILE.OUTPUT, SQLERRM);
END;
FUNCTION CONVERTER_CNY_FORMAT (NUM IN NUMBER)
RETURN VARCHAR2
IS
V_CNY VARCHAR2 (8);
BEGIN
SELECT FLV.MEANING
INTO V_CNY
FROM FND_LOOKUP_VALUES_VL FLV
WHERE 1 = 1
AND SYSDATE BETWEEN NVL (FLV.START_DATE_ACTIVE, SYSDATE)
AND NVL (FLV.END_DATE_ACTIVE, SYSDATE + 1)
AND FLV.ENABLED_FLAG = ‘Y‘
AND FLV.LOOKUP_CODE = NUM
AND FLV.LOOKUP_TYPE = ‘CUX_CNY_FORMAT‘
AND FLV.VIEW_APPLICATION_ID = 0;
RETURN V_CNY;
EXCEPTION
WHEN OTHERS
THEN
FND_FILE.PUT_LINE (FND_FILE.OUTPUT, SQLCODE);
FND_FILE.PUT_LINE (FND_FILE.OUTPUT, SQLERRM);
END;
FUNCTION CONVERTER_CNY_UNIT (LEN IN NUMBER)
RETURN VARCHAR2
IS
V_UNIT VARCHAR2 (10);
BEGIN
SELECT --FLV.DESCRIPTION
FLV.MEANING
INTO V_UNIT
FROM FND_LOOKUP_VALUES_VL FLV
WHERE 1 = 1
AND SYSDATE BETWEEN NVL (FLV.START_DATE_ACTIVE, SYSDATE)
AND NVL (FLV.END_DATE_ACTIVE, SYSDATE + 1)
AND FLV.ENABLED_FLAG = ‘Y‘
AND FLV.LOOKUP_CODE = LEN
AND FLV.LOOKUP_TYPE = ‘CUX_CNY_UNIT‘
AND FLV.VIEW_APPLICATION_ID = 0;
RETURN V_UNIT;
EXCEPTION
WHEN OTHERS
THEN
FND_FILE.PUT_LINE (FND_FILE.OUTPUT, SQLCODE);
FND_FILE.PUT_LINE (FND_FILE.OUTPUT, SQLERRM);
END;
FUNCTION CNY_SPECIAL_ZERO (NUM IN VARCHAR2, LEN IN NUMBER)
RETURN VARCHAR2
IS
V_NUM VARCHAR2 (100) := NUM;
ZERO VARCHAR2(5);
BEGIN
SELECT FLV.MEANING
INTO ZERO
FROM FND_LOOKUP_VALUES_VL FLV
WHERE 1 = 1
AND SYSDATE BETWEEN NVL (FLV.START_DATE_ACTIVE, SYSDATE)
AND NVL (FLV.END_DATE_ACTIVE,
SYSDATE + 1)
AND FLV.ENABLED_FLAG = ‘Y‘
AND FLV.LOOKUP_CODE = ‘0‘
AND FLV.LOOKUP_TYPE = ‘CUX_CNY_FORMAT‘
AND FLV.VIEW_APPLICATION_ID = 0;
FOR Z
IN ( SELECT FLV.MEANING, FLV.DESCRIPTION
FROM FND_LOOKUP_VALUES_VL FLV
WHERE 1 = 1
AND SYSDATE BETWEEN NVL (FLV.START_DATE_ACTIVE, SYSDATE)
AND NVL (FLV.END_DATE_ACTIVE,
SYSDATE + 1)
AND FLV.ENABLED_FLAG = ‘Y‘
AND TO_NUMBER (FLV.LOOKUP_CODE) <= (LEN - 1)
AND FLV.LOOKUP_TYPE = ‘CUX_CNY_SPECIAL_ZERO‘
AND FLV.VIEW_APPLICATION_ID = 0
ORDER BY TO_NUMBER (FLV.LOOKUP_CODE) DESC)
LOOP
V_NUM := REPLACE (V_NUM, Z.MEANING, Z.DESCRIPTION);
END LOOP;
IF (SUBSTR(V_NUM, -1, 1) = ZERO) THEN
V_NUM := SUBSTR(V_NUM, 1, LENGTH(V_NUM)-1);
END IF;
RETURN V_NUM;
EXCEPTION
WHEN OTHERS
THEN
FND_FILE.PUT_LINE (FND_FILE.OUTPUT, SQLCODE);
FND_FILE.PUT_LINE (FND_FILE.OUTPUT, SQLERRM);
END;
FUNCTION CNY_DUPLICATE_UNIT (NUM IN VARCHAR2)
RETURN VARCHAR2
IS
V_CNY VARCHAR2 (100);
V_W5_COUNTER NUMBER := 0;
V_Y9_COUNTER NUMBER := 0;
W5 VARCHAR2 (5);
Y9 VARCHAR2 (5);
V_LEN NUMBER;
V_CUR_CNY VARCHAR2 (10);
V_CNY_LINK VARCHAR2 (100);
STEP NUMBER := 0;
BEGIN
SELECT FLV.MEANING
INTO W5
FROM FND_LOOKUP_VALUES_VL FLV
WHERE 1 = 1
AND SYSDATE BETWEEN NVL (FLV.START_DATE_ACTIVE, SYSDATE)
AND NVL (FLV.END_DATE_ACTIVE, SYSDATE + 1)
AND FLV.ENABLED_FLAG = ‘Y‘
AND FLV.LOOKUP_CODE = ‘5‘
AND FLV.LOOKUP_TYPE = ‘CUX_CNY_UNIT‘
AND FLV.VIEW_APPLICATION_ID = 0;
SELECT FLV.MEANING
INTO Y9
FROM FND_LOOKUP_VALUES_VL FLV
WHERE 1 = 1
AND SYSDATE BETWEEN NVL (FLV.START_DATE_ACTIVE, SYSDATE)
AND NVL (FLV.END_DATE_ACTIVE, SYSDATE + 1)
AND FLV.ENABLED_FLAG = ‘Y‘
AND FLV.LOOKUP_CODE = ‘9‘
AND FLV.LOOKUP_TYPE = ‘CUX_CNY_UNIT‘
AND FLV.VIEW_APPLICATION_ID = 0;
V_CNY := NUM;
V_LEN := - (LENGTH (V_CNY));
LOOP
STEP := STEP - 1;
V_CUR_CNY := SUBSTR (V_CNY, STEP, 1);
IF (V_CUR_CNY = W5)
THEN
V_W5_COUNTER := V_W5_COUNTER + 1;
IF (V_W5_COUNTER > 1)
THEN
V_CUR_CNY := NULL;
END IF;
END IF;
IF (V_CUR_CNY = Y9)
THEN
V_Y9_COUNTER := V_Y9_COUNTER + 1;
IF (V_Y9_COUNTER > 1)
THEN
V_CUR_CNY := NULL;
END IF;
END IF;
V_CNY_LINK := V_CNY_LINK || V_CUR_CNY;
EXIT WHEN STEP = V_LEN;
END LOOP;
V_CNY := NULL;
FOR I IN 1 .. LENGTH (V_CNY_LINK)
LOOP
V_CNY := V_CNY || SUBSTR (V_CNY_LINK, -I, 1);
END LOOP;
RETURN V_CNY;
EXCEPTION
WHEN OTHERS
THEN
FND_FILE.PUT_LINE (FND_FILE.OUTPUT, SQLCODE);
FND_FILE.PUT_LINE (FND_FILE.OUTPUT, SQLERRM);
END;
END;
/
Step 5. Create Testing demo.
数字 : 183066999230.68
人民币大写 : 壹仟捌佰参拾亿零陆仟陆佰玖拾玖万玖仟贰佰参拾圆陆角捌分
数字 : 999900000000
人民币大写 : 玖仟玖佰玖拾玖亿圆整
SELECT CUX_CONVERTER_CNY_PKG.CONVERTER_CNY(183066999230.68) CNY
FROM DUAL;
SELECT CUX_CONVERTER_CNY_PKG.CONVERTER_CNY(999900000000) CNY
FROM DUAL;
Author | 若愚 |
Creation Date | November 2, 2014 |
Last Updated | November 2, 2014 |
Version | V1411.1 |
标签:des style blog http io color ar os for
原文地址:http://www.cnblogs.com/quanweiru/p/4069430.html