當前位置:首頁 » 編程語言 » sql如何提取一列中中括弧內的數據
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sql如何提取一列中中括弧內的數據

發布時間: 2023-07-27 02:22:15

❶ SQL如何把表中一個范圍的數據提取處理

create table aaa (num1 int,num2 int);
insert into aaa values (1,3);
insert into aaa values (6,9);

--豎版
create function dbo.func_d (@a int)
RETURNS @table table(id int) as
begin

declare @num1 int,@num2 int;
declare mycursor cursor for
select * from aaa;
open mycursor
fetch mycursor into @num1,@num2;
while @@fetch_status=0
begin
while @num1<=@num2
begin
insert into @table values (@num1);
set @num1=@num1+1;
end;
fetch mycursor into @num1,@num2;
end;
return;
end

select * from dbo.func_d(1)
--結果:
id
1
2
3
6
7
8
9

----------------------------------
--橫版
create function dbo.func_d2 (@a int)
RETURNS @table table(string varchar(4000)) as
begin

declare @num1 int,@num2 int;
insert into @table values ('a');
declare mycursor cursor for
select * from aaa;
open mycursor
fetch mycursor into @num1,@num2;
while @@fetch_status=0
begin
while @num1<=@num2
begin
update @table set string=string+','+convert(varchar,@num1);
set @num1=@num1+1;
end;
fetch mycursor into @num1,@num2;
end;
update @table set string=stuff(string,1,2,N'');

return;
end

select * from dbo.func_d2(1)
--結果:
string
1,2,3,6,7,8,9

❷ SQL語句通配符查詢, 怎麼查找 中括弧 []

[]中間的大寫字母個數是不固定的話,那就只能參考sungun07了
[]沒有不要+\的.