1.定义存储过程PROCEDURE或函数FUNCTION时,参数列表中的参数是大小写不敏感的。

2.定义存储过程PROCEDURE时参数属性默认是IN,即是“输入参数”。除非标注OUT或者INOUT。注意对于函数FUNCTION的参数只能够为IN,不允许标注OUTINOUT

3.对于存储过程中参数的三种标注:

IN:相当于传值引用的输入参数。由调用者提供值。在存储过程中改变该参数不影响调用者;

OUT:相当于返回值。在存储过程中初值为NULL,需要在存储过程返回时返回给调用者。

INOUT:相当于传址引用的输入参数。由调用者提供初值。在存储过程中改变该参数能够在存储过程返回时更新原始值。


附MySQL5.5帮助摘记:(? CREATE PROCEDURE)

笔者英语水平有限,翻译仅帮助不想看英文的同学,大神勿吐槽。

...

Parameter names are not case sensitive.

参数是大小写不敏感的。


Each parameter is an IN parameter by default. To specify otherwise for

a parameter, use the keyword OUT or INOUT before the parameter name.

参数列表中的参数默认为“IN”参数。需要指定其他类型的参数,可以是使用“OUT”和“INOUT”声明。


*Note*: Specifying a parameter as IN, OUT, or INOUT is valid only for a

PROCEDURE. For a FUNCTION, parameters are always regarded as IN

parameters.

*注意*:”指定参数类别为‘IN’、‘OUT’和‘INOUT’“这一行为仅对于存储过程有效。在存储函数中所有参数都被认为是”IN"类别的。


An IN parameter passes a value into a procedure. The procedure might

modify the value, but the modification is not visible to the caller

when the procedure returns. An OUT parameter passes a value from the

procedure back to the caller. Its initial value is NULL within the

procedure, and its value is visible to the caller when the procedure

returns. An INOUT parameter is initialized by the caller, can be

modified by the procedure, and any change made by the procedure is

visible to the caller when the procedure returns.

IN类别的参数向存储过程传入参数。存储过程可能修改这个参数的值,但这种修改在存储过程返回时对调用者不可见。

OUT类别的参数负责返回一个结果给调用者。OUT类别的参数在存储过程中的值默认为NULL(笔者注:即使传入的参数值不为NULL),并且在存储过程返回时,对其的修改对调用者可见。

INOUT类别的参数由调用者传入的值初始化,并且在存储过程返回时,对其的调用者可见。


For each OUT or INOUT parameter, pass a user-defined variable in the

CALL statement that invokes the procedure so that you can obtain its

value when the procedure returns. If you are calling the procedure from

within another stored procedure or function, you can also pass a

routine parameter or local routine variable as an IN or INOUT

parameter.

对于每个OUTINOUT类别的参数,如果在调用时传入的是用户定义变量(笔者注:定义时以@开头),在调用存储过程返回时,调用者能够获得其修改的值。

当在其他存储过程或存储函数中调用此存储过程,你同样能够将一个局部变量作为ININOUT类别的参数传入此存储过程。


...    更多细节可参见MySQL在线文档http://dev.mysql.com/doc/