这段过程有优化的空间么?请进来看看!!(50分)

  • 主题发起人 主题发起人 龙之天涯
  • 开始时间 开始时间

龙之天涯

Unregistered / Unconfirmed
GUEST, unregistred user!
CREATE OR REPLACE PROCEDURE DY_CREATEYD14(V_TIME DATE,V_ZMLM IN VARCHAR2,V_ID NUMBER,<br>V_INSTR IN VARCHAR2,V_OUTSTR IN VARCHAR2)<br>AS<br>ERRMSG VARCHAR2(1000);<br>V_CID VARCHAR2(24);<br>V_LJDM VARCHAR2(4);<br>V_CB &nbsp; VARCHAR2(10);<br>CURSOR C_CML IS SELECT CDM FROM B_CML WHERE ZMLM=V_ZMLM AND BLZD1 IS NOT NULL ORDER BY BLZD1;<br>TIME1 DATE;<br>TIME2 DATE;<br>SECS &nbsp;VARCHAR(6);<br>errcode varchar(256);<br>BEGIN<br><br>&nbsp; &nbsp;-- SELECT SYSDATE INTO TIME1 FROM DUAL;<br>&nbsp; &nbsp; SELECT SUBSTR(V_ZMLM,3,1) INTO V_LJDM FROM DUAL;<br>------------------清理临时数据------------------------<br>&nbsp; &nbsp; DELETE FROM DY_YD14_TEMP WHERE ZMLM=V_ZMLM;<br> DELETE FROM DY_YD14 &nbsp; &nbsp; &nbsp;WHERE ZMLM=V_ZMLM;<br> COMMIT;<br> LCJ_STATIONYARD_BACKDATE_BYDAT(V_TIME ,V_ZMLM ,V_ID ,V_INSTR ,V_OUTSTR);<br><br><br><br>&nbsp; &nbsp;UPDATE B_ZCXXCLK_TEMP A<br>&nbsp; &nbsp; &nbsp;SET CB=(SELECT CB FROM B_GDML WHERE GDM=A.GDM AND ZMLM=V_ZMLM AND ROWNUM=1),FXH2=(SELECT XFXH FROM DP_ZMFX WHERE BZLM=V_ZMLM AND DZLM=A.DZH AND ROWNUM=1)<br>&nbsp; &nbsp;WHERE ZCXXID=V_ID ;<br><br><br><br>&nbsp; &nbsp;--统一修改CZJM字段,在CZD_CZJM字典中找不到的车种,直接取CZJM的第一位<br>&nbsp; &nbsp;UPDATE B_ZCXXCLK_TEMP A<br>&nbsp; &nbsp; &nbsp;set CZJM=(SELECT F_CZJM FROM CZD_CZJM WHERE F_DM=A.CZ AND ROWNUM=1)<br>&nbsp; &nbsp;WHERE Zcxxid=V_ID AND CZ IN(SELECT F_DM FROM CZD_CZJM) AND CZJM NOT IN('P','C','N','G','B','W','K','X','JC','KC');<br><br>&nbsp; &nbsp;UPDATE B_ZCXXCLK_TEMP A<br>&nbsp; &nbsp; &nbsp;set CZJM=SUBSTR(CZJM,1,1)<br>&nbsp; &nbsp;WHERE Zcxxid=V_ID AND CZ NOT IN(SELECT F_DM FROM CZD_CZJM) &nbsp;AND CZJM NOT IN('P','C','N','G','B','W','K','X','JC','KC');<br><br><br><br> UPDATE B_ZCXXCLK_TEMP<br> SET FXH2='99'<br>&nbsp; &nbsp; WHERE ZCXXID=V_ID AND (FXH2='999');<br><br> UPDATE B_ZCXXCLK_TEMP<br> SET FXH2='-1'<br>&nbsp; &nbsp; WHERE ZCXXID=V_ID AND (FXH2 IS NULL OR FXH2='');<br><br>-----读取站调大表车辆方向----------------------<br> INSERT INTO DY_YD14_TEMP(ZMLM,ZH,ZHM,XH,HJ,CB)<br>&nbsp; &nbsp; select V_ZMLM,dir_scope,row_text ,B.ROW_INDEX,0,'HJ' from CZD_sub_header a,CZD_sub_headER_row b where a.header_INDEX = B.header_INDEX AND A.CODE=5 AND A.TYPE =3<br>&nbsp; &nbsp; AND A.TAB_NUM=1000<br>&nbsp; &nbsp; ORDER BY B.ROW_INDEX;<br>-----读取结束----------------------------------<br>&nbsp; &nbsp; --带方向车辆按组号分类<br> INSERT INTO DY_YD14(ZMLM,ZH,ZHM,KZBZ,XH,HJ,CB)<br>&nbsp; &nbsp; SELECT V_ZMLM,FXH2,FXH2,1,1,COUNT(*),'HJ' FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID AND FXH2&lt;&gt;'-1' AND FYBZ='0'<br>&nbsp; &nbsp; GROUP BY FXH2;<br><br><br>&nbsp; &nbsp; OPEN C_CML;<br>&nbsp; &nbsp; LOOP<br>&nbsp; &nbsp; &nbsp; &nbsp;FETCH C_CML INTO V_CB;<br>&nbsp; &nbsp; &nbsp; &nbsp;EXIT WHEN C_CML%NOTFOUND;<br> &nbsp; INSERT INTO DY_YD14(ZMLM,ZH,ZHM,KZBZ,XH,HJ,CB)<br>&nbsp; &nbsp; &nbsp; &nbsp;SELECT V_ZMLM,FXH2,FXH2,1,1,COUNT(*),V_CB FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID AND FXH2&lt;&gt;'-1' AND FYBZ='0'<br> &nbsp; AND CB=V_CB<br>&nbsp; &nbsp; &nbsp; &nbsp;GROUP BY FXH2;<br>&nbsp; &nbsp; END LOOP;<br>&nbsp; &nbsp; CLOSE C_CML;<br><br><br>&nbsp; &nbsp; INSERT INTO DY_YD14(ZMLM,ZH,ZHM,KZBZ,XH,HJ,CB)<br> SELECT ZMLM,'不明',ZHM,KZBZ,XH,HJ,CB FROM DY_YD14 WHERE ZMLM=V_ZMLM AND ZH NOT IN(SELECT DISTINCT XFXH FROM DP_ZMFX WHERE BZLM=V_ZMLM) AND ZH&lt;&gt;'99' AND KZBZ='1';<br><br> DELETE FROM DY_YD14 WHERE ZMLM=V_ZMLM AND ZH NOT IN (SELECT DISTINCT XFXH FROM DP_ZMFX WHERE BZLM=V_ZMLM) AND ZH NOT IN('不明');<br><br><br>&nbsp; &nbsp; --不带方向车辆按车种分类<br><br> &nbsp; INSERT INTO DY_YD14(ZMLM,ZH,ZHM,KZBZ,XH,HJ,CB)<br>&nbsp; &nbsp; &nbsp; &nbsp;SELECT V_ZMLM,CZJM,CZJM,0,4,COUNT(*),'HJ' FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID AND &nbsp; FXH2='-1' AND FYBZ='0' &nbsp;AND CZJM IN('P','C','N','G','B','W')<br>&nbsp; &nbsp; &nbsp; &nbsp;GROUP BY CZJM ;<br><br><br><br> &nbsp; INSERT INTO DY_YD14(ZMLM,ZH,ZHM,KZBZ,XH,HJ,CB)<br>&nbsp; &nbsp; &nbsp; &nbsp;SELECT V_ZMLM,'K,X,JC,KC','K,X,JC,KC',0,4,COUNT(*),'HJ' FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID AND &nbsp; FXH2='-1' AND FYBZ='0' &nbsp;AND CZJM IN('K','X','JC','KC')<br>&nbsp; &nbsp; &nbsp; &nbsp;GROUP BY CZJM ;<br><br> &nbsp; INSERT INTO DY_YD14(ZMLM,ZH,ZHM,KZBZ,XH,HJ,CB)<br>&nbsp; &nbsp; &nbsp; &nbsp;SELECT V_ZMLM,'QT,99','QT,99',0,4,COUNT(*),'HJ' FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID<br> &nbsp; AND ((FXH2='-1' AND CZJM NOT IN('P','C','N','G','B','W','K','X','JC','KC')) or FXH2='99' ) AND FYBZ='0';<br><br><br><br>&nbsp; &nbsp; OPEN C_CML;<br>&nbsp; &nbsp; LOOP<br>&nbsp; &nbsp; &nbsp; &nbsp;FETCH C_CML INTO V_CB;<br>&nbsp; &nbsp; &nbsp; &nbsp;EXIT WHEN C_CML%NOTFOUND;<br><br><br> &nbsp; INSERT INTO DY_YD14(ZMLM,ZH,ZHM,KZBZ,XH,HJ,CB)<br>&nbsp; &nbsp; &nbsp; &nbsp;SELECT V_ZMLM,CZJM,CZJM,0,4,COUNT(*),V_CB FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID AND &nbsp;FXH2='-1' AND FYBZ='0'<br> &nbsp; AND CB=V_CB AND CZJM IN('P','C','N','G','B','W')<br>&nbsp; &nbsp; &nbsp; &nbsp;GROUP BY CZJM ;<br><br> &nbsp; INSERT INTO DY_YD14(ZMLM,ZH,ZHM,KZBZ,XH,HJ,CB)<br>&nbsp; &nbsp; &nbsp; &nbsp;SELECT V_ZMLM,'K,X,JC,KC','K,X,JC,KC',0,4,COUNT(*),V_CB FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID AND &nbsp; FXH2='-1' AND FYBZ='0'<br> &nbsp; AND CB=V_CB AND CZJM IN('K','X','JC','KC')<br>&nbsp; &nbsp; &nbsp; &nbsp;GROUP BY CZJM ;<br><br>&nbsp; &nbsp; INSERT INTO DY_YD14(ZMLM,ZH,ZHM,KZBZ,XH,HJ,CB)<br>&nbsp; &nbsp; &nbsp; &nbsp;SELECT V_ZMLM,'QT,99','QT,99',0,4,COUNT(*),V_CB FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID<br> &nbsp; AND &nbsp;((FXH2='-1' AND CZJM NOT IN('P','C','N','G','B','W','K','X','JC','KC')) or FXH2='99') AND FYBZ='0'<br> &nbsp; AND CB=V_CB ;<br><br><br>&nbsp; &nbsp; END LOOP;<br>&nbsp; &nbsp; CLOSE C_CML;<br><br><br><br>---------主要想把下面9个代码用油标搞定,只是不知道如何改边字段F0----F9和游标记录条数相等.想尝试使用<br>---------动态数组和油标结合,大家用过来帮帮忙<br> V_CB := 'HJ';<br> UPDATE DY_YD14_TEMP A<br> SET A.HJ=(SELECT HJ FROM DY_YD14 &nbsp;B WHERE B.ZH=A.ZH AND B.CB=V_CB AND ROWNUM=1);<br><br>&nbsp; &nbsp; V_CB := 'SD';<br> UPDATE DY_YD14_TEMP A<br> SET A.F0=(SELECT HJ FROM DY_YD14 &nbsp;B WHERE B.ZH=A.ZH AND B.CB=V_CB AND ROWNUM=1);<br><br><br> V_CB := 'SB';<br> UPDATE DY_YD14_TEMP A<br> SET A.F1=(SELECT HJ FROM DY_YD14 &nbsp;B WHERE B.ZH=A.ZH AND B.CB=V_CB AND ROWNUM=1);<br><br> V_CB := 'SF';<br> UPDATE DY_YD14_TEMP A<br> SET A.F2=(SELECT HJ FROM DY_YD14 &nbsp;B WHERE B.ZH=A.ZH AND B.CB=V_CB AND ROWNUM=1);<br><br> V_CB := 'XD';<br> UPDATE DY_YD14_TEMP A<br> SET A.F3=(SELECT HJ FROM DY_YD14 &nbsp;B WHERE B.ZH=A.ZH AND B.CB=V_CB AND ROWNUM=1);<br><br> V_CB := 'XB';<br> UPDATE DY_YD14_TEMP A<br> SET A.F4=(SELECT HJ FROM DY_YD14 &nbsp;B WHERE B.ZH=A.ZH AND B.CB=V_CB AND ROWNUM=1);<br><br> V_CB := 'XF';<br> UPDATE DY_YD14_TEMP A<br> SET A.F5=(SELECT HJ FROM DY_YD14 &nbsp;B WHERE B.ZH=A.ZH AND B.CB=V_CB AND ROWNUM=1);<br><br> V_CB := 'JH';<br> UPDATE DY_YD14_TEMP A<br> SET A.F6=(SELECT HJ FROM DY_YD14 &nbsp;B WHERE B.ZH=A.ZH AND B.CB=V_CB AND ROWNUM=1);<br><br> V_CB := 'FZ';<br> UPDATE DY_YD14_TEMP A<br> SET A.F7=(SELECT HJ FROM DY_YD14 &nbsp;B WHERE B.ZH=A.ZH AND B.CB=V_CB AND ROWNUM=1);<br><br> V_CB := 'ZY';<br> UPDATE DY_YD14_TEMP A<br> SET A.F8=(SELECT HJ FROM DY_YD14 &nbsp;B WHERE B.ZH=A.ZH AND B.CB=V_CB AND ROWNUM=1);<br><br><br> DELETE FROM DY_YD14_TEMP<br> WHERE ZH='SUM';<br><br> INSERT INTO DY_YD14_TEMP(ZMLM,ZH,ZHM,XH,HJ,F0,F1,F2,F3,F4,F5,F6,F7,F8,CB)<br> SELECT V_ZMLM,'SUM','合计','9999',SUM(HJ),SUM(F0),SUM(F1),SUM(F2),SUM(F3),SUM(F4),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SUM(F5),SUM(F6),SUM(F7),SUM(F8),'HJ'<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;From DY_YD14_TEMP<br>&nbsp; &nbsp; WHERE ZMLM=V_ZMLM;<br><br><br>---------开始生成上传数据------------------------------------------<br><br>---------开始生成上传数据------------------------------------------<br> DELETE FROM CZD_YD14;<br><br>&nbsp; &nbsp; --先生成大方向号<br> INSERT INTO CZD_YD14(TAB_NUM,BALANCE_TIME,DIR_NUM,CAR_NUM,CAR_KIND,REMARK,GD_NO)<br>&nbsp; &nbsp; SELECT 1000,V_TIME, FXH2,COUNT(*),0,'CZ',GDM FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID<br> AND &nbsp;FXH2&lt;&gt;-1 AND FYBZ='0'<br> GROUP BY GDM,FXH2;<br><br><br>&nbsp; &nbsp; --大方向空车计<br> INSERT INTO CZD_YD14(TAB_NUM,BALANCE_TIME,DIR_NUM,CAR_NUM,CAR_KIND,REMARK,GD_NO)<br>&nbsp; &nbsp; SELECT 1000,V_TIME, 0,COUNT(*),CZJM,'CZ',GDM FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID<br> AND &nbsp;FXH2=-1 AND FYBZ='0'<br> GROUP BY GDM,CZJM;<br><br><br>&nbsp; &nbsp;UPDATE B_ZCXXCLK_TEMP A<br>&nbsp; &nbsp;SET FXH2=(SELECT DIRECTION_CODE FROM FXL_FXLB WHERE &nbsp;TELE_CODE=A.DZH AND ROWNUM=1)<br>&nbsp; &nbsp;WHERE ZCXXID=V_ID ;<br><br><br>&nbsp; &nbsp;UPDATE B_ZCXXCLK_TEMP A<br>&nbsp; &nbsp;SET FXH2=-1<br>&nbsp; &nbsp;WHERE ZCXXID=V_ID AND FXH2 IS NULL;<br><br>&nbsp; &nbsp; --大方向空车计<br> INSERT INTO CZD_YD14(TAB_NUM,BALANCE_TIME,DIR_NUM,CAR_NUM,CAR_KIND,REMARK,GD_NO)<br>&nbsp; &nbsp; SELECT 1000,V_TIME, 0,COUNT(*),CZJM,'LJ',GDM FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID<br> AND &nbsp;FXH2=-1 AND FYBZ='0'<br> GROUP BY GDM,CZJM;<br><br> UPDATE CZD_YD14 A<br>&nbsp; &nbsp; SET DIR_NUM=(SELECT DIRECTION_CODE FROM CZD_CARKIND WHERE A.CAR_KIND=CZDM)<br> WHERE BALANCE_TIME=V_TIME AND REMARK='LJ';<br><br>&nbsp; &nbsp; --先生成大方向号<br> INSERT INTO CZD_YD14(TAB_NUM,BALANCE_TIME,DIR_NUM,CAR_NUM,CAR_KIND,REMARK,GD_NO)<br>&nbsp; &nbsp; SELECT 1000,V_TIME, FXH2,COUNT(*),0,'LJ',GDM FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID<br> And &nbsp;FXH2&lt;&gt;-1 AND FYBZ='0'<br> GROUP BY GDM,FXH2;<br><br>---------生成上传数据完成------------------------------------------<br> --DELETE FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID;<br>&nbsp; &nbsp; COMMIT;<br>EXCEPTION<br>&nbsp; &nbsp; &nbsp;WHEN OTHERS THEN<br>&nbsp; &nbsp; &nbsp; &nbsp; ERRMSG:='生成YD14失败:';<br> ERRMSG:=SUBSTRB(SQLERRM,1,256);<br>&nbsp; &nbsp; &nbsp; &nbsp; DBMS_OUTPUT.PUT_LINE(ERRMSG);<br>&nbsp; &nbsp; &nbsp; &nbsp; ROLLBACK;<br>END;<br>/
 
