你知道的越多,你不知道的越多
点赞再看,养成习惯
如果您有疑问或者见解,欢迎指教:


问题

  1. 工作中遇到一些项目需要打印文书,出具文书的日期,客户希望做成XX年XX月XX日的格式,由于目前用的是自研的文书系统,需要通过 sql 来实现格式的转换。
  2. 有些金额,需要转成大写的数字。

解决方案

  1. ORACLE 数据库格式化日期格式为XX年XX月XX日


下面案例的 lzcity_approve_control_info 表 begin_date 字段类型为 DATE


select to_char(a.begin_date,'yyyy')||'年'||to_char(a.begin_date,'MM')||'月'||to_char(a.begin_date,'dd')||'日' begin_date from lzcity_approve_control_info a

oracle、MySQL日期转XX年XX月XX日日期格式和金钱转中文大写数字的方法_格式化日期

2. MySql 数据库格式化日期格式为XX年XX月XX日

select DATE_FORMAT(NOW(),'%Y年%m月%d日');

oracle、MySQL日期转XX年XX月XX日日期格式和金钱转中文大写数字的方法_数据库_02

3. ORACLE 数字大写金额

CREATE OR REPLACE FUNCTION NUMBER_TO_CHINESE(P_NUM IN NUMBER DEFAULT NULL)
RETURN NVARCHAR2 IS
/*Ver:1.0 Created By xsb on 2003-8-18 For:
将金额数字(单位元)转换为大写(采用从低至高算法)
数字整数部分不得超过16位,可以是负数。
Ver:1.1 Modified By xsb on 2003-8-20 For:个位数处理也放在For循环中。
Ver:1.2 Modified By xsb on 2003-8-22 For:分后不带整字。
Ver:1.3 Modified By xsb on 2003-8-28 For:完善测试用例。
测试用例:
SET HEAD OFF
SET FEED OFF
select '无参数时='||NUMBER_TO_CHINESE() from dual;
select 'null='||NUMBER_TO_CHINESE(null) from dual;
select '0='||NUMBER_TO_CHINESE(0) from dual;
select '0.01='||NUMBER_TO_CHINESE(0.01) from dual;
select '0.126='||NUMBER_TO_CHINESE(0.126) from dual;
select '01.234='||NUMBER_TO_CHINESE(01.234) from dual;
select '10='||NUMBER_TO_CHINESE(10) from dual;
select '100.1='||NUMBER_TO_CHINESE(100.1) from dual;
select '100.01='||NUMBER_TO_CHINESE(100.01) from dual;
select '10000='||NUMBER_TO_CHINESE(10000) from dual;
select '10012.12='||NUMBER_TO_CHINESE(10012.12) from dual;
select '20000020.01='||NUMBER_TO_CHINESE(20000020.01) from dual;
select '3040506708.901='||NUMBER_TO_CHINESE(3040506708.901) from dual;
select '40005006078.001='||NUMBER_TO_CHINESE(40005006078.001) from dual;
select '-123456789.98='||NUMBER_TO_CHINESE(-123456789.98) from dual;
select '123456789123456789.89='||NUMBER_TO_CHINESE(123456789123456789.89) from dual;
test
*/
RESULT NVARCHAR2(100); --返回字符串
NUM_ROUND NVARCHAR2(100) := TO_CHAR(ABS(ROUND(P_NUM, 2))); --转换数字为小数点后2位的字符(正数)
NUM_LEFT NVARCHAR2(100); --小数点左边的数字
NUM_RIGHT NVARCHAR2(2); --小数点右边的数字
STR1 NCHAR(10) := '零壹贰叁肆伍陆柒捌玖'; --数字大写
STR2 NCHAR(16) := '元拾佰仟万拾佰仟亿拾佰仟万拾佰仟'; --数字位数(从低至高)
NUM_PRE NUMBER(1) := 1; --前一位上的数字
NUM_CURRENT NUMBER(1); --当前位上的数字
NUM_COUNT NUMBER := 0; --当前数字位数
NUM1 NUMBER;

BEGIN
IF P_NUM IS NULL THEN
RETURN NULL;
END IF; --转换数字为null时返回null

