解析字符串以从下划线分隔的大字符串中获取数字
让我们首先创建一个表-
mysql> create table DemoTable1961 ( Title text );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1961 values('You_can_remove_the_string_part_only-10001-But_You_can_not_remove_the_numeric_parts');使用select语句显示表中的所有记录-
mysql> select * from DemoTable1961;
这将产生以下输出-
+------------------------------------------------------------------------------------+ | Title | +------------------------------------------------------------------------------------+ | You_can_remove_the_string_part_only-10001-But_You_can_not_remove_the_numeric_parts | +------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
这是实现CAST()和解析字符串以从字符串中获取数字的查询-
mysql> select cast(replace(replace('You_can_remove_the_string_part_only-10001-But_You_can_not_remove_the_numeric_parts','You_can_remove_the_string_part_only-',''),
'-But_You_can_not_remove_the_numeric_parts','') as unsigned) as Output from DemoTable1961;这将产生以下输出-
+--------+ | Output | +--------+ | 10001 | +--------+ 1 row in set (0.00 sec)
热门推荐
7 带清的简短祝福语
10 祝女性生日祝福语简短
11 工厂祝福语简短的句子
12 祝福语怎么写大全简短
13 写给男生简短的祝福语
14 送灯祝福语简短独特
15 医生节蛋糕祝福语简短
16 形容新年的祝福语简短
17 比赛结束花束祝福语简短
18 发小结婚简短祝福语