在SQL建
如下:
SQL取汉字拼音首字母
create proc pinyin @var varchar(100)
as
begin
set @var=ltrim(rtrim(@var))
declare @i int,@v varbinary(2),@varchar varchar(100),@pinyin varchar(100)
set @pinyin=''
set @i=1
while @i<=len(@var)
begin
set @v=cast(substring(@var,@i,1) as varbinary)
if @v<0xB0A1 or @v>0xD7FD
begin
print '含有非法字符'
return
end
if @v>=0xB0A1 and @v<=0xB0C4
begin
set @varchar='A'
end
else if @v>=0xB0C5 and @v<=0xB2C0
begin
set @varchar='B'
end
else if @v>=0xB2C1 and @v<=0xB2C0
begin
set @varchar='C'
end
else if @v>=0xB4EE and @v<=0xB6E9
begin
set @varchar='D'
end
else if @v>=0xB6EA and @v<=0xB7A1
begin
set @varchar='E'
end
else if @v>=0xB7A2 and @v<=0xB8C0
begin
set @varchar='F'
end
else if @v>=0xB8C1 and @v<=0xB9FD
begin
set @varchar='G'
end
else if @v>=0xB9EE and @v<=0xBBF6
begin
set @varchar='H'
end
else if @v>=0xBBF7 and @v<=0xBFA5
begin
set @varchar='J'
end
else if @v>=0xBFA6 and @v<=0xC0AB
begin
set @varchar='K'
end
else if @v>=0xC0AC and @v<=0xC2E7
begin
set @varchar='L'
end
else if @v>=0xC2E8 and @v<=0xC4C2
begin
set @varchar='M'
end
else if @v>=0xC4C3 and @v<=0xC5B5
begin
set @varchar='N'
end
else if @v>=0xC5B6 and @v<=0xC5BD
begin
set @varchar='O'
end
else if @v>=0xC5BE and @v<=0xC6D9
begin
set @varchar='P'
end
else if @v>=0xC6DA and @v<=0xC8BA
begin
set @varchar='Q'
end
else if @v>=0xC8BB and @v<=0xC8F5
begin
set @varchar='R'
end
else if @v>=0xC8F6 and @v<=0xCBF9
begin
set @varchar='S'
end
else if @v>=0xCBFA and @v<=0xCDD9
begin
set @varchar='T'
end
else if @v>=0xCDDA and @v<=0xCEF3
begin
set @varchar='W'
end
else if @v>=0xCEF4 and @v<=0xD1B8
begin
set @varchar='X'
end
else if @v>=0xD1B9 and @v<=0xD4D0
begin
set @varchar='Y'
end
else if @v>=0xD4D1 and @v<=0xD7FD
begin
set @varchar='Z'
end
else
begin
print 'error'
return
end
set @pinyin=@pinyin+@varchar
set @i=@i+1
end
print @pinyin
end
--drop proc pinyin
exec pinyin '中国人'
有的时候,我们有需要将由不同栏位获得的资料串连在一起。每一种资料库都有提供方法来达到这个目的:MySQL: CONCAT()
Oracle: CONCAT(), ||
SQL Server: +
CONCAT() 的语法如下:
CONCAT(字串1, 字串2, 字串3, ...): 将字串1、字串2、字串3,等字串连在一起。请注意,Oracle的CONCAT()只允许两个参数;换言之,一次只能将两个字串串连起来。不过,在Oracle中,我们可以用'||'来一次串连多个字串。
来看几个例子。假设我们有以下的表格:
Geography 表格 region_name store_name
East Boston
East New York
West Los Angeles
West San Diego
例子1:
MySQL/Oracle:
SELECT CONCAT(region_name,store_name) FROM Geography
WHERE store_name = 'Boston'
结果:
'EastBoston'
例子2:
Oracle:
SELECT region_name || ' ' || store_name FROM Geography
WHERE store_name = 'Boston'
结果:
'East Boston'
例子3:
SQL Server:
SELECT region_name + ' ' + store_name FROM Geography
WHERE store_name = 'Boston'
你的select option是动态生成的吧。法一,你的value值,这样设置:1+国家;71+大洋洲-澳洲/新西兰
这样你post后,可以再拆分开你的二个值。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)