MySQL字符串URL中的最后一个索引?
要获取最后一个索引,请使用MySQL的SUBSTRING_INDEX()函数。语法如下-
SELECT yourColumnName1,...N,SUBSTRING_INDEX(yourColumnName,’yourDelimiter’,-1)as anyVariableName from yourTableName;
为了理解上述语法,让我们创建一个表。创建表的查询如下
mysql> create table LastIndexString -> ( -> Id int, -> yourURL text -> );
使用INSERT命令在表中插入一些记录。查询如下-
mysql> insert into LastIndexString values(1,'https −//www.example.com/home.html'); mysql> insert into LastIndexString values(2,'https −//exampledemo.example.com/index.jsp'); mysql> insert into LastIndexString values(3,'https −//www.example.com/question/LastString');
使用SELECT语句显示表中的所有记录。查询如下-
mysql> select *from LastIndexString;
以下是显示URL字符串的输出-
+------+---------------------------------------------+ | Id | yourURL | +------+---------------------------------------------+ | 1 | https −//www.example.com/home.html | | 2 | https −//exampledemo.example.com/index.jsp | | 3 | https −//www.example.com/question/LastString| +------+---------------------------------------------+ 3 rows in set (0.00 sec)
这是从URL字符串中获取最后一个索引字符串的查询-
mysql> select Id, substring_index(yourURL,'/',-1) as LastStringFromURL from LastIndexString;
以下是显示URL部分的输出-
+------+-------------------+ | Id | LastStringFromURL | +------+-------------------+ | 1 | home.html | | 2 | index.jsp | | 3 | LastString | +------+-------------------+ 3 rows in set (0.00 sec)
热门推荐
1 如何训练狗狗不叫
2 训练狗狗不叫
3 训练狗狗随行
4 怎么训练狗狗不叫
7 训练比熊狗狗教程
10 上海狗狗训练
11 怎么训练狗狗上厕所
12 训练狗狗趴下
13 狗狗服从训练
14 训练狗狗拒食
15 训练狗狗笑
16 训练狗狗大便
17 训练狗狗立
18 训练狗狗捡东西