DB2在函数中同时对多个变量赋值(例子)
代码
CREATE FUNCTION GDZJ.GETREPORTIDBYBZKEY
(BZKEY INTEGER
)
RETURNS VARCHAR(21)
LANGUAGE SQL
NOT DETERMINISTIC
READS SQL DATA
STATIC DISPATCH
CALLED ON NULL INPUT
EXTERNAL ACTION
INHERIT SPECIAL REGISTERS
begin atomic
declare sResult VARCHAR(21) default '';
declare mtId integer default 0;
declare spMtId integer default 0;
set (mtId,spMtId)=(select COALESCE(MT_ID,0),COALESCE(SP_MT_ID,0) from T_BZ_BZBHGCPCL_INFO where AUTO_ID=BZKEY);
set sResult=char(mtId)||'+'||char(spMtId);
return sResult;
end;
(BZKEY INTEGER
)
RETURNS VARCHAR(21)
LANGUAGE SQL
NOT DETERMINISTIC
READS SQL DATA
STATIC DISPATCH
CALLED ON NULL INPUT
EXTERNAL ACTION
INHERIT SPECIAL REGISTERS
begin atomic
declare sResult VARCHAR(21) default '';
declare mtId integer default 0;
declare spMtId integer default 0;
set (mtId,spMtId)=(select COALESCE(MT_ID,0),COALESCE(SP_MT_ID,0) from T_BZ_BZBHGCPCL_INFO where AUTO_ID=BZKEY);
set sResult=char(mtId)||'+'||char(spMtId);
return sResult;
end;