存储过程的创建使用
标签:存储,name,user1,--,show,delimiter,Mysql,设计,out From: https://www.cnblogs.com/188221creat/p/17997647
-- 复制 world.`user`所在库的表,复制名为 user1
CREATE TABLE user1
as SELECT * from world.`user`
DELETE from user1
-- 存储过程
delimiter $
CREATE PROCEDURE select_all_user1()
BEGIN
SELECT * from user1 ;
END $
delimiter ;
-- 存储过程调用
call select_all_user1();
-- 带输出参数的触发器设计调用
delimiter //
CREATE PROCEDURE show_min_salary(OUT ms INT)
BEGIN
SELECT MIN(age) INTO ms
FROM user1;
end //
delimiter ;
-- 调用带参数的存储过程
CALL show_min_salary(@ms);
-- 查看变量
SELECT @ms;
DESC user1
-- 传入参数返回对应参数的查询条件
delimiter //
CREATE PROCEDURE show_some_age(in name_in varchar(255))
BEGIN
select phone from user1 where name = name_in;
END //
delimiter ;
-- 调用in类型的触发器方式1
call show_some_age('小明');
-- 调用in类型的触发器方式2
set @name_in:='小明';
call show_some_age(@name_in);
-- 同时调用in ,OUT
delimiter //
CREATE PROCEDURE show_in_out_user(in name_in varchar(255),out phone_out varchar(255))
BEGIN
SELECT phone INTO phone_out from user1 where name = name_in;
end //
delimiter ;
set @name_in ='小明';
call show_in_out_user(@name_in,@phone_out);
select @phone_out;