SELECT TO_CHAR(NVL(SUBSTR(TO_CHAR(NUM_ROUND),
1,
DECODE(INSTR(TO_CHAR(NUM_ROUND), '.'),
0,
LENGTH(NUM_ROUND),
INSTR(TO_CHAR(NUM_ROUND), '.') - 1)),
0))
INTO NUM_LEFT
FROM DUAL; --取得小数点左边的数字
SELECT SUBSTR(TO_CHAR(NUM_ROUND),
DECODE(INSTR(TO_CHAR(NUM_ROUND), '.'),
0,
LENGTH(NUM_ROUND) + 1,
INSTR(TO_CHAR(NUM_ROUND), '.') + 1),
2)
INTO NUM_RIGHT
FROM DUAL; --取得小数点右边的数字
SELECT CASE
WHEN LENGTH(NUM_LEFT) >= 8 THEN
TO_NUMBER(SUBSTR(TO_CHAR(NUM_LEFT), -8, 4))
ELSE
TO_NUMBER(SUBSTR(TO_CHAR(NUM_LEFT),
-LENGTH(NUM_LEFT),
LENGTH(NUM_LEFT) - 4))
END
INTO NUM1
FROM DUAL; ---取得千、百、十、万位上的数字
IF LENGTH(NUM_LEFT) > 16 THEN
RETURN '**********';
END IF; --数字整数部分超过16位时

--采用从低至高的算法,先处理小数点右边的数字
IF LENGTH(NUM_RIGHT) = 2 THEN
IF TO_NUMBER(SUBSTR(NUM_RIGHT, 1, 1)) = 0 THEN
RESULT := '零' ||
SUBSTR(STR1, TO_NUMBER(SUBSTR(NUM_RIGHT, 2, 1)) + 1, 1) || '分';
ELSE
RESULT := SUBSTR(STR1, TO_NUMBER(SUBSTR(NUM_RIGHT, 1, 1)) + 1, 1) || '角' ||
SUBSTR(STR1, TO_NUMBER(SUBSTR(NUM_RIGHT, 2, 1)) + 1, 1) || '分';
END IF;
ELSIF LENGTH(NUM_RIGHT) = 1 THEN
RESULT := SUBSTR(STR1, TO_NUMBER(SUBSTR(NUM_RIGHT, 1, 1)) + 1, 1) || '角整';
ELSE
RESULT := '整';
END IF;
--再处理小数点左边的数字
FOR I IN REVERSE 1 .. LENGTH(NUM_LEFT) LOOP
--(从低至高)
NUM_COUNT := NUM_COUNT + 1; --当前数字位数
NUM_CURRENT := TO_NUMBER(SUBSTR(NUM_LEFT, I, 1)); --当前位上的数字
IF NUM_CURRENT > 0 THEN
--当前位上数字不为0按正常处理
RESULT := SUBSTR(STR1, NUM_CURRENT + 1, 1) ||
SUBSTR(STR2, NUM_COUNT, 1) || RESULT;
ELSE
--当前位上数字为0时
IF NUM_COUNT = 5 THEN
IF MOD(NUM_COUNT - 1, 4) = 0 AND NUM1 <> 0 THEN
RESULT := SUBSTR(STR2, NUM_COUNT, 1) || RESULT;
NUM_PRE := 0; --元、万,亿前不准加零 --当前位是元、万或亿时
END IF;
ELSE
IF MOD(NUM_COUNT - 1, 4) = 0 THEN
RESULT := SUBSTR(STR2, NUM_COUNT, 1) || RESULT;
NUM_PRE := 0; --元、万,亿前不准加零
END IF;
END IF;
IF NUM_PRE > 0 OR LENGTH(NUM_LEFT) = 1 THEN
--上一位数字不为0或只有个位时
RESULT := SUBSTR(STR1, NUM_CURRENT + 1, 1) || RESULT;
END IF;
END IF;
NUM_PRE := NUM_CURRENT;
END LOOP;

IF P_NUM < 0 THEN
--转换数字是负数时
RESULT := '负' || RESULT;
END IF;

RETURN RESULT;

EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20001, '数字转换大写出现错误!' || SQLERRM);
END;


下面案例的 appr_pay_order 表的 PN_AMOUNT 字段和 PN_OVERDUE_AMT 字段类型都是 NUMBER(16,2)


select NUMBER_TO_CHINESE(apo.PN_AMOUNT) PN_AMOUNT, NUMBER_TO_CHINESE(apo.PN_OVERDUE_AMT) PN_OVERDUE_AMT from appr_pay_order apo

