在mysql中创建带分隔符的存储过程

你可使用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 co妹妹and. The syntax is as follows −

CALL yourStoredProcedureName();
登录后复造

The above stored procedure can be called using CALL co妹妹and as shown in the below query −

mysql> call Sp_callTableStoredProcTable();
登录后复造

下列是输入 −

+-----------+------+
| FirstName | Age  |
+-----------+------+
| John      | 两3   |
| Bob       | 两4   |
| David     | 两0   |
+-----------+------+
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 co妹妹and. 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外建立带分隔符的存储历程的具体形式,更多请存眷萤水红IT仄台此外相闭文章!

点赞(5) 打赏

评论列表 共有 0 条评论

暂无评论

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部