MySQL存储过程不会获取整个表?
您可以在存储过程中使用SELECT*FROMyourTableName。让我们首先创建一个表-
mysql> create table DemoTable654 ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,StudentFirstName varchar(100) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable654(StudentFirstName) values('John'); mysql> insert into DemoTable654(StudentFirstName) values('Sam'); mysql> insert into DemoTable654(StudentFirstName) values('Mike'); mysql> insert into DemoTable654(StudentFirstName) values('Robert');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable654;
这将产生以下输出-
+-----------+------------------+ | StudentId | StudentFirstName | +-----------+------------------+ | 1 | John | | 2 | Sam | | 3 | Mike | | 4 | Robert | +-----------+------------------+ 4 rows in set (0.00 sec)
以下是使用存储过程获取整个表的记录的查询-
mysql> DELIMITER // mysql> CREATE PROCEDURE getWholeTable() BEGIN SELECT *FROM DemoTable654; END // mysql> DELIMITER ;
现在您可以使用调用命令来调用上述存储过程-
mysql> call getWholeTable();
这将产生以下输出-
+-----------+------------------+ | StudentId | StudentFirstName | +-----------+------------------+ | 1 | John | | 2 | Sam | | 3 | Mike | | 4 | Robert | +-----------+------------------+ 4 rows in set (0.08 sec)