oracle、MySQL日期转XX年XX月XX日日期格式和金钱转中文大写数字的方法_格式化日期_034. MySql 数字转大写金额

set character set utf8;

DELIMITER $$;

DROP FUNCTION IF EXISTS `to_china_num`;

CREATE FUNCTION `to_china_num`(MONEY decimal(14,2)) RETURNS varchar(150) CHARSET utf8
BEGIN
declare RV_MONEY0 VARCHAR(20);
declare RV_MONEY1 VARCHAR(4);
declare RV_MONEY2 VARCHAR(4);
declare V_MONEY0 VARCHAR(28);
declare V_MONEY1 VARCHAR(4);
declare V_MONEY2 VARCHAR(4);
declare V_MONEY3 VARCHAR(4);
declare V_MONEY4 VARCHAR(4);
declare V_MONEY5 VARCHAR(4);
declare V_MONEY6 VARCHAR(4);
declare V_MONEY7 VARCHAR(4);
declare V_MONEY8 VARCHAR(4);
declare V_MONEY9 VARCHAR(4);
declare V_MONEY10 VARCHAR(4);
declare V_MONEY11 VARCHAR(4);
declare V_MONEY12 VARCHAR(4);
declare RPV_MONEY1 VARCHAR(4);
declare RPV_MONEY2 VARCHAR(4);
declare PV_MONEY0 VARCHAR(14);
declare PV_MONEY1 VARCHAR(4);
declare PV_MONEY2 VARCHAR(4);
declare PV_MONEY3 VARCHAR(4);
declare PV_MONEY4 VARCHAR(4);
declare PV_MONEY5 VARCHAR(4);
declare PV_MONEY6 VARCHAR(4);
declare PV_MONEY7 VARCHAR(4);
declare PV_MONEY8 VARCHAR(4);
declare PV_MONEY9 VARCHAR(4);
declare PV_MONEY10 VARCHAR(4);
declare PV_MONEY11 VARCHAR(4);
declare PV_MONEY12 VARCHAR(4);
declare Z_MONEY VARCHAR(28);
set Z_MONEY=FLOOR(MONEY);
set V_MONEY0=LTRIM(RTRIM(Z_MONEY));
set Z_MONEY=FLOOR(MONEY*100);
set RV_MONEY0=LTRIM(RTRIM(Z_MONEY));
set RV_MONEY1=SUBSTR(RV_MONEY0,LENGTH(RV_MONEY0),1);
IF LENGTH(RV_MONEY0)>1 THEN
set RV_MONEY2=SUBSTR(RV_MONEY0,LENGTH(RV_MONEY0)-1,1);
ELSE
set RV_MONEY2='0';
END IF;
set V_MONEY1=SUBSTR(V_MONEY0,LENGTH(V_MONEY0),1);
IF LENGTH(V_MONEY0)-1>0 THEN
set V_MONEY2=SUBSTR(V_MONEY0,LENGTH(V_MONEY0)-1,1);
ELSE
set V_MONEY2='0';
END IF;
IF LENGTH(V_MONEY0)-2>0 THEN
set V_MONEY3=SUBSTR(V_MONEY0,LENGTH(V_MONEY0)-2,1);
ELSE
set V_MONEY3='0';
END IF;
IF LENGTH(V_MONEY0)-3>0 THEN
set V_MONEY4=SUBSTR(V_MONEY0,LENGTH(V_MONEY0)-3,1);
ELSE
set V_MONEY4='0';
END IF;
IF LENGTH(V_MONEY0)-4>0 THEN
set V_MONEY5=SUBSTR(V_MONEY0,LENGTH(V_MONEY0)-4,1);
ELSE
set V_MONEY5='0';
END IF;
IF LENGTH(V_MONEY0)-5>0 THEN
set V_MONEY6=SUBSTR(V_MONEY0,LENGTH(V_MONEY0)-5,1);
ELSE
set V_MONEY6='0';
END IF;
IF LENGTH(V_MONEY0)-6>0 THEN
set V_MONEY7=SUBSTR(V_MONEY0,LENGTH(V_MONEY0)-6,1);
ELSE
set V_MONEY7='0';
END IF;
IF LENGTH(V_MONEY0)-7>0 THEN
set V_MONEY8=SUBSTR(V_MONEY0,LENGTH(V_MONEY0)-7,1);
ELSE
set V_MONEY8='0';
END IF;
IF LENGTH(V_MONEY0)-8>0 THEN
set V_MONEY9=SUBSTR(V_MONEY0,LENGTH(V_MONEY0)-8,1);
ELSE
set V_MONEY9='0';
END IF;
IF LENGTH(V_MONEY0)-9>0 THEN
set V_MONEY10=SUBSTR(V_MONEY0,LENGTH(V_MONEY0)-9,1);
ELSE
set V_MONEY10='0';
END IF;
IF LENGTH(V_MONEY0)-10>0 THEN
set V_MONEY11=SUBSTR(V_MONEY0,LENGTH(V_MONEY0)-10,1);
ELSE
set V_MONEY11='0';
END IF;
IF LENGTH(V_MONEY0)-11>0 THEN
set V_MONEY12=SUBSTR(V_MONEY0,LENGTH(V_MONEY0)-11,1);
ELSE
set V_MONEY12='0';
END IF;
select if(RV_MONEY1='0','零分',if(RV_MONEY1='1','壹分',if(RV_MONEY1='2','贰分',if(RV_MONEY1='3','叁分',
if(RV_MONEY1='4','肆分',if(RV_MONEY1='5','伍分',if(RV_MONEY1='6','陆分',if(RV_MONEY1='7','柒分',if(
RV_MONEY1='8','捌分','玖分'))))))))) into rpv_money1;
select if(RV_MONEY2='0','零角',if(RV_MONEY2='1','壹角',if(RV_MONEY2='2','贰角',if(RV_MONEY2='3','叁角',
if(RV_MONEY2='4','肆角',if(RV_MONEY2='5','伍角',if(RV_MONEY2='6','陆角',if(RV_MONEY2='7','柒角',if(
RV_MONEY2='8','捌角','玖角'))))))))) into rpv_money2;
select if(V_MONEY1='0','元',if(V_MONEY1='1','壹元',if(V_MONEY1='2','贰元',if(V_MONEY1='3','叁元',
if(V_MONEY1='4','肆元',if(V_MONEY1='5','伍元',if(V_MONEY1='6','陆元',if(V_MONEY1='7','柒元',if(
V_MONEY1='8','捌元','玖元'))))))))) into pv_money1;
select if(V_MONEY2='0','',if(V_MONEY2='1','壹拾',if(V_MONEY2='2','贰拾',if(V_MONEY2='3','叁拾',
if(V_MONEY2='4','肆拾',if(V_MONEY2='5','伍拾',if(V_MONEY2='6','陆拾',if(V_MONEY2='7','柒拾',if(
V_MONEY2='8','捌拾','玖拾'))))))))) into pv_money2;
select if(V_MONEY3='0','',if(V_MONEY3='1','壹佰',if(V_MONEY3='2','贰佰',if(V_MONEY3='3','叁佰',
if(V_MONEY3='4','肆佰',if(V_MONEY3='5','伍佰',if(V_MONEY3='6','陆佰',if(V_MONEY3='7','柒佰',if(
V_MONEY3='8','捌佰','玖佰'))))))))) into pv_money3;
select if(V_MONEY4='0','',if(V_MONEY4='1','壹仟',if(V_MONEY4='2','贰仟',if(V_MONEY4='3','叁仟',
if(V_MONEY4='4','肆仟',if(V_MONEY4='5','伍仟',if(V_MONEY4='6','陆仟',if(V_MONEY4='7','柒仟',if(
V_MONEY4='8','捌仟','玖仟'))))))))) into pv_money4;
select if(V_MONEY5='0','万',if(V_MONEY5='1','壹万',if(V_MONEY5='2','贰万',if(V_MONEY5='3','叁万',
if(V_MONEY5='4','肆万',if(V_MONEY5='5','伍万',if(V_MONEY5='6','陆万',if(V_MONEY5='7','柒万',if(
V_MONEY5='8','捌万','玖万'))))))))) into pv_money5;
select if(V_MONEY6='0','',if(V_MONEY6='1','壹拾',if(V_MONEY6='2','贰拾',if(V_MONEY6='3','叁拾',
if(V_MONEY6='4','肆拾',if(V_MONEY6='5','伍拾',if(V_MONEY6='6','陆拾',if(V_MONEY6='7','玖拾',if(
V_MONEY6='8','捌拾','玖万'))))))))) into pv_money6;
select if(V_MONEY7='0','',if(V_MONEY7='1','壹佰',if(V_MONEY7='2','贰佰',if(V_MONEY7='3','叁佰',
if(V_MONEY7='4','肆佰',if(V_MONEY7='5','伍佰',if(V_MONEY7='6','陆佰',if(V_MONEY7='7','柒佰',if(
V_MONEY7='8','捌佰','玖佰'))))))))) into pv_money7;
select if(V_MONEY8='0','',if(V_MONEY8='1','壹仟',if(V_MONEY8='2','贰仟',if(V_MONEY8='3','叁仟',
if(V_MONEY8='4','肆仟',if(V_MONEY8='5','伍仟',if(V_MONEY8='6','陆仟',if(V_MONEY8='7','柒仟',if(
V_MONEY8='8','捌仟','玖仟'))))))))) into pv_money8;
select if(V_MONEY9='0','亿',if(V_MONEY9='1','壹亿',if(V_MONEY9='2','贰亿',if(V_MONEY9='3','叁亿',
if(V_MONEY9='4','肆亿',if(V_MONEY9='5','伍亿',if(V_MONEY9='6','陆亿',if(V_MONEY9='7','柒亿',if(
V_MONEY9='8','捌亿','玖亿'))))))))) into pv_money9;
select if(V_MONEY10='0','',if(V_MONEY10='1','壹拾',if(V_MONEY10='2','贰拾',if(V_MONEY10='3','叁拾',
if(V_MONEY10='4','肆拾',if(V_MONEY10='5','伍拾',if(V_MONEY10='6','陆拾',if(V_MONEY10='7','玖拾',if(
V_MONEY10='8','捌拾','玖万'))))))))) into pv_money10;
select if(V_MONEY11='0','',if(V_MONEY11='1','壹佰',if(V_MONEY11='2','贰佰',if(V_MONEY11='3','叁佰',
if(V_MONEY11='4','肆佰',if(V_MONEY11='5','伍佰',if(V_MONEY11='6','陆佰',if(V_MONEY11='7','柒佰',if(
V_MONEY11='8','捌佰','玖佰'))))))))) into pv_money11;
select if(V_MONEY12='0','',if(V_MONEY12='1','壹仟',if(V_MONEY12='2','贰仟',if(V_MONEY12='3','叁仟',
if(V_MONEY12='4','肆仟',if(V_MONEY12='5','伍仟',if(V_MONEY12='6','陆仟',if(V_MONEY12='7','柒仟',if(
V_MONEY12='8','捌仟','玖仟'))))))))) into pv_money12;
if RPV_MONEY2 = '零角' AND RPV_MONEY1 = '零分' THEN
set V_MONEY0=CONCAT(PV_MONEY12,PV_MONEY11,PV_MONEY10,PV_MONEY9,PV_MONEY8,PV_MONEY7,PV_MONEY6,PV_MONEY5,PV_MONEY4,
PV_MONEY3,PV_MONEY2,PV_MONEY1,'整');
else
set V_MONEY0=CONCAT(PV_MONEY12,PV_MONEY11,PV_MONEY10,PV_MONEY9,PV_MONEY8,PV_MONEY7,PV_MONEY6,PV_MONEY5,PV_MONEY4,
PV_MONEY3,PV_MONEY2,PV_MONEY1,RPV_MONEY2,RPV_MONEY1);
END IF;

