在 MySQL 中從儲存過程中顯示資料表記錄
我們首先建立一個表 −
mysql> create table DemoTable1933 ( ClientName varchar(20) ); Query OK, 0 rows affected (0.00 sec)
使用 insert 命令在表中插入一些記錄 −
mysql> insert into DemoTable1933 values('Chris Brown');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1933 values('David Miller');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1933 values('Adam Smith');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1933 values('John Doe');
Query OK, 1 row affected (0.00 sec)使用 select 語句顯示錶中的所有記錄 −
mysql> select * from DemoTable1933;
這將產生以下輸出 −
+--------------+ | ClientName | +--------------+ | Chris Brown | | David Miller | | Adam Smith | | John Doe | +--------------+ 4 rows in set (0.00 sec)
這是用於建立儲存過程並在其中設定 SELECT 以顯示記錄的查詢 −
mysql> delimiter // mysql> create procedure display_all_records() begin select * from DemoTable1933; end // Query OK, 0 rows affected (0.00 sec) mysql> delimiter ;
現在,可以使用 call 命令呼叫儲存過程
mysql> call display_all_records();
這將產生以下輸出 −
+--------------+ | ClientName | +--------------+ | Chris Brown | | David Miller | | Adam Smith | | John Doe | +--------------+ 4 rows in set (0.00 sec) Query OK, 0 rows affected (0.00 sec)
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP