『壹』 sql一個表A有多列數據是字母,需要關聯字典表B,將這多列字母轉為漢字。
selecta.*,b1.漢字,b2.漢字fromAa
leftjoinBb1ona.欄位1=b1.欄位
leftjoinbb2ona.欄位2=b2.欄位
如果有再多欄位就後面 left join 往上加
『貳』 SQL語句 把用戶名中文改成拼音字母
看看這個http://dhjdhja.blog.163.com/blog/static/64762009101684639346/ ps:奶奶的貼一個地址鏈接還不行什麼破論壇,內容又發不完 --sql漢字轉拼音
SET ANSI_NULLS ON
GOSET QUOTED_IDENTIFIER ON
GOcreate function [dbo].[fn_GetPinyin](@words nvarchar(2000))
returns varchar(8000)
as
begin
declare @word nchar(1)
declare @pinyin varchar(8000)
declare @i int
declare @words_len int
declare @unicode int
set @i = 1
set @words = ltrim(rtrim(@words))
set @words_len = len(@words)
while (@i <= @words_len) --循環取字元
begin
set @word = substring(@words, @i, 1)
set @unicode = unicode(@word)
set @pinyin = ISNULL(@pinyin+space(1),'')+
(case when unicode(@word) between 19968 and 19968+20901 then
(select top 1 py from (
select 'a' as py,N'厑' as word
union all select 'ai',N'靉'
union all select 'an',N'黯'
union all select 'ang',N'醠'
union all select 'ao',N'驁'
union all select 'ba',N'欛'
union all select '',N'瓸' --韛兡瓸
union all select 'ban',N'瓣'
union all select 'bang',N'鎊'
union all select 'bao',N'鑤'
union all select 'bei',N'鐾'
union all select 'ben',N'輽'
union all select 'beng',N'鏰'
union all select 'bi',N'鼊'
union all select 'bian',N'變'
union all select 'biao',N'鰾'
union all select 'bie',N'彆'
union all select 'bin',N'鬢'
union all select 'bing',N'靐'
union all select 'bo',N'卜'
union all select 'bu',N'簿'
union all select 'ca',N'囃'
union all select 'cai',N'乲' --縩乲
union all select 'can',N'爘'
union all select 'cang',N'賶'
union all select 'cao',N'鼜'
union all select 'ce',N'簎'
union all select 'cen',N'笒'
union all select 'ceng',N'乽' --硛硳岾猠乽
union all select 'cha',N'詫'
union all select 'chai',N'囆'
union all select 'chan',N'顫'
union all select 'chang',N'韔'
union all select 'chao',N'觘'
union all select 'che',N'爡'
union all select 'chen',N'讖'
union all select 'cheng',N'秤'
union all select 'chi',N'鷘'
union all select 'chong',N'銃'
union all select 'chou',N'殠'
union all select 'chu',N'矗'
union all select 'chuai',N'踹'
union all select 'chuan',N'鶨'
union all select 'chuang',N'愴'
union all select 'chui',N'顀'
union all select 'chun',N'蠢'
union all select 'chuo',N'縒'
union all select 'ci',N'嗭' --賜嗭
union all select 'cong',N'謥'
union all select 'cou',N'輳'
union all select 'cu',N'顣'
union all select 'cuan',N'爨'
union all select 'cui',N'臎'
union all select 'cun',N'籿'
union all select 'cuo',N'錯'
union all select 'da',N'橽'
union all select 'dai',N'靆'
union all select 'dan',N'饏'
union all select 'dang',N'闣'
union all select '',N'纛'
union all select 'de',N'的'
union all select 'den',N'扽'
union all select 'deng',N'鐙'
union all select 'di',N'螮'
union all select 'dia',N'嗲'
union all select 'dian',N'驔'
union all select 'diao',N'鑃'
union all select 'die',N'嚸' --眰嚸
union all select 'ding',N'顁'
union all select 'diu',N'銩'
union all select 'dong',N'霘'
union all select 'dou',N'鬭'
union all select '',N'蠹'
union all select 'an',N'叾' --籪叾
union all select 'i',N'譵'
union all select 'n',N'踲'
union all select 'o',N'鵽'
union all select 'e',N'鱷'
union all select 'en',N'摁'
union all select 'eng',N'鞥'
union all select 'er',N'樲'
union all select 'fa',N'發'
union all select 'fan',N'瀪'
union all select 'fang',N'放'
union all select 'fei',N'靅'
union all select 'fen',N'鱝'
union all select 'feng',N'覅'
union all select 'fo',N'梻'
union all select 'fou',N'鴀'
union all select 'fu',N'猤' --鰒猤
union all select 'ga',N'魀'
union all select 'gai',N'瓂'
union all select 'gan',N'灨'
union all select 'gang',N'戇'
union all select 'gao',N'鋯'
union all select 'ge',N'獦'
union all select 'gei',N'給'
union all select 'gen',N'搄'
union all select 'geng',N'堩' --亘堩啹喼嗰
union all select 'gong',N'兣' --熕贑兝兣
union all select 'gou',N'購'
union all select 'gu',N'顧'
union all select 'gua',N'詿'
union all select 'guai',N'恠'
union all select 'guan',N'鱹'
union all select 'guang',N'撗'
union all select 'gui',N'鱥'
union all select 'gun',N'謴'
union all select 'guo',N'腂'
union all select 'ha',N'哈'
union all select 'hai',N'饚'
『叄』 sql 語句 急!!!! 數據將英文和數字去掉,只保留漢字的sql語句
1、創建測試表,
create table test_replace_str(value varchar2(200));
4、編寫語句,將英文和數字去掉,只保留漢字;
select t.*, regexp_replace(value, '[a-zA-Z0-9]', '') sec
from test_replace_str t;
『肆』 SQL Server 如何提取漢字首字母
代碼如下:
USE [database]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[getPinYin] (@str varchar(500) = '')
RETURNS varchar(500) AS
BEGIN
Declare @strlen int,
@return varchar(500),
@ii int,
@c char(1),
@chn nchar(1)
--//初始化變數
Declare @pytable table(
chn char(2) COLLATE Chinese_PRC_CS_AS NOT NULL,
py char(1) COLLATE Chinese_PRC_CS_AS NULL,
PRIMARY KEY (chn)
)
insert into @pytable values('吖', 'A')
insert into @pytable values('八', 'B')
insert into @pytable values('嚓', 'C')
insert into @pytable values('咑', 'D')
insert into @pytable values('妸', 'E')
insert into @pytable values('發', 'F')
insert into @pytable values('旮', 'G')
insert into @pytable values('鉿', 'H')
insert into @pytable values('丌', 'I')
insert into @pytable values('丌', 'J')
insert into @pytable values('咔', 'K')
insert into @pytable values('垃', 'L')
insert into @pytable values('嘸', 'M')
insert into @pytable values('拏', 'N')
insert into @pytable values('噢', 'O')
insert into @pytable values('妑', 'P')
insert into @pytable values('七', 'Q')
insert into @pytable values('呥', 'R')
insert into @pytable values('仨', 'S')
insert into @pytable values('他', 'T')
--insert into @pytable values('屲', 'U')
--insert into @pytable values('屲', 'V')
insert into @pytable values('屲', 'W')
insert into @pytable values('夕', 'X')
insert into @pytable values('丫', 'Y')
insert into @pytable values('帀', 'Z')
select @strlen = len(@str), @return = '', @ii = 0
//循環整個字元串,用拼音的首字母替換漢字
while @ii < @strlen
begin
select @ii = @ii + 1, @chn = substring(@str , @ii, 1)
if @chn > 'z' --//檢索輸入的字元串中有中文字元
SELECT @c = max(py)
FROM @pytable
where chn <= @chn
else
set @c=@chn
set @return=@return+@c
end
return @return
END
『伍』 求用sql語句分離漢字和字母
SELECT DECODE(
INSTR(term_code,' ')
,0
,Regexp_replace(term_code,'[-A-Za-z0-9]','')
,substr(term_code,0,INSTR(term_code,' ')-1)
) 類型
,DECODE(
INSTR(term_code,' ')
,0
,Regexp_replace(term_code,'[^-A-Za-z0-9]','')
,substr(term_code,INSTR(term_code,' ')+1)
) 型號
FROM table_name;
『陸』 sql 正則表達式 替換字母+數字
我不知道你用的是什麼資料庫,下面我給你一個Oracle資料庫的替換掉(-N+數字)的例子
update[dbo].[Winit庫存]set[商品編號]=REGEXP_REPLACE([商品編號],'-Nd+','')
不同的資料庫,用的可以用正則表達式的replace函數不一樣
SQL Server中我不知道你那裡有沒有dbo.RegexReplace函數,是不是還要現建這個替換函數
update[dbo].[Winit庫存]set[商品編號]=dbo.RegexReplace([商品編號],'-Nd+','',1)
下面是建立RegexReplace函數的sql語句
--如果存在則刪除原有函數
IFOBJECT_ID(N'dbo.RegexReplace')ISNOTNULL
DROPFUNCTIONdbo.RegexReplace
GO
--開始創建正則替換函數
CREATEFUNCTIONdbo.RegexReplace
(
@stringVARCHAR(MAX),--被替換的字元串
@patternVARCHAR(255),--替換模板
@replacestrVARCHAR(255),--替換後的字元串
@IgnoreCaseINT=0--0區分大小寫1不區分大小寫
)
RETURNSVARCHAR(8000)
AS
BEGIN
DECLARE@objRegexINT,@retstrVARCHAR(8000)
--創建對象
EXECsp_OACreate'VBScript.RegExp',@objRegexOUT
--設置屬性
EXECsp_OASetProperty@objRegex,'Pattern',@pattern
EXECsp_OASetProperty@objRegex,'IgnoreCase',@IgnoreCase
EXECsp_OASetProperty@objRegex,'Global',1
--執行
EXECsp_OAMethod@objRegex,'Replace',@retstrOUT,@string,@replacestr
--釋放
EXECUTEsp_OADestroy@objRegex
RETURN@retstr
END
GO
--保證正常運行的話,需要將OleAutomationProceres選項置為1
EXECsp_configure'showadvancedoptions',1
RECONFIGUREWITHOVERRIDE
EXECsp_configure'OleAutomationProceres',1
RECONFIGUREWITHOVERRIDE