DB2 的function中使用游标
今天在开发的过程用需要写一个function,从一张表里去多条值,让后将其拼接成一个字符串进行返回。刚开始用游标写,死活都不行,老是报错。最后采取下面的方法:Foras
Do
End for;
create functiongetGuarantyInfo("BCSERIALNO" varchar(40))
Returns varchar(40)
LANGUAGE SQL
begin ATOMIC Declare sReturn varchar(10) Default '';
For v_curas (select getItemName('GuarantyType',GuarantyType) as GuarantyType,GuarantorName as GuarantyName from GUARANTY_CONTRACT where SerialNo in (Select ObjectNo from Contract_RELATIVE where SerialNo=BCSERIALNO and ObjectType = 'GuarantyContract'))
Do
set sReturn=v_cur.GuarantyType||'-'||v_cur.GuarantyName||';'||sReturn;
End for;
return sReturn;
end
结果行了,不过现在还不了解这叫什么东西呢
页:
[1]