当前位置:首页 » 编程语言 » sql提取数字

sql提取数字

发布时间: 2023-07-05 06:51:34

1. sql怎样取出字符串中的数字

select
casewhenb.FModellike'%=%'thenSUBSTRING(b.FModel,CHARINDEX('=',b.FModel)+1,LEN(b.FModel)-CHARINDEX('=',b.FModel))
whenb.FModellike'%*%'thenSUBSTRING(b.FModel,0,LEN(b.FModel)-CHARINDEX('*',b.FModel))
endas长度

2. SQL怎么取字符串中的数字

select substring(所查询字符串,patindex('%[^0-9][0-9]%',所查询字符串)+1,patindex('%[0-9][^0-9]%',所查询字符串)-patindex('%[^0-9][0-9]%',所查询字符串))这个只能查询第一次在字符串出现的数字串,希望可帮到你你

3. SQL中怎样提取纯数字或者纯字母的字段

完全按照DB2语法设计:
drop function TEST
go
create function test(@input varchar(100))
returns int
begin atomic
declare @int int default 0;
declare @input_lenght int default 0;
set @input_lenght = length(@input);
while @input_lenght <> 0 do
if ( substr(@input,length(@input) - @input_lenght +1,1) in ('0','1','2','3','4','5','6','7','8','9') ) then
set @int = @int + 0;
elseif ( substr(@input,length(@input) - @input_lenght +1,1) in ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z')) then
set @int = @int - 1;
end if;
set @input_lenght = @input_lenght -1;
end while;
if ( @int = 0 or @int = -1* length(@input)) then --- 如果累积为0全是数字;如果累积正好是-1乘以长度则正好全是字段
return 0;
else
return 1;
end if;
end
go
select test ('123456') from sysibm.al 结果是 0
select test ('123b456a') from sysibm.al 结果是 1
select test ('abcdefg') from sysibm.al 结果是 0

4. sql语句在一个字段中提取数字

select regexp_substr('水库新村332号','[0-9]+' ) from al;--用正则表达式取出数字
select regexp_substr('水库新村332号','[[:digit:]]+') from al;

5. SQL如何取数字 各个位上的个十百千万

先将整型转换成字符串,再来做截取:

用到函数:
用到cast转换
substring截取

selectid,SUBSTRING(cast(字段asvarchar(8)),1,1),SUBSTRING(cast(字段asvarchar(8)),2,1),SUBSTRING(cast(字段asvarchar(8)),3,1),SUBSTRING(cast(字段asvarchar(8)),4,1)from表

有问题追问

6. SQL-提取字符串中,两个不同字符中间的数字

题主你好,

试试:

select regexp_substr(字段名,"(?<=:).*(?=\})") from 表名;


-----

希望可以帮到题主,欢迎追问.

热点内容
溯源码怎么生成 发布:2025-02-09 11:15:15 浏览:442
android70flash 发布:2025-02-09 11:15:06 浏览:725
如何查看服务器拒绝信息 发布:2025-02-09 11:13:07 浏览:946
静态编译失败怎么回事 发布:2025-02-09 11:12:54 浏览:215
sql能力 发布:2025-02-09 10:43:50 浏览:982
编译framework 发布:2025-02-09 10:42:11 浏览:382
五子棋对战算法 发布:2025-02-09 10:12:19 浏览:713
php树菜单 发布:2025-02-09 10:04:10 浏览:360
linux保存ip 发布:2025-02-09 10:04:10 浏览:24
四川霜狼服务器怎么样 发布:2025-02-09 10:02:44 浏览:146