今天再次添补一下小小内容,闲话不多说,直入标题。
先来看下,如何创建带参数的 存储过程(ps:本文只限mysql5及以上版本)
CREATE PROCEDURE prSaveFileInfo
(
TableName1 VARCHAR(64),
FileName1 VARCHAR(50),
FileType1 bigint,
Category1 bigint,
ProtocalVersion1 bigint,
FileCreationTime1 VARCHAR(50),
DeviceID1 bigint,
FileSN1 bigint,
StateFlag1 bigint
)
BEGIN
DECLARE strSQL VARCHAR(2048);
SET strSQL = concat(' insert into ',TableName1,'(FileName, FileType, Category, ProtocalVersion,
FileCreationTime, DeviceID, FileSN, StateFlag)
values("',FileName1,'"',',',FileType1,',',Category1,',',ProtocalVersion1,',','"',FileCreationTime1,'"',',',DeviceID1,',',FileSN1,',',StateFlag1,')');
set @v_sql=strSQL;
prepare stmt from @v_sql;
execute stmt;
END;
注意:这里的sql拼接,请用concat() 函数来连接,否则后续传参进来,会报 1292-Truncate Double value 错误。
我们再来看看调用这个procedure吧,很简单,就一句话:
call prSaveFileInfo('TestDemoTable1', 'test1', 1, 2, 1, '2010-12-07 13:11:23', 1, 2, 1);
OK,大功告成。