让我们首先创建一个表-
mysql> create table DemoTable -> ( -> Name varchar(20) -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('Chris Brown'); mysql> insert into DemoTable values('Adam Smith'); mysql> insert into DemoTable values('John Smith'); mysql> insert into DemoTable values('Carol Smith');
使用select语句显示表中的所有记录-
mysql> select * from DemoTable;
这将产生以下输出-
+-------------+ | Name | +-------------+ | Chris Brown | | Adam Smith | | John Smith | | Carol Smith | +-------------+ 4 rows in set (0.00 sec)
以下是实现SELECT LIKE和CHAR_LENGTH的查询-
mysql> select * from DemoTable -> where Name LIKE '%Smith%' -> and char_length(Name) < 11;
这将产生以下输出-
+------------+ | Name | +------------+ | Adam Smith | | John Smith | +------------+ 2 rows in set (0.00 sec)