[英]SQL extract integer value from a long string
我有一个带有varchar(300)
(包含一些URL)列的表,并且需要将该列的某些值提取到新的integer
列中。
来源栏:
https://my_domain.com/?item1=value1&item2=value2&searching_field=int_value&item4=value4
我需要找到字符串searching_field=int_value
并将int_value
插入表中。
UPD 。 我找到了一个不错的工具REGEXP_SUBSTRING
并且尝试使用如下所示的工具:
SELECT REGEXP_SUBSTR(col_name, 'searching_field=[0-9]+', charindex('searching_field=', col)) as col from my_table
DECLARE @occur_start INT;
DECLARE @occur_end INT;
CREATE TABLE tempdb..#Temp
(col varchar(300), IntVal int)
INSERT INTO tempdb..#Temp
select col, SUBSTRING(col, CHARINDEX('searching_field=', col), CHARINDEX('&item4=value4', col) - CHARINDEX('searching_field=', col)-1) IntValue
FROM YourTable
INSERT INTO YourOtherTable
SELECT IntValue FROM #Temp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.