Those SQLs is base on Oracle, includes make job, do procedure with function, and package them.
Function
- CREATE OR REPLACE FUNCTION F_GETREPLYINFO(BO_PROJECT_ID IN VARCHAR2,VERSION IN VARCHAR2)
- RETURN VARCHAR2 IS
- V_PROJECT_ID VARCHAR2(255);
- V_VERSION VARCHAR2(255);
- V_REPLY VARCHAR2(255);
- BEGIN
- V_PROJECT_ID := BO_PROJECT_ID;
- V_VERSION := VERSION;
- V_REPLY := '';
- SELECT TO_CHAR(T.JHRWSJHYQWCDATE, 'YYYY-MM-DD')
- || ';' || T.JHRWSJSGM || ';'
- || T.JHRWSZTZ INTO V_REPLY
- FROM BO_JHRWS_VER T
- WHERE T.BO_PROJECT_ID = V_PROJECT_ID
- AND T.VERIONNUMBER = (TO_CHAR(TO_NUMBER(V_VERSION)+1) || '.0');
- RETURN(V_REPLY);
- EXCEPTION
- WHEN OTHERS THEN
- RETURN('');
- END F_GETREPLYINFO;
- /**
- * 函数: 根据项目ID和版本号获取该项目的下一个版本的信息
- * 作者: ZHOU DANYONG 2010-11-04
- **/
PROCEDURE
- CREATE OR REPLACE PROCEDURE P_ENGINEERING_ACCOUNTS IS
- BEGIN
- /*
- *删除临时表
- */
- DELETE FROM TEM_ENGINEERING_ACCOUNTS;
- /*
- * 工程台账数据查询并写入临时表
- */
- INSERT INTO TEM_ENGINEERING_ACCOUNTS (MINEPROJ, BO_PROJECT_ID, ENGINEERING_TYPE, IS_RECIEVED, MISPROJECTCODE,
- SENDSTATE, JHRWSJSDW, SPECIALTYGROUP, SETSPECIALTYGROUPDATE, LEADER, DEPTMENTPATH, LEADERCREATEDATE, FINANCE_MANAGER,
- ENG_SPECIALTY_TYPE, ENGINEERING_STATE, RECIEVEDATE, STARTDATE, COMPLETEDATE, REMARK, DESIGNUNIT, SUPERVISIONUNIT,
- CONSTRUCTIONUNIT, BO_ENGINEERING_ID, ISSURE, BO_JHRWS_ID, ERPTEMPLATE, BUILD_DEPT, PLANARRIVALDATE, PLANTASKHISID,
- PLANSCHEDULE, TOTALINVEST, YEARINVEST, BUILDINGSCALE, MAINTAINCORP, PROJECT_CODE, PROJECT_NAME, PLAN_MANAGER, YEAR,
- PROJECT_TYPE, PROJECT_TYPE_NAME, TOTAL_INVEST, MANAGE_ATTRIBUTE, ABC_CLASS, GROUP_CODE, PRIMARY_CONTENT,
- INTEND_START_DATE, INTEND_ISSUE_DATE, INTEND_END_DATE, JHRWSZTZ, JHRWSNDTZ, ENG_SPECIALTY_TYPE_NAME, JHRWSJHXDDATE,
- JHRWSJHYQWCDATE, JHRWSJHYQTZDATE, PLAN_MANAGER_NAME, SPECIALTYGROUP_NAME, LEADER_NAME, BO_BLANKTEMPLATE_ID,
- IS_SHUDI_PROJECT, BUILD_DEPT_NAME, SJPFTZ, SJPFTZTZ, PREDATE, FINALDATE, CHECK_COST_BUDGET, YEAR_INVEST2, TOTAL_INVEST2,
- SGT_MEETTINGTIME, SJ_MEETTINGTIME, PRE_DESIGN_FEE, PRE_SUPERVISION_FEE, PRE_BUILD_BUDGET, CHECK_AMOUNT, PLANMAPPLYTIME,
- PLANMDELAY, PLANMCONTENT, PLANMINVEST, PLANMREPLY, LASTASSESSNAME)
- SELECT NVL2(E.STARTDATE, 1, 0) MINEPROJ,
- E.*,
- TO_CHAR(E.TOTALINVEST, 'FM9999999999990.00') AS JHRWSZTZ,
- TO_CHAR(E.YEARINVEST, 'FM9999999999990.00') AS JHRWSNDTZ,
- DECODE(E.ENG_SPECIALTY_TYPE,
- '1',
- '传输设备专业',
- '2',
- '通信设备专业',
- '3',
- '光缆线路专业',
- '4',
- '无线专业',
- '5',
- '通信管道专业',
- '6',
- '室内覆盖专业',
- '7',
- '建筑专业') AS ENG_SPECIALTY_TYPE_NAME,
- TO_CHAR(E.PLANARRIVALDATE, 'YYYY-MM-DD') AS JHRWSJHXDDATE,
- TO_CHAR(E.PLANSCHEDULE, 'YYYY-MM-DD') AS JHRWSJHYQWCDATE,
- (SELECT TO_CHAR(JHRWSJHYQWCDATE, 'YYYY-MM-DD')
- FROM BO_JHRWS_VER
- WHERE BO_PROJECT_ID = E.BO_PROJECT_ID
- AND VERIONNUMBER = '1.0') JHRWSJHYQTZDATE,
- (SELECT U.FULLNAME FROM V_USER U WHERE U.USERID = E.PLAN_MANAGER) PLAN_MANAGER_NAME,
- (SELECT V.ORGANIZATIONNAME
- FROM V_ORG V
- WHERE V.ORGANIZATIONID = E.SPECIALTYGROUP) SPECIALTYGROUP_NAME,
- V1.FULLNAME LEADER_NAME,
- '' BO_BLANKTEMPLATE_ID,
- (SELECT DECODE(COMMENTS, '2', '1', '2')
- FROM ORGANIZATION_
- WHERE ORGANIZATIONID = E.BUILD_DEPT) IS_SHUDI_PROJECT,
- (SELECT NAME FROM ORGANIZATION_ WHERE ORGANIZATIONID = E.BUILD_DEPT) BUILD_DEPT_NAME,
- TO_CHAR(S1.INVESTBUDGET, 'FM9999999999990.00') SJPFTZ,
- TO_CHAR(S2.INVEST, 'FM9999999999990.00') SJPFTZTZ,
- V2.FACTCOMPDATE PREDATE,
- V3.FACTCOMPDATE FINALDATE,
- V4.CHECK_COST_BUDGET CHECK_COST_BUDGET,
- TO_CHAR(V5.YEAR_INVEST, 'FM9999999999990.00') YEAR_INVEST2,
- TO_CHAR(V5.TOTAL_INVEST, 'FM9999999999990.00') TOTAL_INVEST2,
- TO_CHAR(V6.MEETTINGTIME, 'YYYY-MM-DD') AS SGT_MEETTINGTIME,
- TO_CHAR(V7.MEETTINGTIME, 'YYYY-MM-DD') AS SJ_MEETTINGTIME,
- TO_CHAR(V7.PRE_DESIGN_FEE, 'FM9999999999990.00') PRE_DESIGN_FEE,
- TO_CHAR(V7.PRE_SUPERVISION_FEE, 'FM9999999999990.00') PRE_SUPERVISION_FEE,
- TO_CHAR(V7.PRE_BUILD_BUDGET, 'FM9999999999990.00') PRE_BUILD_BUDGET,
- TO_CHAR(T8.CHECK_AMOUNT, 'FM9999999999990.00') CHECK_AMOUNT,
- DECODE(TO_CHAR(T9.JHRWSBGSQDATE, 'YYYY-MM-DD'), '', '无') AS PLANMAPPLYTIME,
- DECODE(TO_CHAR(T9.DELAYDATE, 'YYYY-MM-DD'), '', '无') AS PLANMDELAY,
- DECODE(TO_CHAR(T9.JHRWSBGSQCS_RY, 'YYYY-MM-DD'), '', '无') AS PLANMCONTENT,
- DECODE(T9.JHRWSBGSQCB_BM, '', '无') PLANMINVEST,
- DECODE(F_GETREPLYINFO(XX.BO_PROJECT_ID, XX.VERIONNUMBER), '', '无') PLANMREPLY, /*F_GETLASTASSESSNAME(E.BO_ENGINEERING_ID, E.BUILD_DEPT)*/
- '数据正在获取中...' LASTASSESSNAME
- FROM V_BO_ENGINEERING E,
- V_USER V1,
- BO_DESIGNAPPROVE_VER S1,
- V_LASTEFFECTED_DESIGNAGREE S2,
- (SELECT * FROM V_BO_TASK_ITEM1_2_PLAN T WHERE T.ASSESSCODE = 'WCCYSJ') V2,
- (SELECT * FROM V_BO_TASK_ITEM1_2_PLAN T WHERE T.ASSESSCODE = 'WCJGSJ') V3,
- (SELECT *
- FROM (SELECT DISTINCT *
- FROM V_BO_DESIGNCHECKUP_2_ENG T
- WHERE T.IS_PASS_DESIGNCHECK = '1'
- ORDER BY T.SGJDJYTIME DESC)
- WHERE ROWNUM = 1) V4,
- (SELECT TT.*
- FROM (SELECT T.*,
- RANK() OVER(PARTITION BY T.BO_PROJECT_ID ORDER BY T.YEAR DESC) NN
- FROM V_PROJECT_GCSB T) TT
- WHERE TT.NN = '1') V5,
- (SELECT *
- FROM (SELECT B.*,
- RANK() OVER(PARTITION BY B.BO_ENGINEERING_ID ORDER BY B.CREATEDATE DESC) Z
- FROM (SELECT DISTINCT T.BO_ENGINEERING_ID,
- T.MEETTINGTIME,
- T.CREATEDATE
- FROM V_BO_DESIGNCHECKUP_2_ENG T
- WHERE T.TYPE = '2') B) BB
- WHERE BB.Z = 1) V6,
- (SELECT *
- FROM (SELECT B.*,
- RANK() OVER(PARTITION BY B.BO_ENGINEERING_ID ORDER BY B.CREATEDATE DESC) Z
- FROM (SELECT T.BO_ENGINEERING_ID,
- T.MEETTINGTIME,
- T.PRE_DESIGN_FEE,
- T.PRE_SUPERVISION_FEE,
- T.PRE_BUILD_BUDGET,
- T.CREATEDATE
- FROM V_BO_DESIGNCHECKUP_2_ENG T
- WHERE T.TYPE IS NULL
- OR T.TYPE = '1') B) BB
- WHERE BB.Z = 1) V7,
- (SELECT *
- FROM (SELECT B.*,
- RANK() OVER(PARTITION BY B.BO_CONTRACT_CHECK_INFO_ID ORDER BY B.CREATORDATE DESC) Z
- FROM BO_CONTRACT_CHECK_INFO B) BB
- WHERE BB.Z = 1) T8,
- (SELECT *
- FROM (SELECT B.*,
- RANK() OVER(PARTITION BY B.BO_ENGINEERING_ID ORDER BY B.CREATEDATE DESC) Z
- FROM (SELECT T.*
- FROM BO_JHRWSBGSQ T
- WHERE T.WORKFLOW_STATE = '4') B) BB
- WHERE BB.Z = 1) T9,
- (SELECT *
- FROM (SELECT *
- FROM (SELECT B.*,
- RANK() OVER(PARTITION BY B.BO_ENGINEERING_ID ORDER BY B.CREATEDATE DESC) Z
- FROM BO_JHRWSBGSQ B
- WHERE B.WORKFLOW_STATE = '4') BB
- WHERE BB.Z = 1) BBB,
- BO_JHRWS_VER Z
- WHERE BBB.BO_JHRWS_VER_ID = Z.BO_JHRWS_VER_ID(+)) XX
- WHERE E.ENGINEERING_STATE = 2
- AND E.BO_PROJECT_ID = V5.BO_PROJECT_ID(+)
- AND E.BO_ENGINEERING_ID = V6.BO_ENGINEERING_ID(+)
- AND E.BO_ENGINEERING_ID = V7.BO_ENGINEERING_ID(+)
- AND E.BO_ENGINEERING_ID = T8.BO_CONTRACT_CHECK_INFO_ID(+)
- AND E.BO_ENGINEERING_ID = T9.BO_ENGINEERING_ID(+)
- AND E.BO_ENGINEERING_ID = XX.BO_ENGINEERING_ID(+)
- AND V1.USERID = E.LEADER(+)
- AND S1.BO_PROJECT_ID(+) = E.BO_PROJECT_ID
- AND S1.VERIONNUMBER(+) = '1.0'
- AND S2.PROJECTID(+) = E.BO_PROJECT_ID
- AND E.BO_ENGINEERING_ID = V2.BO_ENGINEERING_ID(+)
- AND E.BO_ENGINEERING_ID = V3.BO_ENGINEERING_ID(+)
- AND E.BO_ENGINEERING_ID = V4.BO_ENGINEERING_ID(+)
- ;
- COMMIT;
- /**出错回滚**/
- EXCEPTION
- WHEN OTHERS THEN ROLLBACK;
- END P_ENGINEERING_ACCOUNTS;
- /**
- * P_ENGINEERING_ACCOUNTS
- * 作者:Zhou Danyong
- * 日期:2010-11-05
- **/
PACKAGE
- CREATE OR REPLACE PACKAGE PKG_ACCOUNTS IS
- -- Author : Zhou Danyong
- -- Created : 2010-11-05
- -- Purpose : 工程台账
- FUNCTION F_GETREPLYINFO(BO_PROJECT_ID IN VARCHAR2,VERSION IN VARCHAR2) RETURN VARCHAR2 ;
- PROCEDURE P_ENGINEERING_ACCOUNTS;
- END PKG_ACCOUNTS;
Job
- variable job NUMBER;
- begin
- sys.dbms_job.submit(job => :job,
- what => 'PKG_ACCOUNTS.P_ENGINEERING_ACCOUNTS;',
- next_date => to_date('06-11-2010 23:59:59', 'dd-mm-yyyy hh24:mi:ss'),
- interval => 'SYSDATE+ 1');
- commit;
- end;
- /
附件:http://down.51cto.com/data/2357079
本文转自danni505 51CTO博客,原文链接:http://blog.51cto.com/danni505/415915,如需转载请自行联系原作者