Parameters stored procedure

Incoming parameters

For chestnut: The id name search parameters: myid, java similarly defined manner and the function, in variable type variable name;

CREATE  PROCEDURE teste(in myid int)
BEGIN
declare myname VARCHAR(10) default '';
select pname into myname from person where pid =myid;
select myname;
end

When invoked directly call teste (2);

 

Came out parameter type variable name

CREATE  PROCEDURE teste(in myid int,out myname varchar(10))
BEGIN
select pname into myname from person where pid =myid;
end

Call, when the need to pass parameters, you need to set the incoming parameters, you can initialize it to receive a return value. And used as a parameter to the function

set @pname := '';
call teste(2,@pname);
select @pname;

 

There are some parameters is incoming or outgoing parameters, defined by the inout

CREATE  PROCEDURE `teste`(inout myname varchar(10))
BEGIN
select CONCAT((select pname from person where pname = myname),"_来自地球") into myname;
end

Call as follows:

The name can be found after the inclusion of such strings from Earth. Of course, typically stored during operation can do more.

 

Guess you like

Origin www.cnblogs.com/liuyongbo/p/11002969.html