MYSQL common built-in functions and custom functions

Source: Internet
Author: User

MySQL built-in functions:

    • Character functions
    • numeric functions
    • Time-Date function

Common use of numeric functions:

1 Select avg  from Tdb_goods;  Find the average of field values

Built-in summation functions:
1 Select sum  from Tdb_goods; To find the value of the field and

  

    • Examples of common date functions
    • 1 Select

    • 1 Select current_timestamp();

User-defined functions:

    • Grammar
20.2.1.CREATEProcedure and createFUNCTIONCREATE PROCEDURESp_name ([proc_parameter[,...]])    [characteristic ...]Routine_bodyCREATE FUNCTIONSp_name ([func_parameter[,...]])    RETURNStype[characteristic ...]routine_body Proc_parameter:[In | Out | INOUT]param_name type Func_parameter:param_name type type: anyvalid MySQL data type Characteristic:language SQL| [ not]Deterministic|{CONTAINSSql|NO SQL|READS SQL DATA|modifies SQL DATA}|SQL SECURITY {Definer|INVOKER}|COMMENT'string'routine_body:valid SQLprocedureStatementorStatements
    • A simple summation function
    • 1 Create function sum int int )2returnsint3return (num1+num2)/  2;

If a custom function contains a compound statement, you will use begin. End statement.

1 [Begin_label:] BEGIN 2     [statement_list] 3   END [end_label]

//

The storage subroutine can use the begin ... End Compound statement to contain multiple statements. statement_list represents a list of one or more statements. Each statement within Statement_list must be terminated with a semicolon (;).

Compound statements can be marked. Unless Begin_label exists, End_label cannot be given, and if both exist, they must be the same.

Note that the optional [NOT] atomic clause is not currently supported. This means that a storage point that has no interaction at the beginning of the instruction block is set, and the BEGIN clause used in the context has no effect on the current interaction action.

Using multiple statements requires the client to send a query string containing the statement delimiter; This symbol is handled by the command line client with the delimiter command. Change the end of the query delimiter; (e.g. change to//) make; Can be used in the subroutine body.

MYSQL common built-in functions and custom functions

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.