DELIMITER //
DROP PROCEDURE IF EXISTS helloworld//
CREATE PROCEDURE helloworld()
BEGIN
SELECT 'Hello World' AS F;
END
//
DELIMITER;
CALL helloworld
DELIMITER //
DROP PROCEDURE IF EXISTS testadd//
CREATE PROCEDURE testadd(a INT, b INT)
BEGIN
DECLARE c INT;
IF a IS NULL THEN
SET a=0;
END IF;
IF b IS NULL THEN
SET b=0;
END IF;
SET c=a+b;
SELECT c AS SUM;
END
//
DELIMITER;
CALL testadd(10, 20)
SHOW PROCEDURE STATUS
SHOW CREATE PROCEDURE testadd
DELIMITER //
DROP PROCEDURE IF EXISTS querysong//
CREATE PROCEDURE querysong(IN id INT, OUT total INT)
BEGIN
SELECT COUNT(*) FROM songs WHERE songid=id
INTO total;
END
CALL querysong(12979290,@total);
SELECT @total
//
DELIMITER;
MySql存储过程小试牛刀
最新推荐文章于 2024-10-31 23:41:03 发布