I was trying to create a user defined function in DB2. I was not able to create the function and was getting few errors. Please find the code and the error message.
CREATE FUNCTION DESC_FUNC(v_rpt_id integer, v_desc_typ_cde varchar(1))
DECLARE v_desc VARCHAR(32672) default '';
for1: BEGIN ATOMIC
FOR tmp_row AS
"t_flt_sfty_desc DES","t_flt_sfty_rpt rptin1"
AND DES.RPT_EVNT_ORD_NUM = rptin1.RPT_EVNT_ORD_NUM
AND DES.RPTEE_TYP_CDE = rptin1.RPTEE_TYP_CDE
AND DES.View_typ_cde = 'D'
AND desc_typ_cde = v_desc_typ_cde
AND rpt_id= v_rpt_id
ORDER BY desc_seq_num
IF desc_seq_num =1 THEN
SET v_desc = tmp_row.evnt_desc_txt;
SET v_desc = v_desc ||tmp_row.evnt_desc_txt;
END FOR for1;
I got the following error message
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0104N An unexpected token "V_DESC" was found following "". Expected
tokens may include: "ON AFTER <INTEGER>". SQLSTATE=42601