1000 Lines MySQL study notes (11)

Source: Internet
Author: User
Tags mixed

--//storage functions, custom functions----------

--New
CREATE FUNCTION function_name (argument list) RETURNS return value type
function Body

-the function name, which should be a valid identifier, and should not conflict with an existing keyword.
-a function should belong to a database, you can use the form of Db_name.funciton_name to execute the database that the current function belongs to, otherwise the current database.
-The Parameters section, which consists of the parameter name and the parameter type. Multiple parameters are separated by commas.
-The function body consists of a number of available MySQL statements, flow control, variable declaration and other statements.
-Multiple statements should be contained using the BEGIN...END statement block.
-Be sure to have a return value statement.

--Delete
DROP FUNCTION [IF EXISTS] function_name;

--View
SHOW FUNCTION STATUS like ' Partten '
SHOW CREATE FUNCTION function_name;

--Modify
ALTER function function_name option


--//stored procedures, custom features----------

--Definition
A stored procedure is a piece of code (procedure) that is composed of SQL stored in a database.
A stored procedure is typically used to complete a business logic, such as registration, handover fees, order warehousing, etc.
while a function is usually focused on a function, as other program services, you need to call the function in other statements, and the stored procedure cannot be called by others, it is executed by call.

--Create
CREATE PROCEDURE sp_name (parameter list)
Process Body

parameter list: Different from the parameter list of the function, you need to indicate the parameter type
in, indicates input type
out, indicating the output type
INOUT, indicating mixed type

Note that there is no return value.

/ * Stored procedure */------------------
A stored procedure is a collection of executable code. The business logic is more biased than the function.
Invocation: Call Procedure name
--Note
-no return value.
-can only be called separately and cannot be mixed in other statements

--Parameters
in| Out| INOUT parameter name data type
In input: During invocation, data is entered into parameters inside the procedure body
Out output: Returns the result of process body processing to the client during the call process
INOUT input and output: can be input or output

--Grammar
CREATE PROCEDURE Procedure name (parameter list)
BEGIN
Process Body
END

(not to be continued)

(Shocker Source: http://www.cnblogs.com/shockerli/p/1000-plus-line-mysql-notes.html)

1000 Lines MySQL study notes (11)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.