我有这张桌子:
DROP TABLE IF EXISTS test2_sim;
CREATE TABLE test2_sim (
texto VARCHAR(1024) NOT NULL
);
有了这些记录:
INSERT INTO test2_sim (texto) VALUES ('/A/posts/2088973241125818');
INSERT INTO test2_sim (texto) VALUES ('/A/posts/2088973241125818?commen');
INSERT INTO test2_sim (texto) VALUES ('/B/posts/10155759853867175?__xts_');
INSERT INTO test2_sim (texto) VALUES ('/C/posts/595673157521288');
INSERT INTO test2_sim (texto) VALUES ('/D/posts/365108183946?__xts__%5B0%5D=68.ARCs');
INSERT INTO test2_sim (texto) VALUES ('/E/posts/1028007200735853?__xts__%5B0%5');
我试着为每一个记录提取一个可变的数字序列,
例如
Record1 > 2088973241125818
Record2 > 2088973241125818
Record3 > 10155759853867175
可以在Select语句中使用REGEX命令吗?
比如:
Select *, REGEX(texto,'^[specific_patterns]' AS regex_out from test2_sim;
假设一个有效的数字序列是大于10的连续数字。
谢谢
规则
最佳答案
无需使用REGEX
。用这种方式使用CONVERT
和SUBSTRING_INDEX
怎么样?
SELECT CONVERT(SUBSTRING_INDEX(texto, '/', -1), UNSIGNED INTEGER) as seq_num from test2_sim;
见小提琴:http://www.sqlfiddle.com/#!9/e914d/12