[英]SQL extract integer value from a long string
I have a table with varchar(300)
(it containts some URLs) column, and I need to extract some value of this column to a new integer
column. 我有一个带有
varchar(300)
(包含一些URL)列的表,并且需要将该列的某些值提取到新的integer
列中。
Source column: 来源栏:
https://my_domain.com/?item1=value1&item2=value2&searching_field=int_value&item4=value4
I need to find string searching_field=int_value
and insert int_value
to a table. 我需要找到字符串
searching_field=int_value
并将int_value
插入表中。
UPD . UPD 。 I found a good tool
REGEXP_SUBSTRING
and I'm trying to use like below: 我找到了一个不错的工具
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.