Mysql stored procedures use the select... into statement to assign values to variables.

Source: Internet
Author: User
In the MySQL stored procedure, you can use SELECT... The INTO statement is used to assign a variable. The statement is queried in the database and the obtained result is assigned to the variable. SELECT... The syntax of the INTO statement is as follows: SELECTcol_name [,...] INTO var_name [,...] table_expr code: createproceduregetMsg () Begindec

In the MySQL stored procedure, you can use SELECT... The INTO statement is used to assign a variable. The statement is queried in the database and the obtained result is assigned to the variable. SELECT... The syntax of the INTO statement is as follows: SELECT col_name [,...] INTO var_name [,...] table_expr code: create procedure getMsg () Begin dec

In the MySQL stored procedure, you can use SELECT... The INTO statement assigns a value to the variable, queries the variable in the database, and assigns the obtained result to the variable. SELECT... The syntax format of the INTO statement is as follows:

SELECT col_name [,...] INTO var_name [,...] table_expr

The Code is as follows: create procedure getMsg () Begin declare v_title varchar (30); declare v_content varchar (100); select title, content into v_title, v_content from news where artId = 333; End

Return the variable value to the caller.

After processing the variables defined in the stored procedure, the result value may be returned to the stored procedure caller. So how to return? It is convenient to use the SELECT statement to return the variables as the result set. Therefore, add the following sentence based on the preceding code:

create procedure getMsg ()  Begin   declare v_title varchar(30);    declare v_content varchar(100);    select title,content into v_title,v_content from news where artId=333;    select v_title,v_content;  End
In this way, call getMsg (); after the stored procedure is called, the information is output on the console.

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.