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.