让我们首先创建一个表-
mysql> create table DemoTable ( UserName varchar(100) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('Smith_John'); mysql> insert into DemoTable values('Smith_Adam'); mysql> insert into DemoTable values('Smith_David'); mysql> insert into DemoTable values('Smith_Mike');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-------------+ | UserName | +-------------+ | Smith_John | | Smith_Adam | | Smith_David | | Smith_Mike | +-------------+ 4 rows in set (0.00 sec)
以下是在下划线后仅显示字符串部分的查询-
mysql> update DemoTable set UserName=substring(UserName,7) where UserName LIKE 'Smith_%'; Rows matched: 4 Changed: 4 Warnings: 0
让我们再次检查表记录-
mysql> select *from DemoTable;
这将产生以下输出-
+----------+ | UserName | +----------+ | John | | Adam | | David | | Mike | +----------+ 4 rows in set (0.00 sec)