Chinaunix首页 | 论坛 | 博客
  • 博客访问: 101923931
  • 博文数量: 19283
  • 博客积分: 9968
  • 博客等级: 上将
  • 技术积分: 196062
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-07 14:28
文章分类

全部博文(19283)

文章存档

2011年(1)

2009年(125)

2008年(19094)

2007年(63)

分类:

2008-04-14 19:30:27

来源:赛迪网    作者:zy

我们把B0C0-5 位置的汉字记录下来,即“澳”字,这是以“a”拼音开头在内码表中排列在最后的汉字,用同样的方法,我们找出所有以拼音从b至z开头,在内码表中排列在最后的汉字,与26个字母的对应关系如下:

'澳' a
'怖' b
'错' c
'堕' d
'贰' e
'咐' f
'过' g
'祸' h
i
'骏' j
'阔' k
'络' l
'穆' m
'诺' n
'沤' o
'瀑' p
'群' q
'弱' r
'所' s
'唾' t
u
v
'误' w
'迅' x
'孕' y
'座 z

注:没有以'i','u','v'开头的汉语拼音。

现在假若我们拿出任何一个汉字,放在我们挑选出的这些汉字中间,利用数据库进行一次使用GBK字符集的排序,我们便能够根据这个汉字排列的相对位置得到其拼音首字母。

利用sql语句生成一组上述汉字的结果集,我们将'i','u','v' 三个空缺汉字的位置补上了上一个拼音的汉字,

select t1.strChn 
from ( select '澳' strChn from sysibm.sysdummy1 
union all 
select '怖' strChn from sysibm.sysdummy1 
union all 
select '错' strChn from sysibm.sysdummy1 
union all 
select '堕' strChn from sysibm.sysdummy1 
union all 
select '贰' strChn from sysibm.sysdummy1 
union all 
select '咐' strChn from sysibm.sysdummy1 
union all 
select '过' strChn from sysibm.sysdummy1 
union all 
select '祸' strChn from sysibm.sysdummy1 
union all 
select '祸' strChn from sysibm.sysdummy1 
union all 
select '骏' strChn from sysibm.sysdummy1 
union all 
select '阔' strChn from sysibm.sysdummy1 
union all 
select '络' strChn from sysibm.sysdummy1 
union all 
select '穆' strChn from sysibm.sysdummy1 
union all 
select '诺' strChn from sysibm.sysdummy1 
union all 
select '沤' strChn from sysibm.sysdummy1 
union all 
select '瀑' strChn from sysibm.sysdummy1 
union all 
select '群' strChn from sysibm.sysdummy1 
union all 
select '弱' strChn from sysibm.sysdummy1 
union all 
select '所' strChn from sysibm.sysdummy1 
union all 
select '唾' strChn from sysibm.sysdummy1 
union all 
select '唾' strChn from sysibm.sysdummy1 
union all 
select '唾' strChn from sysibm.sysdummy1 
union all 
select '误' strChn from sysibm.sysdummy1 
union all 
select '迅' strChn from sysibm.sysdummy1 
union all 
select '孕' strChn from sysibm.sysdummy1 
union all 
select '座' strChn from sysibm.sysdummy1 
) as t1

实现

接下来很方便的就可以写出这个函数的具体实现,在实现的代码中,我们又加入了针对英文字母的处理,函数编译后,可通过如下方式调用:

select getIndex( '索' ) index from dual;

index
------
f

实际使用中,应注意建立数据库时字符集参数的设置,应使用GBK字符集。

应用以下命令查看已建立数据库的字符集:

db2 connect to db_name user user_name using password
db2 get db cfg | grep -i 'code set'

此参数在数据库建立之后不能修改。

阅读(457) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~