如何按拼音查询

qq_40608182 2017-10-22 09:57:37
表名为tab,字段名称为name
数据如下:
Name






select * from table where 条件(拼音为A开头);

要求查询结果:
Name

...全文
639 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
碧水幽幽泉 2017-10-22
  • 打赏
  • 举报
回复
引用 6 楼 tangren的回复:
[quote=引用 4 楼 qq646748739 的回复:] [quote=引用 2 楼 tangren的回复:]可以参照一下这个: https://www.2cto.com/database/201203/123635.html 或者更复杂和全面一点的: http://blog.csdn.net/zftang/article/details/6439805
老衲,好多年没看到你了,上次见你活跃于CSDN是在2010年,7年前~[/quote] 呵呵,老了,退隐江湖了。兄弟记忆力真是厉害![/quote] 搞数据的,记忆力应该比别人好点才行。最近感觉CSDN越来越没落了,之前很多大牛活跃CSDN,比如@wildwave @shiyiwan @iqlife @wh62592855 @gelyon。。。等等,现在变成我是最活跃之一了。
tangren 2017-10-22
  • 打赏
  • 举报
回复
引用 4 楼 qq646748739 的回复:
[quote=引用 2 楼 tangren的回复:]可以参照一下这个: https://www.2cto.com/database/201203/123635.html 或者更复杂和全面一点的: http://blog.csdn.net/zftang/article/details/6439805
老衲,好多年没看到你了,上次见你活跃于CSDN是在2010年,7年前~[/quote] 呵呵,老了,退隐江湖了。兄弟记忆力真是厉害!
碧水幽幽泉 2017-10-22
  • 打赏
  • 举报
回复
格式化下:

--1.创建测试表
select ascii('安') a,'安' x from dual union all
select ascii('被') a,'被' x from dual union all
select ascii('走') a,'走' x from dual union all
select ascii('神') a,'神' x from dual union all
select ascii('哎') a,'哎' x from dual union all
select ascii('澳') a,'澳' x from dual union all
select ascii('阿') a,'阿' x from dual  
order by x


--2.应该根据ascii排序的。
SQL> select ascii('安') a,'安' x from dual union all
  2  select ascii('被') a,'被' x from dual union all
  3  select ascii('走') a,'走' x from dual union all
  4  select ascii('神') a,'神' x from dual union all
  5  select ascii('哎') a,'哎' x from dual union all
  6  select ascii('澳') a,'澳' x from dual union all
  7  select ascii('阿') a,'阿' x from dual
  8  order by x;
 
         A X
---------- --------------------------------
     45218 阿
     45221 哎
     45234 安
     45252 澳
     45499 被
     51697 神
     55263 走
 
7 rows selected

--3.分析:"哎"和"安"对于得ascii为45221和45234
故要查询出"安"和"哎"只要ascii的范围包括45221和45234即可.

例:
SQL> select chr(45219) from dual;
 
CHR(45219)
----------
埃

SQL> select chr(45235) from dual;
 
CHR(45235)
----------
俺

--写法1: 
SQL> select * from tt where substr(name,1,1) between '挨' and '俺';
 
NAME
----
安
哎

--写法2:
SQL> select * from tt where substr(name,1,1) between chr(45221) and chr(45234);
 
NAME
----
安
哎

--写法3:

SQL> select * from tt where substr(name,1,1) between '阿' and '澳';
 
NAME
----
安
碧水幽幽泉 2017-10-22
  • 打赏
  • 举报
回复
引用 2 楼 tangren的回复:
可以参照一下这个: https://www.2cto.com/database/201203/123635.html 或者更复杂和全面一点的: http://blog.csdn.net/zftang/article/details/6439805
老衲,好多年没看到你了,上次见你活跃于CSDN是在2010年,7年前~
碧水幽幽泉 2017-10-22
  • 打赏
  • 举报
回复
--1.创建测试表 select ascii('安') a,'安' x from dual union all select ascii('被') a,'被' x from dual union all select ascii('走') a,'走' x from dual union all select ascii('神') a,'神' x from dual union all select ascii('哎') a,'哎' x from dual union all select ascii('澳') a,'澳' x from dual union all select ascii('阿') a,'阿' x from dual order by x --2.应该根据ascii排序的。 SQL> select ascii('安') a,'安' x from dual union all 2 select ascii('被') a,'被' x from dual union all 3 select ascii('走') a,'走' x from dual union all 4 select ascii('神') a,'神' x from dual union all 5 select ascii('哎') a,'哎' x from dual union all 6 select ascii('澳') a,'澳' x from dual union all 7 select ascii('阿') a,'阿' x from dual 8 order by x; A X ---------- -------------------------------- 45218 阿 45221 哎 45234 安 45252 澳 45499 被 51697 神 55263 走 7 rows selected --3.分析:"哎"和"安"对于得ascii为45221和45234 故要查询出"安"和"哎"只要ascii的范围包括45221和45234即可. 例: SQL> select chr(45219) from dual; CHR(45219) ---------- 埃 SQL> select chr(45235) from dual; CHR(45235) ---------- 俺 --写法1: SQL> select * from tt where substr(name,1,1) between '挨' and '俺'; NAME ---- 安 哎 --写法2: SQL> select * from tt where substr(name,1,1) between chr(45221) and chr(45234); NAME ---- 安 哎 --写法3: SQL> select * from tt where substr(name,1,1) between '阿' and '澳'; NAME ---- 安 哎
tangren 2017-10-22
  • 打赏
  • 举报
回复
可以参照一下这个: https://www.2cto.com/database/201203/123635.html 或者更复杂和全面一点的: http://blog.csdn.net/zftang/article/details/6439805
花开了叫我 2017-10-22
  • 打赏
  • 举报
回复
多音字咋办?

17,081

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