MySQL过程与SELECT一起返回整个表
让我们首先创建一个表-
create table DemoTable1971 ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(20), StudentPassword int );
使用插入命令在表中插入一些记录-
insert into DemoTable1971(StudentName,StudentPassword) values('John','123456');
insert into DemoTable1971(StudentName,StudentPassword) values('Chris','123456');
insert into DemoTable1971(StudentName,StudentPassword) values('David','123456');
insert into DemoTable1971(StudentName,StudentPassword) values('Mike','123456');使用select语句显示表中的所有记录-
select * from DemoTable1971;
这将产生以下输出-
+-----------+-------------+-----------------+ | StudentId | StudentName | StudentPassword | +-----------+-------------+-----------------+ | 1 | John | 123456 | | 2 | Chris | 123456 | | 3 | David | 123456 | | 4 | Mike | 123456 | +-----------+-------------+-----------------+ 4 rows in set (0.00 sec)
这是创建存储过程的查询-
delimiter // create procedure returnAll(pass varchar(30)) begin select * from DemoTable1971 where StudentPassword=pass; end // delimiter ;
现在您可以使用CALL命令调用存储过程-
call returnAll('123456');这将产生以下显示整个表的输出-
+-----------+-------------+-----------------+ | StudentId | StudentName | StudentPassword | +-----------+-------------+-----------------+ | 1 | John | 123456 | | 2 | Chris | 123456 | | 3 | David | 123456 | | 4 | Mike | 123456 | +-----------+-------------+-----------------+ 4 rows in set (0.00 sec)
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短