怎么全是有人看,没人答啊
 
你最好先了解一下SQL优化的原理。<br><br>数据量大的情况下,你用IN / NOT IN的操作会很消耗资源的,建议改成 exists 或 not exists方式。
 
B_ZCXXCLK_TEMP表的数据大概也就在5000左右,整个过程执行大概需要18秒,<br>我想能不能进一步优化,<br>特别是加强过程的通用性<br><br>---------主要想把下面9个代码用油标搞定,只是不知道如何改边字段F0----F9和游标记录条数相等.想尝试使用<br>---------动态数组和油标结合,大家用过来帮帮忙<br>&nbsp;V_CB := 'HJ';<br>&nbsp;UPDATE DY_YD14_TEMP A<br>&nbsp;SET A.HJ=(SELECT HJ FROM DY_YD14 &nbsp;B WHERE B.ZH=A.ZH AND B.CB=V_CB AND ROWNUM=1);<br><br>&nbsp; &nbsp; V_CB := 'SD';<br>&nbsp;UPDATE DY_YD14_TEMP A<br>&nbsp;SET A.F0=(SELECT HJ FROM DY_YD14 &nbsp;B WHERE B.ZH=A.ZH AND B.CB=V_CB AND ROWNUM=1);<br><br><br>&nbsp;V_CB := 'SB';<br>&nbsp;UPDATE DY_YD14_TEMP A<br>&nbsp;SET A.F1=(SELECT HJ FROM DY_YD14 &nbsp;B WHERE B.ZH=A.ZH AND B.CB=V_CB AND ROWNUM=1);<br><br><br>就是把这段代码换个通用点出来
 
