当前位置:首页 » 编程语言 » 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了
[]没有不要+\的.