什麼是 MySQL 儲存函數以及如何建立它們?

WBOY
發布: 2023-08-24 21:57:02
轉載
921 人瀏覽過

什么是 MySQL 存储函数以及如何创建它们?

MySQL stored function is basically a special kind of stored program that returns a single value. We can use stored functions in MySQL to encapsulate mainly simple formulas orbus encapsulates . among SQL statements or stored programs. Other than that stored functions are used in SQL statements whenever an expression is used.

This feature of stored functions is different from store procedures .alt. IN parameter of the stored procedure as the functions use RETURN keyword to determine what is passed back. Its syntax can be as follows −

Syntax

CREATE
   [DEFINER = { user | CURRENT_USER }]
   FUNCTION sp_name ([func_parameter[,...]])
   RETURNS type
   [characteristic ...] routine_body

func_parameter:
   param_name type

type:
   Any valid MySQL data type

characteristic:
   COMMENT 'string'
 | LANGUAGE SQL
 | [NOT] DETERMINISTIC
 | { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
 | SQL SECURITY { DEFINER | INVOKER }

routine_body:
   Valid SQL routine statement
登入後複製

函數只有輸入參數和傳回值,因此在輸入參數和傳回值函數定義中必須有一個RETURNS子句來指示傳回值的資料型態。此外,在函數體內必須至少有一個RETURN語句來將值傳回給呼叫者。

以上是什麼是 MySQL 儲存函數以及如何建立它們?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:tutorialspoint.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!