您可以使用create procedure命令創建存儲過程。語法如下 ?
delimiter // CREATE PROCEDURE yourStoreProcedureName() BEGIN Declare variable here The query statement END // delimiter //
登錄后復制
將上述語法應用于創建存儲過程。查詢如下 −
mysql> use test; Database changed mysql> delimiter // mysql> create procedure Sp_callTableStoredProcTable() −> begin −> select *from StoredProcTable; −> end // Query OK, 0 rows affected (0.54 sec)
登錄后復制
Now you need to change the delimiter with ; to call stored procedure −
mysql> delimiter ;
登錄后復制
You can call stored procedure using CALL command. The syntax is as follows −
CALL yourStoredProcedureName();
登錄后復制
The above stored procedure can be called using CALL command as shown in the below query −
mysql> call Sp_callTableStoredProcTable();
登錄后復制
以下是輸出 −
+-----------+------+ | FirstName | Age | +-----------+------+ | John | 23 | | Bob | 24 | | David | 20 | +-----------+------+ 3 rows in set (0.03 sec) Query OK, 0 rows affected (0.06 sec)
登錄后復制
在上面,我們使用了表格 ‘StoredProcTable’,這個表格有三條記錄。使用存儲過程顯示了所有記錄。
您可以使用存儲過程檢查表格中有多少條記錄 –
mysql> delimiter // mysql> create procedure CountingRecords() −> begin −> select count(*) as AllRecords from StoredProcTable; −> end // Query OK, 0 rows affected (0.19 sec) mysql> delimiter ;
登錄后復制
Call the stored procedure using CALL command. The query is as follows −
mysql> call CountingRecords();
登錄后復制
以下輸出顯示記錄的計數 −
+------------+ | AllRecords | +------------+ | 3 | +------------+ 1 row in set (0.31 sec) Query OK, 0 rows affected (0.33 sec)
登錄后復制
以上就是在MySQL中創建帶分隔符的存儲過程的詳細內容,更多請關注www.92cms.cn其它相關文章!