Home >Database >Mysql Tutorial >读书笔记-MySQL存储过程-存储函数_MySQL

读书笔记-MySQL存储过程-存储函数_MySQL

WBOY
WBOYOriginal
2016-06-01 13:26:381179browse

bitsCN.com

存储函数和存储过程不同的地方有以下几点:

1.函数的参数列表中模式只能为IN。

2.函数必须返回一个值,它的类型被定义于函数的头部

3.函数能被SQL语句所调用

4.函数可能不返回任何结果集

DELIMITER $$DROP FUNCTION IF EXISTS discount_price$$CREATE FUNCTION discount_price        normal_price NUMERIC(8, 2)        RETURN NUMERIC(8, 2)        DETERMINISTICBEGIN     DECLARE v_discount_price NUMERIC(8, 2);    IF (normal_price > 500) THEN        SET discount_price = normal_price * .8;    ELSE IF (normal_price > 1000) THEN         SET discount_price = normal_price * .9;    ELSE         SET discount_price = normal_price;    END IF;    RETURN (discount_price);END$$

bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn