MySQL语法模板 SQL语句:函数、存储过程

  1. 创建函数
CREATE FUNCTION sp_name ([func_parameter[,...]])
    RETURNS type
    [characteristic ...]
 routine_body

characteristic:
    LANGUAGE SQL
  | [NOT] DETERMINISTIC
  | { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
  | SQL SECURITY { DEFINER | INVOKER }
  | COMMENT 'string'
  1. 创建存储过程

CREATE PROCEDURE sp_name ([proc_parameter[,...]])
    [characteristic ...]
 routine_body
characteristic:
    LANGUAGE SQL
  | [NOT] DETERMINISTIC
  | { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
  | SQL SECURITY { DEFINER | INVOKER }
  | COMMENT 'string'


  1. 修改函数
ALTER FUNCTION sp_name [characteristic ...]
 
characteristic:
    { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
  | SQL SECURITY { DEFINER | INVOKER }
  | COMMENT 'string'
  1. 修改存储过程
ALTER PROCEDURE sp_name [characteristic ...]
 
characteristic:
    { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
  | SQL SECURITY { DEFINER | INVOKER }
  | COMMENT 'string'

  1. 调用
CALL sp_name([parameter[,...]])
  1. 删除函数
DROP FUNCTION [IF EXISTS] sp_name
  1. 删除存储过程
DROP PROCEDURE [IF EXISTS] sp_name
    原文作者:liuawei
    原文地址: https://www.jianshu.com/p/d53364ff74ae
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