Oracle函数中文转拼音(首字母)
CREATE OR REPLACE FUNCTION FUN_GET_PYCODE(p_str IN VARCHAR2,
p_flag NUMBER DEFAULT NULL)
RETURN VARCHAR2 AS
v_compare VARCHAR2(4);
v_return VARCHAR2(4000);
v_length INT := 0;
v_substr VARCHAR2(4); FUNCTION fn_nlssort(p_word IN VARCHAR2) RETURN VARCHAR2 AS
BEGIN
RETURN SUBSTR(NLSSORT(p_word, 'nls_sort=schinese_pinyin_m'), 1, 4);
END fn_nlssort;
BEGIN
IF p_str IS NULL THEN
RETURN '';
END IF; v_length := LENGTH(p_str); CASE p_flag
WHEN 1 THEN
--首字母小写
FOR i IN 1 .. v_length LOOP
v_substr := SUBSTR(p_str, i, 1);
v_compare := fn_nlssort(v_substr); CASE
WHEN v_compare BETWEEN '3B29' AND '3C82' THEN
v_return := v_return || 'a';
WHEN v_compare BETWEEN '3C84' AND '427C' THEN
v_return := v_return || 'b';
WHEN v_compare BETWEEN '427D' AND '4BA9' THEN
v_return := v_return || 'c';
WHEN v_compare BETWEEN '4BAD' AND '' THEN
v_return := v_return || 'd';
WHEN v_compare BETWEEN '' AND '' THEN
v_return := v_return || 'e';
WHEN v_compare BETWEEN '' AND '' THEN
v_return := v_return || 'f';
WHEN v_compare BETWEEN '573C' AND '5CB6' THEN
v_return := v_return || 'g';
WHEN v_compare BETWEEN '5CB8' AND '63FA' THEN
v_return := v_return || 'h';
WHEN v_compare = 'B359' THEN
v_return := v_return || 'i';
WHEN v_compare BETWEEN '63FE' AND '6E85' THEN
v_return := v_return || 'j';
WHEN v_compare BETWEEN '5BC8' AND '' THEN
v_return := v_return || 'k';
WHEN v_compare BETWEEN '722C' AND '7C98' THEN
v_return := v_return || 'l';
WHEN v_compare BETWEEN '569D' AND '821E' THEN
v_return := v_return || 'm';
WHEN v_compare BETWEEN '' AND '' THEN
v_return := v_return || 'n';
WHEN v_compare BETWEEN '' AND '85AE' THEN
v_return := v_return || 'o';
WHEN v_compare BETWEEN '85B1' AND '89C4' THEN
v_return := v_return || 'p';
WHEN v_compare BETWEEN '7E0C' AND '90AA' THEN
v_return := v_return || 'q';
WHEN v_compare BETWEEN '90B0' AND '92E4' THEN
v_return := v_return || 'r';
WHEN v_compare BETWEEN '92E5' AND '9BA9' THEN
v_return := v_return || 's';
WHEN v_compare BETWEEN '' AND 'A1AE' THEN
v_return := v_return || 't';
WHEN v_compare BETWEEN '9AF0' AND 'A5D4' THEN
v_return := v_return || 'w';
WHEN v_compare BETWEEN 'A5D6' AND 'AF1E' THEN
v_return := v_return || 'x';
WHEN v_compare BETWEEN 'AF20' AND 'BC58' THEN
v_return := v_return || 'y';
WHEN v_compare BETWEEN 'BC59' AND 'C7B4' THEN
v_return := v_return || 'z';
ELSE
v_return := v_return || v_substr;
END CASE; END LOOP;
WHEN 2 THEN
--首字母大写
FOR i IN 1 .. v_length LOOP
v_substr := SUBSTR(p_str, i, 1);
v_compare := fn_nlssort(v_substr); CASE
WHEN v_compare BETWEEN '3B29' AND '3C82' THEN
v_return := v_return || 'A';
WHEN v_compare BETWEEN '3C84' AND '427C' THEN
v_return := v_return || 'B';
WHEN v_compare BETWEEN '427D' AND '4BA9' THEN
v_return := v_return || 'C';
WHEN v_compare BETWEEN '4BAD' AND '' THEN
v_return := v_return || 'D';
WHEN v_compare BETWEEN '' AND '' THEN
v_return := v_return || 'E';
WHEN v_compare BETWEEN '' AND '' THEN
v_return := v_return || 'F';
WHEN v_compare BETWEEN '573C' AND '5CB6' THEN
v_return := v_return || 'G';
WHEN v_compare BETWEEN '5CB8' AND '63FA' THEN
v_return := v_return || 'H';
WHEN v_compare = 'B359' THEN
v_return := v_return || 'I';
WHEN v_compare BETWEEN '63FE' AND '6E85' THEN
v_return := v_return || 'J';
WHEN v_compare BETWEEN '5BC8' AND '' THEN
v_return := v_return || 'K';
WHEN v_compare BETWEEN '722C' AND '7C98' THEN
v_return := v_return || 'L';
WHEN v_compare BETWEEN '569D' AND '821E' THEN
v_return := v_return || 'M';
WHEN v_compare BETWEEN '' AND '' THEN
v_return := v_return || 'N';
WHEN v_compare BETWEEN '' AND '85AE' THEN
v_return := v_return || 'O';
WHEN v_compare BETWEEN '85B1' AND '89C4' THEN
v_return := v_return || 'P';
WHEN v_compare BETWEEN '7E0C' AND '90AA' THEN
v_return := v_return || 'Q';
WHEN v_compare BETWEEN '90B0' AND '92E4' THEN
v_return := v_return || 'R';
WHEN v_compare BETWEEN '92E5' AND '9BA9' THEN
v_return := v_return || 'S';
WHEN v_compare BETWEEN '' AND 'A1AE' THEN
v_return := v_return || 'T';
WHEN v_compare BETWEEN '9AF0' AND 'A5D4' THEN
v_return := v_return || 'W';
WHEN v_compare BETWEEN 'A5D6' AND 'AF1E' THEN
v_return := v_return || 'X';
WHEN v_compare BETWEEN 'AF20' AND 'BC58' THEN
v_return := v_return || 'Y';
WHEN v_compare BETWEEN 'BC59' AND 'C7B4' THEN
v_return := v_return || 'Z';
ELSE
v_return := v_return || v_substr;
END CASE; END LOOP;
ELSE
--首字母小写
FOR i IN 1 .. v_length LOOP
v_substr := SUBSTR(p_str, i, 1);
v_compare := fn_nlssort(v_substr); CASE
WHEN v_compare BETWEEN '3B29' AND '3C82' THEN
v_return := v_return || 'a';
WHEN v_compare BETWEEN '3C84' AND '427C' THEN
v_return := v_return || 'b';
WHEN v_compare BETWEEN '427D' AND '4BA9' THEN
v_return := v_return || 'c';
WHEN v_compare BETWEEN '4BAD' AND '' THEN
v_return := v_return || 'd';
WHEN v_compare BETWEEN '' AND '' THEN
v_return := v_return || 'e';
WHEN v_compare BETWEEN '' AND '' THEN
v_return := v_return || 'f';
WHEN v_compare BETWEEN '573C' AND '5CB6' THEN
v_return := v_return || 'g';
WHEN v_compare BETWEEN '5CB8' AND '63FA' THEN
v_return := v_return || 'h';
WHEN v_compare = 'B359' THEN
v_return := v_return || 'i';
WHEN v_compare BETWEEN '63FE' AND '6E85' THEN
v_return := v_return || 'j';
WHEN v_compare BETWEEN '5BC8' AND '' THEN
v_return := v_return || 'k';
WHEN v_compare BETWEEN '722C' AND '7C98' THEN
v_return := v_return || 'l';
WHEN v_compare BETWEEN '569D' AND '821E' THEN
v_return := v_return || 'm';
WHEN v_compare BETWEEN '' AND '' THEN
v_return := v_return || 'n';
WHEN v_compare BETWEEN '' AND '85AE' THEN
v_return := v_return || 'o';
WHEN v_compare BETWEEN '85B1' AND '89C4' THEN
v_return := v_return || 'p';
WHEN v_compare BETWEEN '7E0C' AND '90AA' THEN
v_return := v_return || 'q';
WHEN v_compare BETWEEN '90B0' AND '92E4' THEN
v_return := v_return || 'r';
WHEN v_compare BETWEEN '92E5' AND '9BA9' THEN
v_return := v_return || 's';
WHEN v_compare BETWEEN '' AND 'A1AE' THEN
v_return := v_return || 't';
WHEN v_compare BETWEEN '9AF0' AND 'A5D4' THEN
v_return := v_return || 'w';
WHEN v_compare BETWEEN 'A5D6' AND 'AF1E' THEN
v_return := v_return || 'x';
WHEN v_compare BETWEEN 'AF20' AND 'BC58' THEN
v_return := v_return || 'y';
WHEN v_compare BETWEEN 'BC59' AND 'C7B4' THEN
v_return := v_return || 'z';
ELSE
v_return := v_return || v_substr;
END CASE; END LOOP;
END CASE;
RETURN v_return;
END FUN_GET_PYCODE;
Oracle函数中文转拼音(首字母)的更多相关文章
- Oracle提取中文字符串拼音首字母函数
通过oracle的NLSSORT函数对汉字按照拼音排序,然后根据汉字的区间返回对应的首字母. 效果1,获取拼音简码: 效果2,获取姓名首字母: 创建函数: /* 获取拼音简码函数 */ CREATE ...
- php 获取中文字符拼音首字母
//php获取中文字符拼音首字母 function getFirstCharter($str){ if(empty($str)){return '';} $fchar=ord($str{}); }); ...
- php获取中文字符拼音首字母
//php获取中文字符拼音首字母 function getFirstCharter($str){ if(empty($str)){ return ''; } $fchar = ord($str{0}) ...
- js 获取中文的拼音首字母
es6 + 模块化封装 "use strict"; module.exports = { //参数,中文字符串 //返回值:拼音首字母串数组 makePy (str) { if ( ...
- C#&Sql获取中文字符拼音首字母的方法
C#获取字符拼音首字母,可以存储在数据库中以备将来按字母搜索的需求. public static string GetAc(string s) { try { string temp = Servic ...
- php 中文转拼音首字母问题
<?php /* 中文汉字转拼音首字母的PHP简易实现方法. 要求: 只能是GB2312码表里面中文字符 转换得到字符串对应的拼音首字母大写. 用法: echo zh2py::conv('Chi ...
- mysql 中将汉字(中文)按照拼音首字母排序
因为数据库中可以设定表的编码格式,不同编码格式下,中文的排序有区别,下面分别介绍常用编码下的排序方法. 1.如果数据表的某字段的字符编码是 utf8_general_ci,排序写法: ORDER BY ...
- Oracle的汉字转拼音首字母的函数
CREATE OR REPLACE FUNCTION F_PINYIN(P_NAME IN VARCHAR2) RETURN VARCHAR2 AS V_COMPARE VARCHAR2(100); ...
- javascript 实现中文按照拼音首字母排序
js提供了sort()方法来对数组内的数据进行排序,但是只是对英文有作用,这个时候需要自定义排序的规则 ['张三','李四','王五'].sort((a, b) => a.localeCompa ...
随机推荐
- Vi 的常用命令
1. vi 的三种工作模式 命令模式 打开文件首先进入命令模式, 是使用 vi 的入口; 通过命令对文件进行常规的编辑操作, 例如: 定位,翻页,复制,粘贴,删除等; 末行模式 执行保存,退出等操作, ...
- js获取浏览器信息及版本(兼容IE)
获取浏览器信息方法有很多种,但是要是兼容ie旧版本就有点麻烦了,因为很多方法在旧版本ie是不支持的,所以ie我做了单独处理,但是目前还有小问题,就是想显示QQ浏览器,搜狗浏览器..这样的,这样还实现不 ...
- OCR技术浅探 : 文字定位和文本切割(2)
文字定位 经过前面的特征提取,我们已经较好地提取了图像的文本特征,下面进行文字定位. 主要过程分两步: 1.邻近搜索,目的是圈出单行文字: 2.文本切割,目的是将单行文本切割为单字. 邻近搜索 我们可 ...
- POJ1664:放苹果(线性dp)
题目: http://poj.org/problem?id=1664 Description 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1 ...
- MFC程序执行过程剖析
一 MFC程序执行过程剖析 1)我们知道在WIN32API程序当中,程序的入口为WinMain函数,在这个函数当中我们完成注册窗口类,创建窗口,进入消息循环,最后由操作系统根据发送到程序窗口的消息调用 ...
- ORM中的related_name
ORM 的反向查找(related_name) 先定义两个模型,一个是A,一个是B,是一对多的类型. class A(models.Model): name= models.CharField('名称 ...
- web前端攻城狮整理的收藏夹
作为一名web前端开发工程师你的收藏夹存对了吗?下面是一份互联网上流传甚广的web前端开发收藏夹资源,包含学习网站.JS库.常用工具.常用插件.资讯书籍等资源.速速转存吧~ 一.学习网站 W3 ...
- C# 各种导入 Excel 文件的数据的方法总结
在导入之前都需要将上传的文件保存到服务器,所以避免重复的写这些代码,先贴出上传文件并保存到服务器指定路径的代码. protected void btnImport_Click(object sende ...
- iClap的名字是怎么来的,clap是有什么特殊的意义么?
iClap的名字来源于:Clap中文是鼓掌的意思,鼓掌代表合拍,一个团队的价值观以及工作方式合拍,是最重要的,当项目启动时,大家对产品认可,鼓掌开始实施:当项目成功上线,团队也会以鼓掌的形式庆祝:当我 ...
- Codeforces Round #408 (Div. 2) D - Police Stations
地址:http://codeforces.com/contest/796/problem/D 题目: D. Police Stations time limit per test 2 seconds ...