MySQL variable definition and assignment during storage

Source: Internet
Author: User
Tags mysql injection

MySQL variable definition and assignment are common problems. The following describes how to define and assign values to MySQL variables during storage, I hope you can learn more about MySQL variable definition.

I. MySQL variable definition

Mysql variable definition uses declare to define a local variable. The definition and value assignment operations of variables in mysql stored procedures can only be performed in begin... used in the end block, the variable must be defined at the beginning of the composite statement, and prior to other statements, expr is the value or return value expression, so that any MySQL-supported Return Value expression can be used. You can assign values to multiple variables at a time, or declare multiple variables at a time. If you want to assign a default value, you can use default.

The syntax for defining a MySQL variable is as follows:
Declare var_name [,...] type [default value] to view a variable definition instance
Declare last date;

Ii. mysql Stored Procedure variable assignment

You can directly assign values to variables or assign values to queries. You can directly assign values to set variables. constants or expressions are supported as follows:
Set var_name = [, var_name expr]...

The method for assigning values to the above last variable is as follows:
Set last = date_sub (current_date (), interval 1 month );

The following describes how to assign a value to a variable through a query. The result returned by the query must be a row. The specific operations are as follows:
Select col into var_name [,...] table_expr.
Create function get _ cost (p_custid int, p_eff datetime)
Return decimal (5, 2)
Deterministic
Reads SQL data
Begin
Declare v_pay decimail (5, 2 );
Select ifnull (sum (pay. amount), 0) into vpay from payment where pay. payd <= p_eff and pay. custid = pid
Reutrn v_rent + v_over-v_pay;
End $

Now, this simple tutorial on variable definition assignment in the stored procedure is complete.

Detailed description of MySQL injection using variables

Usage of MySQL user Variables

Difference between NULL and MySQL NULL strings

In-depth study of MySQL result strings

Top 10 most noteworthy MySQL Variables


 

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.