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函数中文转拼音(首字母)的更多相关文章

  1. Oracle提取中文字符串拼音首字母函数

    通过oracle的NLSSORT函数对汉字按照拼音排序,然后根据汉字的区间返回对应的首字母. 效果1,获取拼音简码: 效果2,获取姓名首字母: 创建函数: /* 获取拼音简码函数 */ CREATE ...

  2. php 获取中文字符拼音首字母

    //php获取中文字符拼音首字母 function getFirstCharter($str){ if(empty($str)){return '';} $fchar=ord($str{}); }); ...

  3. php获取中文字符拼音首字母

    //php获取中文字符拼音首字母 function getFirstCharter($str){ if(empty($str)){ return ''; } $fchar = ord($str{0}) ...

  4. js 获取中文的拼音首字母

    es6 + 模块化封装 "use strict"; module.exports = { //参数,中文字符串 //返回值:拼音首字母串数组 makePy (str) { if ( ...

  5. C#&Sql获取中文字符拼音首字母的方法

    C#获取字符拼音首字母,可以存储在数据库中以备将来按字母搜索的需求. public static string GetAc(string s) { try { string temp = Servic ...

  6. php 中文转拼音首字母问题

    <?php /* 中文汉字转拼音首字母的PHP简易实现方法. 要求: 只能是GB2312码表里面中文字符 转换得到字符串对应的拼音首字母大写. 用法: echo zh2py::conv('Chi ...

  7. mysql 中将汉字(中文)按照拼音首字母排序

    因为数据库中可以设定表的编码格式,不同编码格式下,中文的排序有区别,下面分别介绍常用编码下的排序方法. 1.如果数据表的某字段的字符编码是 utf8_general_ci,排序写法: ORDER BY ...

  8. Oracle的汉字转拼音首字母的函数

    CREATE OR REPLACE FUNCTION F_PINYIN(P_NAME IN VARCHAR2) RETURN VARCHAR2 AS V_COMPARE VARCHAR2(100); ...

  9. javascript 实现中文按照拼音首字母排序

    js提供了sort()方法来对数组内的数据进行排序,但是只是对英文有作用,这个时候需要自定义排序的规则 ['张三','李四','王五'].sort((a, b) => a.localeCompa ...

随机推荐

  1. python 面向对象(进阶篇)转载武沛齐

    上一篇<Python 面向对象(初级篇)>文章介绍了面向对象基本知识: 面向对象是一种编程方式,此编程方式的实现是基于对 类 和 对象 的使用 类 是一个模板,模板中包装了多个“函数”供使 ...

  2. Purpose of ContextLoaderListener in Spring

    The ApplicationContext is where your Spring beans live. The purpose of the ContextLoaderListener is ...

  3. django cookie 提供的功能 参数

    # 用户发来数据带来所有COOKIES 这个cookie是字典 request.COOKIES # 获取字典 获取cookierequest.COOKIES["username111&quo ...

  4. dijstra算法,求源点到各个顶点的最短距离

    1:dijstra算法常用语求最短距离, dijstra每次从未发现节点n[]中,发现距离源点最短的节点m,求出最短节点后,将m添加到已发现节点y[]中,用该节点m进行更新其它未发现节点n[]-m的最 ...

  5. Spark如何写入HBase/Redis/MySQL/Kafka

    一些概念 一个partition 对应一个task,一个task 必定存在于一个Executor,一个Executor 对应一个JVM. Partition 是一个可迭代数据集合 Task 本质是作用 ...

  6. HBase在HDFS上的目录树

    众所周知,HBase 是天生就是架设在 HDFS 上,在这个分布式文件系统中,HBase 是怎么去构建自己的目录树的呢? 这里只介绍系统级别的目录树: 一.0.94-cdh4.2.1版本 系统级别的一 ...

  7. 推荐系统第3周--- 大数据环境下的itemCF实现

    代码报错注意事项: 1:最后Ctrl+shift+O  导入包2:导入mahout包3:新建datafile文件包,在其下面新建csv文件

  8. 深入理解JS对象和原型链

    函数在整个js中是最复杂也是最重要的知识 一个函数中存在多面性: 1.它本身就是一个普通的函数,执行的时候形成的私有作用域(闭包),形参赋值,预解释,代码执行,执行完 成后栈内存销毁/不销毁. 2.& ...

  9. fake-useragent,python爬虫伪装请求头

    在编写爬虫进行网页数据的时候,大多数情况下,需要在请求是增加请求头,下面介绍一个python下非常好用的伪装请求头的库:fake-useragent,具体使用说明如下: 1.在scrapy中的使用 第 ...

  10. tomcat服务无响应堆栈分析

    tomcat服务突然无响应了,导出内存堆栈和线程堆栈,分析后发现是同步锁使用不合理导致的. [root@prd-dtb-web-01 ~]# [root@prd-dtb-web-01 ~]# jmap ...