我来解释一下,只想把下面这段代码优化一下.<br><br>由于where 条件 的值不同,没有办法只有写了8行看起来很类似的代码,想通过动态数组的办法来实现<br>不知道有那位做过类似的?<br>V_CB 这个变量的值,通过以下游标可以取到.<br>有"x"行记录,相应的就会更新 F"X"列<br>CURSOR C_CML IS SELECT CDM FROM B_CML WHERE ZMLM=V_ZMLM AND BLZD1 IS NOT NULL ORDER BY BLZD1;<br>&nbsp; &nbsp; V_CB := 'SD'; <br>UPDATE DY_YD14_TEMP A <br>SET A.F0=(SELECT HJ FROM DY_YD14 &nbsp;B WHERE B.ZH=A.ZH AND B.CB=V_CB AND ROWNUM=1); <br><br><br>V_CB := 'SB'; <br>UPDATE DY_YD14_TEMP A <br>SET A.F1=(SELECT HJ FROM DY_YD14 &nbsp;B WHERE B.ZH=A.ZH AND B.CB=V_CB AND ROWNUM=1); <br><br>V_CB := 'SF'; <br>UPDATE DY_YD14_TEMP A <br>SET A.F2=(SELECT HJ FROM DY_YD14 &nbsp;B WHERE B.ZH=A.ZH AND B.CB=V_CB AND ROWNUM=1); <br><br>V_CB := 'XD'; <br>UPDATE DY_YD14_TEMP A <br>SET A.F3=(SELECT HJ FROM DY_YD14 &nbsp;B WHERE B.ZH=A.ZH AND B.CB=V_CB AND ROWNUM=1); <br><br>V_CB := 'XB'; <br>UPDATE DY_YD14_TEMP A <br>SET A.F4=(SELECT HJ FROM DY_YD14 &nbsp;B WHERE B.ZH=A.ZH AND B.CB=V_CB AND ROWNUM=1); <br><br>V_CB := 'XF'; <br>UPDATE DY_YD14_TEMP A <br>SET A.F5=(SELECT HJ FROM DY_YD14 &nbsp;B WHERE B.ZH=A.ZH AND B.CB=V_CB AND ROWNUM=1); <br><br>V_CB := 'JH'; <br>UPDATE DY_YD14_TEMP A <br>SET A.F6=(SELECT HJ FROM DY_YD14 &nbsp;B WHERE B.ZH=A.ZH AND B.CB=V_CB AND ROWNUM=1); <br><br>V_CB := 'FZ'; <br>UPDATE DY_YD14_TEMP A <br>SET A.F7=(SELECT HJ FROM DY_YD14 &nbsp;B WHERE B.ZH=A.ZH AND B.CB=V_CB AND ROWNUM=1); <br><br>V_CB := 'ZY'; <br>UPDATE DY_YD14_TEMP A <br>SET A.F8=(SELECT HJ FROM DY_YD14 &nbsp;B WHERE B.ZH=A.ZH AND B.CB=V_CB AND ROWNUM=1);
 
