當前位置:首頁 » 編程語言 » sql截取中文
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sql截取中文

發布時間: 2022-03-14 00:50:18

sql 怎樣截取指定位置的中英文混合體 例如 截取『我是中國人0001』 的8 至 14位元組

create table #temp( test varchar(20) );
INSERT INTO #temp VALUES('我是中國人0001');
go
SELECT
Convert(char(8), test) AS [0to8],
Convert(char(14), test) AS [0to14],
RIGHT(Convert(char(14), test), LEN(Convert(char(14), test)) - LEN(Convert(char(8), test))) AS [8to14]
FROM
#temp
GO
0to8 0to14 8to14
-------- -------------- --------------
我是中國 我是中國人0001 人0001
(1 行受影響)



SQL Server 2008 Express 下測試通過。

㈡ sqlsever中消除記錄中的中文,提取非中文字元

建立函數來處理吧。
createfunctionfun_del_zh
(@colvarchar(1000))
returnsvarchar(1000)
AS
begin
declare@returncharvarchar(1000),@lenint
select@returnchar='',@len=1

while(@len<=len(@col))
begin
if(ASCII(substring(@col,@len,1))<122)
set@returnchar=@returnchar+substring(@col,@len,1)
set@len=@len+1
end
return@returnchar
end
go

selectid,dbo.fun_del_zh(name)nmfromtest;
idnm
test test
test1 test
test2 test2
有問題再追問。

㈢ sql如何從右向左截取中文字元串不亂碼

樓下有結局,中文字元串不亂,門都辦不到了。我覺得目前來說不是很准確的。

㈣ sql 怎麼獲取漢字

、Sql語句是操作資料庫用的,所以,資料庫中沒有的東西是沒辦法調出來的 2、輸入品名就會出現相關的簡名、名字、拼音、拼音縮寫之類的,是通過編程語言來

㈤ sql怎麼截取中文部分

代碼如下:
CREATE PROCEDURE sp_str
(
IN p_str VARCHAR(50), /*原始字元串*/
IN p_begin_str VARCHAR(50), /*要匹配的起始字元串*/
IN p_end_str VARCHAR(50)) /*要匹配的結束字元串*/
OUT p_result VARCHAR(50)) /*返回結果*/
NOT DETERMINISTIC
SQL SECURITY DEFINER
COMMENT ''
BEGIN
DECLARE m_len INT DEFAULT 0;
DECLARE m_index INT DEFAULT 0;
/*計算第一個匹配字元串的索引位置*/
select locate(p_begin_str,p_str)+char_length(p_begin_str) into m_index;
/*計算第一個匹配字元串的長度*/
select locate(p_end_str,p_str,m_index) into m_len;
select SUBSTRING(p_str,m_index,m_len-m_index) INTO p_result ;
END;

執行:
CALL sp_str('[]abcd[12345]aa[]ss','abcd[',']',@result);
返回值 @result 為12345
call sp_str('[]abcd[sdww]aa[]ss','abcd[',']',@result);
返回值 @result 為sdww
如果不用存儲過程,可以直接寫sql語句實現:

代碼如下:
select SUBSTRING(
']abcd[12345]111[]',
locate('abcd[',']abcd[12345]111[]')+CHAR_LENGTH('abcd['),
locate(']',']abcd[12345]111[]',CHAR_LENGTH('abcd['))-
(select locate('abcd[',']abcd[12345]111[]')+CHAR_LENGTH('abcd['))
)

㈥ 如何用sql實現如何只提取漢字或者字母的列部分

如何用sql實現如何只提取漢字或者字母的列部分
select * from a where isnumeric(b)
union all
select * from a where NOT isnumeric(b)

--其中b為需要過濾掉的列名

㈦ SQL 向資料庫只提取漢字

public string NoHTML(string Htmlstring) //去除HTML標記
{
//刪除腳本
Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
//刪除HTML
Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(|#169);", "\xa9", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);

Htmlstring.Replace("<", "");
Htmlstring.Replace(">", "");
Htmlstring.Replace("\r\n", "");
Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();

return Htmlstring;
}

㈧ SQL語句提取出中文的拼音首字母

正好最近收藏了一個 你可以看下思路
--將中文字元串轉化成文字首拼音的組合
create function fun_getPY(@str nvarchar(4000))
returns nvarchar(4000)
as
begin
declare @word nchar(1),@PY nvarchar(4000)
set @PY=''
while len(@str)>0
begin
set @word=left(@str,1)
--如果非漢字字元,返回原字元
set @PY=@PY+(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 'B',N'簿'
union all select 'C',N'錯'
union all select 'D',N'鵽'
union all select 'E',N'樲'
union all select 'F',N'鰒'
union all select 'G',N'腂'
union all select 'H',N'夻'
union all select 'J',N'攈'
union all select 'K',N'穒'
union all select 'L',N'鱳'
union all select 'M',N'旀'
union all select 'N',N'桛'
union all select 'O',N'漚'
union all select 'P',N'曝'
union all select 'Q',N'囕'
union all select 'R',N'鶸'
union all select 'S',N'蜶'
union all select 'T',N'籜'
union all select 'W',N'鶩'
union all select 'X',N'鑂'
union all select 'Y',N'韻'
union all select 'Z',N'咗'
) T
where word>=@word collate Chinese_PRC_CS_AS_KS_WS
order by PY ASC) else @word end)
set @str=right(@str,len(@str)-1)
end
return @PY
end
--函數調用實例:
select dbo.fun_getPY('中華人民共和國AAA01')

/*

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ZHRMGHGAAA01

(1 行受影響)

*/

㈨ SQL截取中文部份

是ORACLE的話,可以考慮:

SQL> select regexp_replace('0005中國文學', '[0-9]', '') from al;

REGEXP_REPLACE('0005中國文學',
------------------------------
中國文學

-----------------------------------
select substr('0006中國文學',5,4) from al;
這個如果前面有 數 是大於 4 的就不對了。
如下:

SQL> select substr('000006中國文學',5,4) from al;

SUBSTR('000006中國文學',5,4)
----------------------------
06中國
--------------------------------------
而這個:
SQL> select regexp_replace('00000005中國文學', '[0-9]', '') from al;

REGEXP_REPLACE('00000005中國文
------------------------------
中國文學

㈩ SQL 怎樣截取指定位置的中英文混合體 例如 截取『我是中國人0001』 的8 至 14位元組

create table #temp( test varchar(20) );
INSERT INTO #temp VALUES('我是中國人0001');
go
SELECT
Convert(char(8), test) AS [0to8],
Convert(char(14), test) AS [0to14],
RIGHT(Convert(char(14), test), LEN(Convert(char(14), test)) - LEN(Convert(char(8), test))) AS [8to14]
FROM
#temp
GO
0to8 0to14 8to14
-------- -------------- --------------
我是中國 我是中國人0001 人0001
(1 行受影響)



SQL Server 下面, 可以這么寫。