Mysql Stored Programs

本文介绍了MySQL中的存储程序概念,包括存储过程、触发器和事件等。详细解释了存储过程的创建、查看及删除方法,并提供了具体的示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[size=medium]
[b]1.Stored programs include these objects:[/b]
a).Stored routines, that is, stored procedures and functions. A stored procedure is invoked using the CALL statement. A procedure does not have a return value but can modify its parameters for later inspection by the caller. It can also generate result sets to be returned to the client program. A stored function is used much like a built-in function. you invoke it in an expression and it returns a value during expression evaluation.

b).Triggers. A trigger is a named database object that is associated with a table and that is activated when a particular event occurs for the table, such as an insert or update.

c).Events. An event is a task that the server runs according to schedule.

[b]2.Defining Stored Programs[/b]
Each stored program contains a body that consists of an SQL statement. This statement may be a compound statement made up of several statements separated by semicolon (;) characters.
[/size]

CREATE PROCEDURE dorepeat(p1 INT)
BEGIN
SET @x = 0;
REPEAT SET @x = @x + 1; UNTIL @x > p1 END REPEAT;
END;


[size=medium]
Stored routines require the proc table in the mysql database.


[b]mysql stored procedure[/b]
[b]1.创建[/b]
delimiter //
create procedure calcal(actId int)
begin
#do something
end;
//
delimiter ;

[b]2.查看[/b]
方法一:
select `name` from mysql.proc where db = 'your_db_name' and `type` = 'PROCEDURE'

方法二:
show procedure status;

[b]3.删除[/b]
drop procedure db_name.sp_name;[/size]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值