如何用数组你自己可以google一下。<br><br>如果你想实现动态列名 FX 你可以把执行SQL的方式改成循环语句 FOR ....<br>loop<br>EXECUTE IMMEDIATE 'UPDATE TABLENAME SET F'||TO_CHAR(I)||'= .......';<br>end loop;
 
现在已经改成这样了,通用性强了一点点<br>CREATE OR REPLACE PROCEDURE DY_CREATEYD14(V_TIME DATE,V_ZMLM IN VARCHAR2,V_ID NUMBER,<br>V_INSTR IN VARCHAR2,V_OUTSTR IN VARCHAR2)<br>AS<br>ERRMSG VARCHAR2(1000);<br>V_CID VARCHAR2(24);<br>V_LJDM VARCHAR2(4);<br>V_CB &nbsp; VARCHAR2(10);<br>CURSOR C_CML IS SELECT CDM FROM B_CML WHERE ZMLM=V_ZMLM AND BLZD1 IS NOT NULL ORDER BY BLZD1;<br>TIME1 DATE;<br>TIME2 DATE;<br>SECS &nbsp;VARCHAR(6);<br>errcode varchar(256);<br>vsql &nbsp;varchar2(1000);<br>vnum &nbsp;number; <br>--开头加声明此<br>BEGIN<br><br>&nbsp; &nbsp;-- SELECT SYSDATE INTO TIME1 FROM DUAL;<br>&nbsp; &nbsp; SELECT SUBSTR(V_ZMLM,3,1) INTO V_LJDM FROM DUAL;<br>------------------清理临时数据------------------------<br>&nbsp; &nbsp; DELETE FROM DY_YD14_TEMP WHERE ZMLM=V_ZMLM;<br> DELETE FROM DY_YD14 &nbsp; &nbsp; &nbsp;WHERE ZMLM=V_ZMLM;<br> COMMIT;<br> LCJ_STATIONYARD_BACKDATE_BYDAT(V_TIME ,V_ZMLM ,V_ID ,V_INSTR ,V_OUTSTR);<br><br><br><br>&nbsp; &nbsp;UPDATE B_ZCXXCLK_TEMP A<br>&nbsp; &nbsp; &nbsp;SET CB=(SELECT CB FROM B_GDML WHERE GDM=A.GDM AND ZMLM=V_ZMLM AND ROWNUM=1),FXH2=(SELECT XFXH FROM DP_ZMFX WHERE BZLM=V_ZMLM AND DZLM=A.DZH AND ROWNUM=1)<br>&nbsp; &nbsp;WHERE ZCXXID=V_ID ;<br><br><br><br>&nbsp; &nbsp;--统一修改CZJM字段,在CZD_CZJM字典中找不到的车种,直接取CZJM的第一位<br>&nbsp; &nbsp;UPDATE B_ZCXXCLK_TEMP A<br>&nbsp; &nbsp; &nbsp;set CZJM=(SELECT F_CZJM FROM CZD_CZJM WHERE F_DM=A.CZ AND ROWNUM=1)<br>&nbsp; &nbsp;WHERE Zcxxid=V_ID AND CZ IN(SELECT F_DM FROM CZD_CZJM) AND CZJM NOT IN('P','C','N','G','B','W','K','X','JC','KC');<br><br>&nbsp; &nbsp;UPDATE B_ZCXXCLK_TEMP A<br>&nbsp; &nbsp; &nbsp;set CZJM=SUBSTR(CZJM,1,1)<br>&nbsp; &nbsp;WHERE Zcxxid=V_ID AND CZ NOT IN(SELECT F_DM FROM CZD_CZJM) &nbsp;AND CZJM NOT IN('P','C','N','G','B','W','K','X','JC','KC');<br><br><br><br> UPDATE B_ZCXXCLK_TEMP<br> SET FXH2='99'<br>&nbsp; &nbsp; WHERE ZCXXID=V_ID AND (FXH2='999');<br><br> UPDATE B_ZCXXCLK_TEMP<br> SET FXH2='-1'<br>&nbsp; &nbsp; WHERE ZCXXID=V_ID AND (FXH2 IS NULL OR FXH2='');<br><br>-----读取站调大表车辆方向----------------------<br> INSERT INTO DY_YD14_TEMP(ZMLM,ZH,ZHM,XH,HJ,CB)<br>&nbsp; &nbsp; select V_ZMLM,dir_scope,row_text ,B.ROW_INDEX,0,'HJ' from CZD_sub_header a,CZD_sub_headER_row b where a.header_INDEX = B.header_INDEX AND A.CODE=5 AND A.TYPE =3<br>&nbsp; &nbsp; AND A.TAB_NUM=1000<br>&nbsp; &nbsp; ORDER BY B.ROW_INDEX;<br>-----读取结束----------------------------------<br>&nbsp; &nbsp; --带方向车辆按组号分类<br> INSERT INTO DY_YD14(ZMLM,ZH,ZHM,KZBZ,XH,HJ,CB)<br>&nbsp; &nbsp; SELECT V_ZMLM,FXH2,FXH2,1,1,COUNT(*),'HJ' FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID AND FXH2&lt;&gt;'-1' AND FYBZ='0'<br>&nbsp; &nbsp; GROUP BY FXH2;<br><br><br>&nbsp; &nbsp; OPEN C_CML;<br>&nbsp; &nbsp; LOOP<br>&nbsp; &nbsp; &nbsp; &nbsp;FETCH C_CML INTO V_CB;<br>&nbsp; &nbsp; &nbsp; &nbsp;EXIT WHEN C_CML%NOTFOUND;<br> &nbsp; INSERT INTO DY_YD14(ZMLM,ZH,ZHM,KZBZ,XH,HJ,CB)<br>&nbsp; &nbsp; &nbsp; &nbsp;SELECT V_ZMLM,FXH2,FXH2,1,1,COUNT(*),V_CB FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID AND FXH2&lt;&gt;'-1' AND FYBZ='0'<br> &nbsp; AND CB=V_CB<br>&nbsp; &nbsp; &nbsp; &nbsp;GROUP BY FXH2;<br>&nbsp; &nbsp; END LOOP;<br>&nbsp; &nbsp; CLOSE C_CML;<br><br><br>&nbsp; &nbsp; INSERT INTO DY_YD14(ZMLM,ZH,ZHM,KZBZ,XH,HJ,CB)<br> SELECT ZMLM,'不明',ZHM,KZBZ,XH,HJ,CB FROM DY_YD14 WHERE ZMLM=V_ZMLM AND ZH NOT IN(SELECT DISTINCT XFXH FROM DP_ZMFX WHERE BZLM=V_ZMLM) AND ZH&lt;&gt;'99' AND KZBZ='1';<br><br> DELETE FROM DY_YD14 WHERE ZMLM=V_ZMLM AND ZH NOT IN (SELECT DISTINCT XFXH FROM DP_ZMFX WHERE BZLM=V_ZMLM) AND ZH NOT IN('不明');<br><br><br>&nbsp; &nbsp; --不带方向车辆按车种分类<br><br> &nbsp; INSERT INTO DY_YD14(ZMLM,ZH,ZHM,KZBZ,XH,HJ,CB)<br>&nbsp; &nbsp; &nbsp; &nbsp;SELECT V_ZMLM,CZJM,CZJM,0,4,COUNT(*),'HJ' FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID AND &nbsp; FXH2='-1' AND FYBZ='0' &nbsp;AND CZJM IN('P','C','N','G','B','W')<br>&nbsp; &nbsp; &nbsp; &nbsp;GROUP BY CZJM ;<br><br><br><br> &nbsp; INSERT INTO DY_YD14(ZMLM,ZH,ZHM,KZBZ,XH,HJ,CB)<br>&nbsp; &nbsp; &nbsp; &nbsp;SELECT V_ZMLM,'K,X,JC,KC','K,X,JC,KC',0,4,COUNT(*),'HJ' FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID AND &nbsp; FXH2='-1' AND FYBZ='0' &nbsp;AND CZJM IN('K','X','JC','KC')<br>&nbsp; &nbsp; &nbsp; &nbsp;GROUP BY CZJM ;<br><br> &nbsp; INSERT INTO DY_YD14(ZMLM,ZH,ZHM,KZBZ,XH,HJ,CB)<br>&nbsp; &nbsp; &nbsp; &nbsp;SELECT V_ZMLM,'QT,99','QT,99',0,4,COUNT(*),'HJ' FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID<br> &nbsp; AND ((FXH2='-1' AND CZJM NOT IN('P','C','N','G','B','W','K','X','JC','KC')) or FXH2='99' ) AND FYBZ='0';<br><br><br><br>&nbsp; &nbsp; OPEN C_CML;<br>&nbsp; &nbsp; LOOP<br>&nbsp; &nbsp; &nbsp; &nbsp;FETCH C_CML INTO V_CB;<br>&nbsp; &nbsp; &nbsp; &nbsp;EXIT WHEN C_CML%NOTFOUND;<br><br><br> &nbsp; INSERT INTO DY_YD14(ZMLM,ZH,ZHM,KZBZ,XH,HJ,CB)<br>&nbsp; &nbsp; &nbsp; &nbsp;SELECT V_ZMLM,CZJM,CZJM,0,4,COUNT(*),V_CB FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID AND &nbsp;FXH2='-1' AND FYBZ='0'<br> &nbsp; AND CB=V_CB AND CZJM IN('P','C','N','G','B','W')<br>&nbsp; &nbsp; &nbsp; &nbsp;GROUP BY CZJM ;<br><br> &nbsp; INSERT INTO DY_YD14(ZMLM,ZH,ZHM,KZBZ,XH,HJ,CB)<br>&nbsp; &nbsp; &nbsp; &nbsp;SELECT V_ZMLM,'K,X,JC,KC','K,X,JC,KC',0,4,COUNT(*),V_CB FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID AND &nbsp; FXH2='-1' AND FYBZ='0'<br> &nbsp; AND CB=V_CB AND CZJM IN('K','X','JC','KC')<br>&nbsp; &nbsp; &nbsp; &nbsp;GROUP BY CZJM ;<br><br>&nbsp; &nbsp; INSERT INTO DY_YD14(ZMLM,ZH,ZHM,KZBZ,XH,HJ,CB)<br>&nbsp; &nbsp; &nbsp; &nbsp;SELECT V_ZMLM,'QT,99','QT,99',0,4,COUNT(*),V_CB FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID<br> &nbsp; AND &nbsp;((FXH2='-1' AND CZJM NOT IN('P','C','N','G','B','W','K','X','JC','KC')) or FXH2='99') AND FYBZ='0'<br> &nbsp; AND CB=V_CB ;<br><br><br>&nbsp; &nbsp; END LOOP;<br>&nbsp; &nbsp; CLOSE C_CML;<br><br><br><br><br><br><br> V_CB := 'HJ';<br> UPDATE DY_YD14_TEMP A<br> SET A.HJ=(SELECT HJ FROM DY_YD14 &nbsp;B WHERE B.ZH=A.ZH AND B.CB=V_CB AND ROWNUM=1);<br> <br>&nbsp; &nbsp; vnum:=0;<br>&nbsp; &nbsp; open C_CML;<br>&nbsp; &nbsp; loop<br>&nbsp; &nbsp; &nbsp; fetch C_CML into V_CB;<br>&nbsp; &nbsp; &nbsp; exit when C_CML%notfound;<br>&nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; vsql:='UPDATE DY_YD14_TEMP A'||' SET A.F'||to_char(vnum)||'=(SELECT HJ FROM DY_YD14 &nbsp;B WHERE B.ZH=A.ZH AND B.CB='''||V_CB||''' AND ROWNUM=1)'; <br>&nbsp; &nbsp; &nbsp; execute immediate vsql;<br>&nbsp; &nbsp; &nbsp; vnum := vnum+1;<br>&nbsp; &nbsp; end loop;<br>&nbsp; &nbsp; close C_CML;<br> <br><br> DELETE FROM DY_YD14_TEMP<br> WHERE ZH='SUM';<br><br> INSERT INTO DY_YD14_TEMP(ZMLM,ZH,ZHM,XH,HJ,F0,F1,F2,F3,F4,F5,F6,F7,F8,CB)<br> SELECT V_ZMLM,'SUM','合计','9999',SUM(HJ),SUM(F0),SUM(F1),SUM(F2),SUM(F3),SUM(F4),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SUM(F5),SUM(F6),SUM(F7),SUM(F8),'HJ'<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;From DY_YD14_TEMP<br>&nbsp; &nbsp; WHERE ZMLM=V_ZMLM;<br><br><br>---------开始生成上传数据------------------------------------------<br><br>---------开始生成上传数据------------------------------------------<br> DELETE FROM CZD_YD14;<br><br>&nbsp; &nbsp; --先生成大方向号<br> INSERT INTO CZD_YD14(TAB_NUM,BALANCE_TIME,DIR_NUM,CAR_NUM,CAR_KIND,REMARK,GD_NO)<br>&nbsp; &nbsp; SELECT 1000,V_TIME, FXH2,COUNT(*),0,'CZ',GDM FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID<br> AND &nbsp;FXH2&lt;&gt;-1 AND FYBZ='0'<br> GROUP BY GDM,FXH2;<br><br><br>&nbsp; &nbsp; --大方向空车计<br> INSERT INTO CZD_YD14(TAB_NUM,BALANCE_TIME,DIR_NUM,CAR_NUM,CAR_KIND,REMARK,GD_NO)<br>&nbsp; &nbsp; SELECT 1000,V_TIME, 0,COUNT(*),CZJM,'CZ',GDM FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID<br> AND &nbsp;FXH2=-1 AND FYBZ='0'<br> GROUP BY GDM,CZJM;<br><br><br>&nbsp; &nbsp;UPDATE B_ZCXXCLK_TEMP A<br>&nbsp; &nbsp;SET FXH2=(SELECT DIRECTION_CODE FROM FXL_FXLB WHERE &nbsp;TELE_CODE=A.DZH AND ROWNUM=1)<br>&nbsp; &nbsp;WHERE ZCXXID=V_ID ;<br><br><br>&nbsp; &nbsp;UPDATE B_ZCXXCLK_TEMP A<br>&nbsp; &nbsp;SET FXH2=-1<br>&nbsp; &nbsp;WHERE ZCXXID=V_ID AND FXH2 IS NULL;<br><br>&nbsp; &nbsp; --大方向空车计<br> INSERT INTO CZD_YD14(TAB_NUM,BALANCE_TIME,DIR_NUM,CAR_NUM,CAR_KIND,REMARK,GD_NO)<br>&nbsp; &nbsp; SELECT 1000,V_TIME, 0,COUNT(*),CZJM,'LJ',GDM FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID<br> AND &nbsp;FXH2=-1 AND FYBZ='0'<br> GROUP BY GDM,CZJM;<br><br> UPDATE CZD_YD14 A<br>&nbsp; &nbsp; SET DIR_NUM=(SELECT DIRECTION_CODE FROM CZD_CARKIND WHERE A.CAR_KIND=CZDM)<br> WHERE BALANCE_TIME=V_TIME AND REMARK='LJ';<br><br>&nbsp; &nbsp; --先生成大方向号<br> INSERT INTO CZD_YD14(TAB_NUM,BALANCE_TIME,DIR_NUM,CAR_NUM,CAR_KIND,REMARK,GD_NO)<br>&nbsp; &nbsp; SELECT 1000,V_TIME, FXH2,COUNT(*),0,'LJ',GDM FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID<br> And &nbsp;FXH2&lt;&gt;-1 AND FYBZ='0'<br> GROUP BY GDM,FXH2;<br><br>---------生成上传数据完成------------------------------------------<br> --DELETE FROM B_ZCXXCLK_TEMP WHERE ZCXXID=V_ID;<br>&nbsp; &nbsp; COMMIT;<br>EXCEPTION<br>&nbsp; &nbsp; &nbsp;WHEN OTHERS THEN<br>&nbsp; &nbsp; &nbsp; &nbsp; ERRMSG:='生成YD14失败:';<br> ERRMSG:=SUBSTRB(SQLERRM,1,256);<br>&nbsp; &nbsp; &nbsp; &nbsp; DBMS_OUTPUT.PUT_LINE(ERRMSG);<br>&nbsp; &nbsp; &nbsp; &nbsp; ROLLBACK;<br>END;<br>/
 
Commit一次就够了,不要多次提交。<br>你在亿阳交通工作吧?感觉这存储过程挺亲切的...我写的车辆统计存储过程大概有2000行。<br>这种大的存储过程只能自己看了,慢慢优化,别靠别人,多看看甲骨文的帮助,Oracle存储过程功能很强大的。
 
后退
顶部