㈠ sql語句查詢字元串,根據單詞前幾個字母進行模糊查詢
SQL模糊查詢,使用like比較關鍵字,加上SQL里的通配符,請參考以下:1、LIKE'Mc%'將搜索以字母Mc開頭的所有字元串(如McBadden)。2、LIKE'%inger'將搜索以字母inger結尾的所有字元串(如Ringer、Stringer)。3、LIKE'%en%'將搜索在
㈡ sql語句 怎麼在一個字元串中間加幾個字元
1、創建測試表,
create table test_split(id number, value varchar2(20));
㈢ sql 查詢出字元串內有重復字母的
--如果是字元型的,用以下語句
SELECT numberName FROM TABLE
WHERE substr(numberName,1,1)=substr(numberName,2,1) OR substr(numberName,1,1)=substr(numberName,3,1) OR substr(numberName,1,1)=substr(numberName,4,1)
OR substr(numberName,5,1)=substr(numberName,6,1) OR substr(numberName,1,1)=substr(numberName,5,1) OR substr(numberName,1,1)=substr(numberName,7,1)
OR substr(numberName,2,1)=substr(numberName,3,1) OR substr(numberName,2,1)=substr(numberName,4,1) OR substr(numberName,2,1)=substr(numberName,5,1)
OR substr(numberName,2,1)=substr(numberName,6,1) OR substr(numberName,2,1)=substr(numberName,7,1) OR substr(numberName,3,1)=substr(numberName,4,1)
OR substr(numberName,3,1)=substr(numberName,5,1) OR substr(numberName,3,1)=substr(numberName,6,1) OR substr(numberName,3,1)=substr(numberName,7,1)
OR substr(numberName,4,1)=substr(numberName,5,1) OR substr(numberName,4,1)=substr(numberName,6,1) OR substr(numberName,4,1)=substr(numberName,7,1)
OR substr(numberName,5,1)=substr(numberName,6,1) OR substr(numberName,5,1)=substr(numberName,7,1) OR substr(numberName,6,1)=substr(numberName,7,1)
--如果是非數值型,在上述欄位名前加to_char
㈣ sql 判斷字元串中是否含有數字和字母
判斷是否含有字母
select
patindex('%[a-za-z]%',
『ads23432')=0
(如果存在字母,結果>1)
判斷是否含有數字
patindex('%[0-9]%',
『234sdf')=0
(如果存在數字,結果>1)
㈤ 怎樣判斷sql字元串中是否包含數字和字母
判斷否含字母
select PATINDEX('%[A-Za-z]%', 『ads23432')=0
(存字母結>1)
判斷否含數字
PATINDEX('%[0-9]%', 『234sdf')=0
(存數字結>1)
㈥ 用t-sql語句 統計一個字元串中數字,字母,空格以及其他字元的數量
CREATE TABLE TSET_VAR
(
NAME VARCHAR(200)
)
INSERT INTO TSET_VAR VALUES ('AAS12');
INSERT INTO TSET_VAR VALUES ('1AA@@S12');
INSERT INTO TSET_VAR VALUES ('12##1A');
INSERT INTO TSET_VAR VALUES ('AA S 1# 2');
create function tj
(
@str varchar(8000)
)
returns @s table (空格 int,數字 int,字母 int,其他 int)
AS
BEGIN
declare @i int = 1
declare @kg int = 0
declare @sz int =0
declare @zm int =0
declare @qt int =0
declare @x varchar(2000)
while(@i<=(LEN(@str)))
begin
set @x =SUBSTRING(@str,@i,1)
IF (@x =' ')
begin
set @kg =@kg+1
end
else if (PATINDEX('[0-9]',@x)!=0)
begin
set @sz=@sz +1
END
ELSE IF (PATINDEX('[A-Za-z]',@x))!=0
begin
set @zm =@zm+1
end
else
begin
set @qt =@qt+1
end
set @i=@i+1
end
INSERT @s VALUES(@kg,@sz ,@zm,@qt )
return
END
SELECT * FROM TSET_VAR OUTER APPLY DBO.TJ(NAME)
㈦ sql server 2005 如何截取字元串中的字母
如果是第一位,可以直接用left()函數
selectleft(book_id,1)
from表
這樣就可以了
如果是截取第一位後的前二位,要用substring()函數
selectsubstring(book_id,2,2)
from表
這樣就可以了
有問題請繼續追問
㈧ sql server怎麼設計程序統計出一個字元串中的字母空格數字的個數
--建立函數
createfunctiontj
(
@strvarchar(8000)
)
returns@stable(空格int,數字int,字母int,其他int)
AS
BEGIN
declare@iint=1
declare@kgint=0
declare@szint=0
declare@zmint=0
declare@qtint=0
declare@xvarchar(2000)
while(@i<=(LEN(@str)))
begin
set@x=SUBSTRING(@str,@i,1)
IF(@x='')
begin
set@kg=@kg+1
end
elseif(PATINDEX('[0-9]',@x)!=0)
begin
set@sz=@sz+1
END
ELSEIF(PATINDEX('[A-Za-z]',@x))!=0
begin
set@zm=@zm+1
end
else
begin
set@qt=@qt+1
end
set@i=@i+1
end
INSERT@sVALUES(@kg,@sz,@zm,@qt)
return
END
--建立測試表
CREATETABLETSET_VAR
(
NAMEVARCHAR(200)
)
INSERTINTOTSET_VARVALUES('AAS12');
INSERTINTOTSET_VARVALUES('1AA@@S12');
INSERTINTOTSET_VARVALUES('12##1A');
INSERTINTOTSET_VARVALUES('AAS1#2');
--嘗試結果
SELECT*FROMTSET_VAROUTERAPPLYDBO.TJ(NAME)
我這個是查詢空格(KG),字母(ZM),數字(SZ),其他字元(qt)的一個函數
㈨ SQL語句查詢返回字元串中中文字元前的字元(包含數字與字母)
select substring(field1,1,patindex('%[吖-咗]%',field1)-1) from table