1. 程式人生 > >mysql儲存過程接收動態sql返回值

mysql儲存過程接收動態sql返回值

一、今天需要用到mysql儲存過程接受動態sql的返回值,特此做以下記錄

二、具體如下

-- BS追加公能欄位 獲取型別和公能分組ID

declare vPartName,vType,vSql,vId varchar(100);
declare vPartGroupId int;
set vPartName = params->>'$.partName';
set vSql = concat('select id into @vId from part where partName = \'',vPartName,'\';');
set @ms=vSql;
PREPARE s1 from @ms;
EXECUTE s1;
set vId = @vId;
if vId is not null then
set vType = 'table';
else
set vType = 'stoproc';
end if;
select id into vPartGroupId from part where partName = vPartName;
select vType,vPartGroupId;