MySQL 过程使用 SELECT 返回整个表
mysqlmysqli database更新于 2024/12/8 1:16:17
首先我们创建一个表 −
mysql> create table DemoTable1971 ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(20), StudentPassword int ); Query OK, 0 rows affected (0.00 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable1971(StudentName,StudentPassword) values('John','123456');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1971(StudentName,StudentPassword) values('Chris','123456');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1971(StudentName,StudentPassword) values('David','123456');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1971(StudentName,StudentPassword) values('Mike','123456');
Query OK, 1 row affected (0.00 sec)
使用 select 语句显示表中的所有记录 −
mysql> 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)
这是创建存储过程的查询 −
mysql> delimiter // mysql> create procedure returnAll(pass varchar(30)) begin select * from DemoTable1971 where StudentPassword=pass; end // Query OK, 0 rows affected (0.00 sec) mysql> delimiter ;
现在您可以使用 CALL 命令调用存储过程 −
mysql> 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) Query OK, 0 rows affected, 1 warning (0.00 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