if SUBSTR(V_MONEY0,1,1)='亿' then
set V_MONEY0=SUBSTR(V_MONEY0,2,LENGTH(V_MONEY0)-1);
end if;
if SUBSTR(V_MONEY0,1,1)='万' then
set V_MONEY0=SUBSTR(V_MONEY0,2,LENGTH(V_MONEY0)-1);
end if;
/* 判断亿和万之间间隔的位数 locate */
set V_MONEY0=REPLACE(V_MONEY0,'亿万','亿');
/* 判断亿和元之间间隔的位数 locate */
if locate('元',V_MONEY0)-locate('亿',V_MONEY0)=2 then
set V_MONEY0=REPLACE(V_MONEY0,'亿壹','亿零壹');
set V_MONEY0=REPLACE(V_MONEY0,'亿贰','亿零贰');
set V_MONEY0=REPLACE(V_MONEY0,'亿叁','亿零叁');
set V_MONEY0=REPLACE(V_MONEY0,'亿肆','亿零肆');
set V_MONEY0=REPLACE(V_MONEY0,'亿伍','亿零伍');
set V_MONEY0=REPLACE(V_MONEY0,'亿陆','亿零陆');
set V_MONEY0=REPLACE(V_MONEY0,'亿柒','亿零柒');
set V_MONEY0=REPLACE(V_MONEY0,'亿捌','亿零捌');
set V_MONEY0=REPLACE(V_MONEY0,'亿玖','亿零玖');
end if;
set V_MONEY0=REPLACE(V_MONEY0,'亿壹拾','亿零壹拾');
set V_MONEY0=REPLACE(V_MONEY0,'亿贰拾','亿零贰拾');
set V_MONEY0=REPLACE(V_MONEY0,'亿叁拾','亿零叁拾');
set V_MONEY0=REPLACE(V_MONEY0,'亿肆拾','亿零肆拾');
set V_MONEY0=REPLACE(V_MONEY0,'亿伍拾','亿零伍拾');
set V_MONEY0=REPLACE(V_MONEY0,'亿陆拾','亿零陆拾');
set V_MONEY0=REPLACE(V_MONEY0,'亿柒拾','亿零柒拾');
set V_MONEY0=REPLACE(V_MONEY0,'亿捌拾','亿零捌拾');
set V_MONEY0=REPLACE(V_MONEY0,'亿玖拾','亿零玖拾');
set V_MONEY0=REPLACE(V_MONEY0,'亿壹佰','亿零壹佰');
set V_MONEY0=REPLACE(V_MONEY0,'亿贰佰','亿零贰佰');
set V_MONEY0=REPLACE(V_MONEY0,'亿叁佰','亿零叁佰');
set V_MONEY0=REPLACE(V_MONEY0,'亿肆佰','亿零肆佰');
set V_MONEY0=REPLACE(V_MONEY0,'亿伍佰','亿零伍佰');
set V_MONEY0=REPLACE(V_MONEY0,'亿陆佰','亿零陆佰');
set V_MONEY0=REPLACE(V_MONEY0,'亿柒佰','亿零柒佰');
set V_MONEY0=REPLACE(V_MONEY0,'亿捌佰','亿零捌佰');
set V_MONEY0=REPLACE(V_MONEY0,'亿玖佰','亿零玖佰');
/* 判断最后一个万和元之间间隔的位数 */
if locate('元',V_MONEY0)-locate('万',V_MONEY0)=2 then
set V_MONEY0=REPLACE(V_MONEY0,'万壹','万零壹');
set V_MONEY0=REPLACE(V_MONEY0,'万贰','万零贰');
set V_MONEY0=REPLACE(V_MONEY0,'万叁','万零叁');
set V_MONEY0=REPLACE(V_MONEY0,'万肆','万零肆');
set V_MONEY0=REPLACE(V_MONEY0,'万伍','万零伍');
set V_MONEY0=REPLACE(V_MONEY0,'万陆','万零陆');
set V_MONEY0=REPLACE(V_MONEY0,'万柒','万零柒');
set V_MONEY0=REPLACE(V_MONEY0,'万捌','万零捌');
set V_MONEY0=REPLACE(V_MONEY0,'万玖','万零玖');
end if;
set V_MONEY0=REPLACE(V_MONEY0,'万壹拾','万零壹拾');
set V_MONEY0=REPLACE(V_MONEY0,'万贰拾','万零贰拾');
set V_MONEY0=REPLACE(V_MONEY0,'万叁拾','万零叁拾');
set V_MONEY0=REPLACE(V_MONEY0,'万肆拾','万零肆拾');
set V_MONEY0=REPLACE(V_MONEY0,'万伍拾','万零伍拾');
set V_MONEY0=REPLACE(V_MONEY0,'万陆拾','万零陆拾');
set V_MONEY0=REPLACE(V_MONEY0,'万柒拾','万零柒拾');
set V_MONEY0=REPLACE(V_MONEY0,'万捌拾','万零捌拾');
set V_MONEY0=REPLACE(V_MONEY0,'万玖拾','万零玖拾');
set V_MONEY0=REPLACE(V_MONEY0,'万壹佰','万零壹佰');
set V_MONEY0=REPLACE(V_MONEY0,'万贰佰','万零贰佰');
set V_MONEY0=REPLACE(V_MONEY0,'万叁佰','万零叁佰');
set V_MONEY0=REPLACE(V_MONEY0,'万肆佰','万零肆佰');
set V_MONEY0=REPLACE(V_MONEY0,'万伍佰','万零伍佰');
set V_MONEY0=REPLACE(V_MONEY0,'万陆佰','万零陆佰');
set V_MONEY0=REPLACE(V_MONEY0,'万柒佰','万零柒佰');
set V_MONEY0=REPLACE(V_MONEY0,'万捌佰','万零捌佰');
set V_MONEY0=REPLACE(V_MONEY0,'万玖佰','万零玖佰');
/* 判断最后一个千和元之间间隔的位数 */
if locate('元',V_MONEY0)-locate('仟',V_MONEY0)=2 then
set V_MONEY0=REPLACE(V_MONEY0,'仟壹','仟零壹');
set V_MONEY0=REPLACE(V_MONEY0,'仟贰','仟零贰');
set V_MONEY0=REPLACE(V_MONEY0,'仟叁','仟零叁');
set V_MONEY0=REPLACE(V_MONEY0,'仟肆','仟零肆');
set V_MONEY0=REPLACE(V_MONEY0,'仟伍','仟零伍');
set V_MONEY0=REPLACE(V_MONEY0,'仟陆','仟零陆');
set V_MONEY0=REPLACE(V_MONEY0,'仟柒','仟零柒');
set V_MONEY0=REPLACE(V_MONEY0,'仟捌','仟零捌');
set V_MONEY0=REPLACE(V_MONEY0,'仟玖','仟零玖');
end if;
set V_MONEY0=REPLACE(V_MONEY0,'仟壹拾','仟零壹拾');
set V_MONEY0=REPLACE(V_MONEY0,'仟贰拾','仟零贰拾');
set V_MONEY0=REPLACE(V_MONEY0,'仟叁拾','仟零叁拾');
set V_MONEY0=REPLACE(V_MONEY0,'仟肆拾','仟零肆拾');
set V_MONEY0=REPLACE(V_MONEY0,'仟伍拾','仟零伍拾');
set V_MONEY0=REPLACE(V_MONEY0,'仟陆拾','仟零陆拾');
set V_MONEY0=REPLACE(V_MONEY0,'仟柒拾','仟零柒拾');
set V_MONEY0=REPLACE(V_MONEY0,'仟捌拾','仟零捌拾');
set V_MONEY0=REPLACE(V_MONEY0,'仟玖拾','仟零玖拾');
/* 判断最后一个佰和元之间间隔的位数 */
if locate('元',V_MONEY0)-locate('佰',V_MONEY0)=2 then
set V_MONEY0=REPLACE(V_MONEY0,'佰壹','佰零壹');
set V_MONEY0=REPLACE(V_MONEY0,'佰贰','佰零贰');
set V_MONEY0=REPLACE(V_MONEY0,'佰叁','佰零叁');
set V_MONEY0=REPLACE(V_MONEY0,'佰肆','佰零肆');
set V_MONEY0=REPLACE(V_MONEY0,'佰伍','佰零伍');
set V_MONEY0=REPLACE(V_MONEY0,'佰陆','佰零陆');
set V_MONEY0=REPLACE(V_MONEY0,'佰柒','佰零柒');
set V_MONEY0=REPLACE(V_MONEY0,'佰捌','佰零捌');
set V_MONEY0=REPLACE(V_MONEY0,'佰玖','佰零玖');
end if;

if SUBSTR(V_MONEY0,LENGTH(V_MONEY0)/2-1,1)='零' then
set V_MONEY0=SUBSTR(V_MONEY0,1,LENGTH(V_MONEY0)/2-2);
end if;
if SUBSTR(V_MONEY0,LENGTH(V_MONEY0)/2-1,1)='零' then
set V_MONEY0=SUBSTR(V_MONEY0,1,LENGTH(V_MONEY0)/2-2);
set V_MONEY0=CONCAT(V_MONEY0,'整');
end if;
/* 判断有没有零角,有就替换成零 */
set V_MONEY0=REPLACE(V_MONEY0,'零角','零');
if V_MONEY0='元整' then
set V_MONEY0='零元';
end if;
return V_MONEY0;
END;

测试方法

SELECT to_china_num('2343121.12') AS mathTochar;

oracle、MySQL日期转XX年XX月XX日日期格式和金钱转中文大写数字的方法_格式化日期_04