DB2 创建存储过程保存:XX 后面找到异常标记 "END-OF-STATEMENT"。
阅读原文时间:2023年07月13日阅读:1

存储过程最后一行加结束符@:

然后执行:db2 -td@ -vf /home/WGJ/proc_data_calculate.sql

[slsadmin@localhost /]$ db2 -td@ -vf /home/WGJ/proc_data_calculate.sql
CREATE OR REPLACE PROCEDURE "SLSADMIN"."PROC_DATA_CALCULATE"
(
IN i_report_id VARCHAR(20),
IN i_report_date VARCHAR(20),
IN i_organ_id VARCHAR(20),
OUT o_msg varchar(32672),
OUT o_ret varchar(32672)
)
LANGUAGE SQL
SPECIFIC SQL140801094913965
RESULT SETS 2
BEGIN
DECLARE v_propotype_table CHAR(30);
DECLARE v_physical_table CHAR(50);
DECLARE v_temp_table CHAR(30);
DECLARE v_history_table CHAR(30);
DECLARE v_columns VARCHAR(4000);
declare sSql varchar(1000) ;
declare eSql varchar(32672);

 SELECT phy\_table, phy\_table||'\_'||substr(i\_report\_date, 5, 2)  
   INTO v\_propotype\_table,v\_temp\_table  
   FROM code\_rep\_report t  
  WHERE t.pkid = i\_report\_id;  
 --真心不会啊  
 IF v\_propotype\_table = 'rep\_dataf' THEN

 IF i\_report\_id = '' THEN  
  set v\_physical\_table = 'VIEW\_DATAF\_' || substr(i\_report\_date, 5, 2);  
  set  v\_history\_table  = 'wgj\_data\_submit\_info\_hist\_f';  
  set  v\_columns = 'ORGAN\_ID,REPORT\_ID,ITEM\_ID,REPORT\_DATE,ITEMVALUE1,ITEMVALUE2,ITEMVALUE21';  
 ELSE  
 SELECT phy\_table||'\_'||substr(i\_report\_date, 5, 2)||'\_0'  
   INTO v\_physical\_table  
   FROM code\_rep\_report t  
  WHERE t.pkid = i\_report\_id;  
  set  v\_history\_table  = 'wgj\_data\_submit\_info\_hist\_f';  
  set  v\_columns = 'ITEMVALUE63,ITEMVALUE64,ITEMVALUE65,ITEMVALUE66,ITEMVALUE67,ITEMVALUE68,ITEMVALUE69,ITEMVALUE7,ITEMVALUE70,ITEMVALUE71,ITEMVALUE72,ITEMVALUE73,ITEMVALUE74,ITEMVALUE75,ITEMVALUE76,ITEMVALUE77,ITEMVALUE78,ITEMVALUE79,ITEMVALUE8,ITEMVALUE80,ITEMVALUE9,ORGAN\_ID,REPORT\_DATE,REPORT\_ID,ITEMVALUE81,ITEMVALUE82,ITEMVALUE83,ITEMVALUE84,ITEMVALUE85,ITEMVALUE86,ITEMVALUE87,ITEMVALUE88,ITEMVALUE89,ITEMVALUE90,ITEMVALUE91,ITEMVALUE92,ITEMVALUE93,ITEMVALUE94,ITEMVALUE95,ITEMVALUE96,ITEMVALUE97,ITEMVALUE98,ITEMVALUE99,ITEMVALUE100,ITEMVALUE101,ITEMVALUE102,ITEMVALUE103,ITEMVALUE104,ITEMVALUE105,ITEMVALUE106,ITEMVALUE107,ITEMVALUE108,ITEMVALUE109,ITEMVALUE110,ITEMVALUE111,ITEMVALUE112,ITEMVALUE113,ITEMVALUE114,ITEMVALUE115,ITEMVALUE116,ITEMVALUE117,ITEMVALUE118,ITEMVALUE119,ITEMVALUE120,ITEMVALUE121,ITEMVALUE122,ITEMVALUE123,ITEMVALUE124,ITEMVALUE125,ITEMVALUE126,ITEMVALUE127,ITEMVALUE128,ITEMVALUE129,ITEMVALUE130,ITEMVALUE131,ITEMVALUE132,ITEMVALUE133,ITEMVALUE134,ITEMVALUE135,ITEMVALUE136,ITEMVALUE137,ITEMVALUE138,ITEMVALUE139,ITEMVALUE140,ITEM\_ID,ITEMVALUE1,ITEMVALUE10,ITEMVALUE11,ITEMVALUE12,ITEMVALUE13,ITEMVALUE14,ITEMVALUE15,ITEMVALUE16,ITEMVALUE17,ITEMVALUE18,ITEMVALUE19,ITEMVALUE2,ITEMVALUE20,ITEMVALUE21,ITEMVALUE22,ITEMVALUE23,ITEMVALUE24,ITEMVALUE25,ITEMVALUE26,ITEMVALUE27,ITEMVALUE28,ITEMVALUE29,ITEMVALUE3,ITEMVALUE30,ITEMVALUE31,ITEMVALUE32,ITEMVALUE33,ITEMVALUE34,ITEMVALUE35,ITEMVALUE36,ITEMVALUE37,ITEMVALUE38,ITEMVALUE39,ITEMVALUE4,ITEMVALUE40,ITEMVALUE41,ITEMVALUE42,ITEMVALUE43,ITEMVALUE44,ITEMVALUE45,ITEMVALUE46,ITEMVALUE47,ITEMVALUE48,ITEMVALUE49,ITEMVALUE5,ITEMVALUE50,ITEMVALUE51,ITEMVALUE52,ITEMVALUE53,ITEMVALUE54,ITEMVALUE55,ITEMVALUE56,ITEMVALUE57,ITEMVALUE58,ITEMVALUE59,ITEMVALUE6,ITEMVALUE60,ITEMVALUE61,ITEMVALUE62';

 END IF;

 ELSE  
 SELECT phy\_table||'\_'||substr(i\_report\_date, 5, 2)  
   INTO v\_physical\_table  
   FROM code\_rep\_report t  
  WHERE t.pkid = i\_report\_id;  
  set  v\_history\_table = 'wgj\_data\_submit\_info\_hist\_d';  
  set  v\_columns = 'ITEMVALUE38,ITEMVALUE39,ITEMVALUE40,ITEMVALUE41,ITEMVALUE42,ITEMVALUE43,ITEMVALUE44,ITEMVALUE45,ITEMVALUE46,ITEMVALUE47,ITEMVALUE48,ITEMVALUE49,ITEMVALUE50,ORGAN\_ID,REPORT\_DATE,REPORT\_ID,ITEM\_ID,ITEMVALUE1,ITEMVALUE2,ITEMVALUE3,ITEMVALUE4,ITEMVALUE5,ITEMVALUE6,ITEMVALUE7,ITEMVALUE8,ITEMVALUE9,ITEMVALUE10,ITEMVALUE11,ITEMVALUE12,ITEMVALUE13,ITEMVALUE14,ITEMVALUE15,ITEMVALUE16,ITEMVALUE17,ITEMVALUE18,ITEMVALUE19,ITEMVALUE20,ITEMVALUE21,ITEMVALUE22,ITEMVALUE23,ITEMVALUE24,ITEMVALUE25,ITEMVALUE26,ITEMVALUE27,ITEMVALUE28,ITEMVALUE29,ITEMVALUE30,ITEMVALUE31,ITEMVALUE32,ITEMVALUE33,ITEMVALUE34,ITEMVALUE35,ITEMVALUE36,ITEMVALUE37';  
 END IF;

 DELETE FROM wgj\_data\_submit\_info t WHERE t.report\_id =i\_report\_id and t.organ\_id=i\_organ\_id and t.report\_date=i\_report\_date;

 set eSql = 'INSERT INTO wgj\_data\_submit\_info  
   SELECT wgj\_data\_submit\_info\_seq.nextval pkid,  
          report\_id report\_id,  
          decode(flag,'''',''A'','''',''D'','''',''C'') operation\_type,  
          '''' remark,  
          organ\_id organ\_id,  
          report\_date report\_date,  
          item\_id item\_id  
     FROM (SELECT report\_id, organ\_id, report\_date, item\_id, SUM(d) flag  
             FROM (SELECT report\_id, organ\_id, report\_date, item\_id, 1 d  
                     FROM (SELECT ' || v\_columns || '  
                             FROM '||v\_physical\_table||' t  
                            WHERE t.report\_id = ' ||  
                   i\_report\_id || '  
                              AND t.report\_date = ''' ||  
                   i\_report\_date || '''  
                              AND t.organ\_id = ''' ||  
                   i\_organ\_id || '''  
                           except  
                           SELECT ' || v\_columns || '  
                             FROM ' ||  
                   v\_history\_table || ' f  
                            WHERE f.report\_id = ' ||  
                   i\_report\_id || '  
                              AND f.report\_date = ''' ||  
                   i\_report\_date || '''  
                              AND f.organ\_id = ''' ||  
                   i\_organ\_id || '''  
                              AND f.send\_bat = ''''  
                              AND f.operation\_type !=''D'')  
                   UNION ALL  
                   SELECT report\_id, organ\_id, report\_date, item\_id, 2 d  
                     FROM (SELECT ' || v\_columns || '  
                             FROM ' ||  
                   v\_history\_table || ' f  
                            WHERE f.report\_id = ' ||  
                   i\_report\_id || '  
                              AND f.report\_date = ''' ||  
                   i\_report\_date || '''  
                              AND f.organ\_id = ''' ||  
                   i\_organ\_id || '''  
                              AND f.send\_bat = ''''  
                              AND f.operation\_type !=''D''  
                           except  
                           SELECT ' || v\_columns || '  
                             FROM '||v\_physical\_table||' t  
                            WHERE t.report\_id = ' ||  
                   i\_report\_id || '  
                              AND t.report\_date =  ''' ||  
                   i\_report\_date || '''  
                              AND t.organ\_id = ''' ||  
                   i\_organ\_id || '''))  
                    group by report\_id, organ\_id, report\_date, item\_id  
                             )';  
     prepare s3 from eSql;  
     execute s3;  
     commit;  

set o_msg =eSql;
set o_ret = '';
END
DB20000I The SQL command completed successfully.

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器