MySql存储过程

创建简单的存储过程

CREATE PROCEDURE pro_get_sal()
BEGIN
  SELECT stu_name,salary FROM student;
END

CALL pro_get_sal()
创建一个存储过程,通过传入一个id和一个name参数,可以根据所传入的id值来更改name
CREATE PROCEDURE pro_stu3(in i int,in names VARCHAR(20))
BEGIN
UPDATE student1 set name = names WHERE id=i;
END
CALL pro_stu3(2,'王组')

删除该存储过程

DROP PROCEDURE pro_stu3;
声明变量
CREATE PROCEDURE pro_stu2()
BEGIN
DECLARE a int; -- 声明变量
set a = 10;  -- 设置变量
SELECT a;
END

CALL pro_stu2()
SELECT INTO
CREATE PROCEDURE pro_stu4()
BEGIN
DECLARE names VARCHAR(20);
SELECT name into names from student1 WHERE id = 1;
SELECT NAMES;
END

DROP PROCEDURE pro_stu4;

CALL pro_stu4()

你可能感兴趣的:(MySql存储过程)