使用IN()仅获取MySQL存储过程中的特定记录?
让我们首先创建一个表-
mysql> create table DemoTable2004 ( UserId varchar(20), UserName varchar(20) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable2004 values('John_123','John'); mysql> insert into DemoTable2004 values('23456_Carol','Carol'); mysql> insert into DemoTable2004 values('111_Bob','Bob');
使用select语句显示表中的所有记录-
mysql> select * from DemoTable2004;
这将产生以下输出-
+-------------+----------+ | UserId | UserName | +-------------+----------+ | John_123 | John | | 23456_Carol | Carol | | 111_Bob | Bob | +-------------+----------+ 3 rows in set (0.00 sec)
这是创建存储过程并仅选择具有IN()
-的特定记录的查询
mysql> delimiter // mysql> create procedure test_of_in(IN uId varchar(20)) BEGIN select * from DemoTable2004 where UserId IN(uId); END // mysql> delimiter ; Call the stored procedure: mysql> call test_of_in('23456_Carol');
这将产生以下输出-
+-------------+----------+ | UserId | UserName | +-------------+----------+ | 23456_Carol | Carol | +-------------+----------+ 1 row in set (0.00 sec)