当前位置:首页 » 编程语言 » 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-10-19 06:40:34 浏览:928
squid代理ftp 发布:2025-10-19 06:25:53 浏览:211
php定义全局变量 发布:2025-10-19 06:21:49 浏览:37
为什么要做配置中心 发布:2025-10-19 06:18:11 浏览:81
php异步上传图片 发布:2025-10-19 06:01:23 浏览:524
mysql数据库属性 发布:2025-10-19 05:39:10 浏览:818
python3发送邮件 发布:2025-10-19 05:37:42 浏览:149
怎么把安卓软件包做成链接 发布:2025-10-19 05:31:17 浏览:651
安卓系统怎么越来越大了 发布:2025-10-19 05:30:28 浏览:758
db2数据库编目 发布:2025-10-19 05:22:45 浏览:237