网站首页 > 技术文章 正文
在最近做的一个项目中,需要将数据库表中的中文字符提取出来,以供业务人员二次处理。网上搜索一番后,采用Oracle数据库的ASCII函数解决问题。主要思路整理如下:
由于中文字符的ASCII码范围为45217至63486之间,因此可以此为切入点对目标字符串进行判断截取。编写函数如下:
create or replace function getCNStr(str varchar2)
return varchar2 is
tmpStr varchar2(100); --临时变量
currentStr varchar2(10); --当前待判断处理的字符
asciiCode number; --当前待怕短处理字符的Ascii码
counts number; --字符串中的字符个数
i_loop number := 1; --循环变量
resultStr varchar2(200); --返回的结果字符串
begin
--取出待处理字符串的长度(counts)
select length(str) into counts from dual;
--根据待处理字符串长度(counts) ,逐个字符判断处理
while i_loop <= counts loop
currentStr := substr(str, i_loop, 1);
select ASCII(currentStr) into asciiCode from dual;
if asciiCode >= 45217 then
tmpStr := tmpStr || currentStr;
end if;
if asciiCode <= 45216 then
--非连续的中文字符串之间以空格隔开
tmpStr := tmpStr || ' ';
end if;
i_loop := i_loop + 1;
end loop;
resultStr := tmpStr;
return(resultStr);
end getCNStr;
至此,函数编写完成,编译后测试如下图:
有图有真相(哈哈)
经测试,此种方法虽然可解决一般的中文提取问题,但在大数据量的情况下,其执行效率的确不怎么高,还有待研究更加高效优化的方法。
猜你喜欢
- 2024-10-18 Oracle ocp认证中文考试考题063-3(中文原版)
- 2024-10-18 Oracle ocp认证中文考试考题063-13(中文原版)
- 2024-10-18 Oracle ocp认证中文考试考题063-44(中文原版)
- 2024-10-18 Oracle OCP 12c 071中文考试题库-第15题
- 2024-10-18 Oracle ocp认证中文考试考题063-25(中文原版)
- 2024-10-18 Oracle ocp认证中文考试考题063-36(中文原版)
- 2024-10-18 Oracle ocp认证中文考试考题063-34(中文原版)
- 2024-10-18 记一次oracle数据库substr和instr函数的使用
- 2024-10-18 Oracle ocp认证中文考试考题063-9(中文原版)
- 2024-10-18 Oracle ocp认证中文考试考题063-23(中文原版)
你 发表评论:
欢迎- 05-10如何优化数据库和前端之间的交互?
- 05-10前端代码优化小秘籍(前端优化24条建议)
- 05-10VS Code当中的15个神仙插件,值得收藏
- 05-10如何自己开发一个Google浏览器插件?
- 05-10前端流行框架Vue3教程:14. 组件传递Props效验
- 05-10吃了一年的SU,最好用的插件都在这了
- 05-10前端必看!这款神器让网站界面告别千篇一律
- 05-10程序员请收好:10个非常有用的 Visual Studio Code 插件
- 最近发表
- 标签列表
-
- 前端设计模式 (75)
- 前端性能优化 (51)
- 前端模板 (66)
- 前端跨域 (52)
- 前端md5加密 (49)
- 前端路由 (55)
- 前端数组 (65)
- 前端定时器 (47)
- 前端懒加载 (45)
- 前端接口 (46)
- Oracle RAC (73)
- oracle恢复 (76)
- oracle 删除表 (48)
- oracle 用户名 (74)
- oracle 工具 (55)
- oracle 内存 (50)
- oracle 导出表 (57)
- oracle查询数据库 (45)
- oracle约束 (46)
- oracle 中文 (51)
- oracle链接 (47)
- oracle的函数 (57)
- mac oracle (47)
- 前端调试 (52)
- 前端登录页面 (48)
本文暂时没有评论,来添加一个吧(●'◡'●)