PKG Tools
CREATE OR REPLACE PACKAGE BODY PKG_TOOLS_CONF_JCJ AS PROCEDURE PROC_GET_COMBINE_SQLS(V_IN_NAME IN VARCHAR2, INSERT_COLNAME OUT CLOB, SELECT_COLNAME OUT CLOB) IS V_INSERT_COLNAME CLOB:=''; V_SELECT_COLNAME CLOB:=''; --IN_COLNAME CLOB; --SE_COLNAME CLOB; BEGIN FOR I IN(SELECT A.INSERT_COLNAME,A.SELECT_COLNAME FROM GCG_CUST_ACCT_CREDIT_JCJCONF A WHERE A.TAB_NAME=V_IN_NAME) LOOP V_INSERT_COLNAME:=V_INSERT_COLNAME||I.INSERT_COLNAME||','; V_SELECT_COLNAME:=V_SELECT_COLNAME||I.SELECT_COLNAME||','; END LOOP; INSERT_COLNAME:=RTRIM(V_INSERT_COLNAME,','); SELECT_COLNAME:=RTRIM(V_SELECT_COLNAME,','); --PKG_TOOLS_CONF_JCJ.PROC_DISP_LONG_STRING(INSERT_COLNAME||CHR(10)||SELECT_COLNAME); RETURN; END; PROCEDURE PROC_DISP_LONG_STRING(V_SQL CLOB) IS PRAGMA AUTONOMOUS_TRANSACTION; BEGIN IF LENGTH(V_SQL)>80 THEN DBMS_OUTPUT.PUT_LINE(SUBSTR(V_SQL,1,80)); PROC_DISP_LONG_STRING(SUBSTR(V_SQL,81)); ELSE DBMS_OUTPUT.PUT_LINE(SUBSTR(V_SQL,1,80)); END IF; END; PROCEDURE PROC_EXEC_JOB(IN_SP_NAME VARCHAR2,IN_PARAM PROC_PARAM_TYPE) IS V_PROGRAMNAME VARCHAR2(30); V_JOBNAME VARCHAR2(100); V_JOB_PROCNAME VARCHAR2(100); V_SEQ_JOBID VARCHAR2(5); BEGIN V_SEQ_JOBID := LPAD(SEQ_SP_JOBID.NEXTVAL,3,'0'); V_PROGRAMNAME := 'PRO_'||SUBSTR(IN_SP_NAME, 5, 22)||'_'||V_SEQ_JOBID; V_JOBNAME := 'JOB_' || SUBSTR(IN_SP_NAME, 5, 22)||'_'||V_SEQ_JOBID; V_JOB_PROCNAME := IN_SP_NAME; --1.创建JOB对应的PROGRAM和参数 DBMS_SCHEDULER.CREATE_PROGRAM(PROGRAM_NAME => V_PROGRAMNAME, PROGRAM_TYPE => 'STORED_PROCEDURE', PROGRAM_ACTION => V_JOB_PROCNAME, NUMBER_OF_ARGUMENTS => 1, ENABLED => FALSE); DBMS_SCHEDULER.DEFINE_ANYDATA_ARGUMENT(PROGRAM_NAME => V_PROGRAMNAME, ARGUMENT_POSITION => 1, ARGUMENT_NAME => 'IN_WF_PARAM', ARGUMENT_TYPE => 'SYS.ANYDATA', DEFAULT_VALUE => SYS.ANYDATA.CONVERTOBJECT(IN_PARAM)); --2.创建JOB one-time-run DBMS_SCHEDULER.CREATE_JOB(JOB_NAME => V_JOBNAME, PROGRAM_NAME => V_PROGRAMNAME, JOB_CLASS =>'DEFAULT_JOB_CLASS', ENABLED => FALSE, AUTO_DROP => TRUE); --3.ENABLE PROGRAM AND JOB DBMS_SCHEDULER.ENABLE(V_PROGRAMNAME); DBMS_SCHEDULER.ENABLE(V_JOBNAME); END; PROCEDURE PROC_CREATE_JOB(V_SP_NAME VARCHAR2,PARAM IN OUT PROC_WF_PARAM_TYPE) IS V_JOB_NAME VARCHAR2(64); V_SQL VARCHAR2(4000); IN_PARAM PROC_PARAM_TYPE; BEGIN V_JOB_NAME :=SUBSTR(V_SP_NAME,0,10)||TO_CHAR(SYSDATE,'HH24MISS'); IN_PARAM := PROC_PARAM_TYPE(NULL,'',PARAM.IN_BUSI_DT,PARAM.IN_IMPORT_DT,''); V_SQL:='BEGIN DBMS_SCHEDULER.CREATE_JOB ( job_name =>'''||V_JOB_NAME||''', job_type =>''PLSQL_BLOCK'', job_action =>''BEGIN '||V_SP_NAME||'(:A); END;'', job_class =>''DEFAULT_JOB_CLASS'', enabled =>TRUE, auto_drop =>TRUE, comments =>'''' ); END;'; --DBMS_OUTPUT.PUT_LINE(PARAM.IN_BUSI_DT||PARAM.IN_IMPORT_DT); EXECUTE IMMEDIATE 'DBMS_OUTPUT.PUT_LINE(:B)' USING IN OUT IN_PARAM; EXECUTE IMMEDIATE V_SQL USING IN OUT IN_PARAM; END; PROCEDURE PROC_DISP_LONG_STRING_PLUS(V_IN_NAME IN VARCHAR2, SELECT_COLNAME OUT CLOB, INSERT_COLNAME OUT CLOB) IS V_INSERT_COLNAME CLOB; V_SELECT_COLNAME CLOB; V_COUNT NUMBER; BEGIN FOR I IN(SELECT A.COLUMN_NAME FROM USER_TAB_COLUMNS A WHERE A.TABLE_NAME=V_IN_NAME) LOOP V_INSERT_COLNAME:=V_INSERT_COLNAME||I.COLUMN_NAME||','; --ODS_COLNAME SELECT COUNT(1) INTO V_COUNT FROM DML_ODS_IN_SCONF WHERE TABNAME = UPPER(V_IN_NAME); IF V_COUNT = 0 THEN V_SELECT_COLNAME:=V_SELECT_COLNAME||I.COLUMN_NAME||','; ELSE V_SELECT_COLNAME:=V_SELECT_COLNAME||'REGEXP_REPLACE('||I.COLUMN_NAME||',''(^null$|^-$)'',''''),'; END IF; END LOOP; INSERT_COLNAME:=RTRIM(V_INSERT_COLNAME,','); SELECT_COLNAME:=RTRIM(V_SELECT_COLNAME,','); RETURN; END; PROCEDURE PROC_ODS_IN_LOADDATA_PLUS(V_ODS_TABNAME VARCHAR2, /*原始表*/ V_IN_TABNAME VARCHAR2, /*IN层表*/ IN_DATE DATE, /*跑批日期*/ VIN_DBLINK VARCHAR2, /*DBLINK默认NULL*/ V_USER VARCHAR2) IS DEFAULT_COLNAME CLOB; --IN表前6个字段 ODS_COLNAME CLOB; --原始表字段 V_SQL CLOB; IN_ODS_COLNAME CLOB; --插入IN表字段 RECORD_LOG LOG_EVENT%ROWTYPE; --日志 V_DATECOL VARCHAR2(32); --获取配置表日期字段 V_DATACOUNT NUMBER; --记录隐式游标属性 V_DBLINK VARCHAR2(64):=VIN_DBLINK; --DBLINK IN_TABNAME VARCHAR2(32):=UPPER(V_IN_TABNAME);--IN层表 V_DATATYPE VARCHAR2(32); --根据数据字典判断数据类型 ODS_IN_DATE VARCHAR2(256):=TO_CHAR(IN_DATE,'YYYY-MM-DD');--配合日期字段为varchar2的ods表 V_LINK_ODS_TABNAME VARCHAR2(64):=V_USER||UPPER(V_ODS_TABNAME)||V_DBLINK; BEGIN --初始化日志 PKG_LOG_EVENT.INITEVENT(RECORD_LOG,V_ODS_TABNAME,IN_TABNAME,IN_DATE); --删除重跑 EXECUTE IMMEDIATE 'TRUNCATE TABLE '||IN_TABNAME; --拼接ODS字段 PKG_TOOLS_CONF_JCJ.PROC_DISP_LONG_STRING_PLUS(V_ODS_TABNAME,ODS_COLNAME,IN_ODS_COLNAME); --获取配置表日期字段 SELECT DATE_COLUMN INTO V_DATECOL FROM WF_NODE_CONF WHERE ODS_TABNAME=V_ODS_TABNAME AND NODE_TABNAME=IN_TABNAME AND WF_CODE='005' AND LAYER='IN'; IF V_DATECOL IS NOT NULL --不为空加入到谓词 THEN --计算IN表前6个字段 SELECT 'PKG_COMM_UTIL.FUNC_GET_DATA_ID(),:A,' ||'PKG_COMM_UTIL.FUNC_BRANCH_CDE_TRANSFER('||NVL(A.BRANCH_COLUMN,'''''')||')'||',' ||NVL(A.BRANCH_COLUMN,'''0000''')||','''||SRC_SYS_NO||''','||'SYSDATE' AS SELECT_COLUMN INTO DEFAULT_COLNAME FROM WF_NODE_CONF A WHERE A.ODS_TABNAME =V_ODS_TABNAME AND A.NODE_TABNAME=IN_TABNAME AND A.LAYER='IN' AND A.WF_CODE='005'; V_SQL:='INSERT /*+APPEND PARALLEL(4)*/ INTO '||IN_TABNAME||' NOLOGGING (DATA_ID,BUSI_DT,BRANCH_CD, BRANCH_CD_ORG,SRC_SYS_NO,INPUT_DT,'||IN_ODS_COLNAME||') SELECT ' ||DEFAULT_COLNAME||','||ODS_COLNAME||' FROM '||V_LINK_ODS_TABNAME||' WHERE '|| V_DATECOL||'=:B'; SELECT DATA_TYPE INTO V_DATATYPE FROM USER_TAB_COLUMNS WHERE TABLE_NAME=V_ODS_TABNAME AND COLUMN_NAME=V_DATECOL; IF V_DATATYPE='DATE'--判断日期字段是date类型还是varchar2采用绑定变量传入参数 THEN EXECUTE IMMEDIATE V_SQL USING IN_DATE,IN_DATE; V_DATACOUNT:=SQL%ROWCOUNT; --插入数据量记录日志 PKG_LOG_EVENT.APPEND_RECORDS(RECORD_LOG,'INSERT:'||V_DATACOUNT); PKG_LOG_EVENT.APPEND_COUNT(RECORD_LOG,V_DATACOUNT); COMMIT; ELSE EXECUTE IMMEDIATE V_SQL USING IN_DATE,ODS_IN_DATE; V_DATACOUNT:=SQL%ROWCOUNT; --插入数据量记录日志 PKG_LOG_EVENT.APPEND_RECORDS(RECORD_LOG,'INSERT:'||V_DATACOUNT); PKG_LOG_EVENT.APPEND_COUNT(RECORD_LOG,V_DATACOUNT); COMMIT; END IF; ELSE --配置表日期字段为空,则全量导入数据 --计算IN表前6个字段 SELECT 'PKG_COMM_UTIL.FUNC_GET_DATA_ID(),:A,' ||'PKG_COMM_UTIL.FUNC_BRANCH_CDE_TRANSFER('||NVL(A.BRANCH_COLUMN,'''''')||')'||',' ||NVL(A.BRANCH_COLUMN,'''0000''')||','''||SRC_SYS_NO||''','||'SYSDATE' AS SELECT_COLUMN INTO DEFAULT_COLNAME FROM WF_NODE_CONF A WHERE A.ODS_TABNAME=V_ODS_TABNAME AND A.NODE_TABNAME=IN_TABNAME AND A.LAYER='IN' AND A.WF_CODE='005'; V_SQL:='INSERT /*+APPEND PARALLEL(4)*/ INTO '||IN_TABNAME||' NOLOGGING (DATA_ID,BUSI_DT,BRANCH_CD, BRANCH_CD_ORG,SRC_SYS_NO,INPUT_DT,'||IN_ODS_COLNAME||') SELECT ' ||DEFAULT_COLNAME||','||ODS_COLNAME||' FROM '||V_LINK_ODS_TABNAME; EXECUTE IMMEDIATE V_SQL USING IN_DATE; V_DATACOUNT:=SQL%ROWCOUNT; --插入数据量记录日志 PKG_LOG_EVENT.APPEND_RECORDS(RECORD_LOG,'INSERT:'||V_DATACOUNT); PKG_LOG_EVENT.APPEND_COUNT(RECORD_LOG,V_DATACOUNT); COMMIT; END IF; --PROC_DISP_LONG_STRING(V_SQL); RECORD_LOG.END_TIME:=SYSDATE; PKG_LOG_EVENT.START_EVENT(RECORD_LOG); EXCEPTION WHEN OTHERS THEN RECORD_LOG.REMARK:=SQLERRM; PKG_LOG_EVENT.START_EVENT(RECORD_LOG); END; PROCEDURE PROC_SWAP_TO_PARTITION_BATCH(VIN_TABNAME VARCHAR2) IS V_TABNAME VARCHAR2(32):=UPPER(VIN_TABNAME); V_BAK_TABNAME VARCHAR2(32); V_TABLENGTH NUMBER; V_NEW_TABNAME VARCHAR2(32); V_CONSTRAIN_NAME VARCHAR2(1024); V_INDEX_NAME VARCHAR2(1024); V_BAKINDEX VARCHAR2(32); V_TABCOMMENT VARCHAR2(512); V_COLCOMMENT VARCHAR2(512); V_COLCOUNT NUMBER; V_EVENT_DESC VARCHAR2(64):='HEAPTAB_TO_PARTITIONTAB'; V_DATE DATE:=TRUNC(SYSDATE); RECORD_LOG LOG_EVENT%ROWTYPE; V_COLNAME CLOB; V_CREATE_SQL CLOB; V_SQL CLOB; V_INDEX_SQL CLOB; V_EXEC_INDEX_SQL CLOB; V_INSERT_COLUMN CLOB; V_SELECT_COLUMN CLOB; V_PARTCOL CLOB:='PARTITION BY RANGE ("BUSI_DT") INTERVAL (NUMTOYMINTERVAL(1,''MONTH'')) STORE IN ("MDR") (PARTITION "PM_201804" VALUES LESS THAN (TO_DATE(''2018-05-01'',''YYYY-MM-DD'')))'; BEGIN --初始化日志 PKG_LOG_EVENT.INITEVENT(RECORD_LOG,V_TABNAME,V_EVENT_DESC,V_DATE); --获取原装创建表语句 SELECT SUBSTR(SUBSTR(DBMS_METADATA.GET_DDL('TABLE',V_TABNAME), INSTR(DBMS_METADATA.GET_DDL('TABLE',V_TABNAME),'(',1,1)), 1, INSTR(SUBSTR(DBMS_METADATA.GET_DDL('TABLE',V_TABNAME),INSTR(DBMS_METADATA.GET_DDL('TABLE',V_TABNAME),'(',1,1)),' ) ',1,1)+1) INTO V_COLNAME FROM DUAL; --拼接新表名 SELECT LENGTH(V_TABNAME) INTO V_TABLENGTH FROM DUAL; IF V_TABLENGTH<28 THEN V_NEW_TABNAME:=V_TABNAME||'_P'; ELSE V_NEW_TABNAME:=SUBSTR(V_TABNAME,1,28)||'_P'; END IF; --创建表语句 V_CREATE_SQL:='CREATE TABLE '||V_NEW_TABNAME||V_COLNAME||V_PARTCOL; /*INSERT INTO DATA_CONTROL_JCJTEST_LOG(SQL_TEXT,EXEC_DATE) VALUES(V_CREATE_SQL,SYSDATE); COMMIT;*/ --执行创建表语句 --EXECUTE IMMEDIATE V_CREATE_SQL; --EXECUTE IMMEDIATE 'ALTER TABLE '||V_NEW_TABNAME||' NOLOGGING'; --记录日志 PKG_LOG_EVENT.APPEND_RECORDS(RECORD_lOG,'CREATE:'||V_NEW_TABNAME); --获取源表字段 PKG_TOOLS_CONF_JCJ.PROC_DISP_LONG_STRING_PLUS(V_TABNAME,V_INSERT_COLUMN,V_SELECT_COLUMN); --同步数据到新表 V_SQL:='INSERT /*+APPEND NOLOGGING PARALELL(4)*/ INTO '||V_NEW_TABNAME||'('||V_INSERT_COLUMN||') SELECT '||V_SELECT_COLUMN||' FROM '||V_TABNAME; --EXECUTE IMMEDIATE V_SQL; --记录插入数据 PKG_LOG_EVENT.APPEND_COUNT(RECORD_LOG,SQL%ROWCOUNT); COMMIT; --复制约束和索引 FOR I IN (SELECT A.INDEX_NAME,B.CONSTRAINT_NAME FROM USER_INDEXES A,USER_CONSTRAINTS B WHERE A.INDEX_NAME=B.CONSTRAINT_NAME(+) AND A.TABLE_NAME=V_TABNAME) LOOP IF I.CONSTRAINT_NAME IS NOT NULL THEN SELECT REPLACE(SUBSTR(DBMS_METADATA.GET_DDL('CONSTRAINT',I.CONSTRAINT_NAME), 1, INSTR(DBMS_METADATA.GET_DDL('CONSTRAINT',I.CONSTRAINT_NAME),'USING INDEX ',1,1)+10), V_TABNAME, V_NEW_TABNAME) INTO V_CONSTRAIN_NAME FROM DUAL; SELECT REPLACE(I.INDEX_NAME,'IDX','BAK') INTO V_BAKINDEX FROM DUAL; --EXECUTE IMMEDIATE 'ALTER INDEX '||I.INDEX_NAME||' RENAME TO '||V_BAKINDEX; --EXECUTE IMMEDIATE V_CONSTRAIN_NAME||' LOCAL'; ELSE SELECT REPLACE(SUBSTR(DBMS_METADATA.GET_DDL('INDEX',I.INDEX_NAME), 1, INSTR(DBMS_METADATA.GET_DDL('INDEX',I.INDEX_NAME),') ',1,1)+1), V_TABNAME, V_NEW_TABNAME) INTO V_INDEX_NAME FROM DUAL; SELECT REPLACE(I.INDEX_NAME,'IDX','BAK') INTO V_BAKINDEX FROM DUAL; V_INDEX_SQL:='ALTER INDEX '||I.INDEX_NAME||' RENAME TO '||V_BAKINDEX; --EXECUTE IMMEDIATE V_INDEX_SQL; V_EXEC_INDEX_SQL:=V_INDEX_NAME||' LOCAL'; --EXECUTE IMMEDIATE V_EXEC_INDEX_SQL; END IF; END LOOP; --记录创建索引 PKG_LOG_EVENT.APPEND_RECORDS(RECORD_lOG,',CREATED INDEX'); --同步表注释 SELECT 'COMMENT ON TABLE '||V_NEW_TABNAME||' IS '''||COMMENTS||'''' INTO V_TABCOMMENT FROM USER_TAB_COMMENTS WHERE TABLE_NAME=V_TABNAME; --EXECUTE IMMEDIATE V_TABCOMMENT; --同步字段注释 SELECT COUNT(*) INTO V_COLCOUNT FROM USER_COL_COMMENTS WHERE TABLE_NAME=V_TABNAME AND COMMENTS IS NOT NULL; IF V_COLCOUNT>0 THEN FOR J IN (SELECT COLUMN_NAME,COMMENTS FROM USER_COL_COMMENTS WHERE TABLE_NAME=V_TABNAME AND COMMENTS IS NOT NULL) LOOP V_COLCOMMENT:='COMMENT ON COLUMN '||V_NEW_TABNAME||'.'||J.COLUMN_NAME||' IS ''' ||J.COMMENTS||''''; --EXECUTE IMMEDIATE V_COLCOMMENT; END LOOP; END IF; --备份源表修改“ODS/DML为“BAK_”,新表RENAME为源表; SELECT REGEXP_REPLACE(V_TABNAME,'(^ODS|^DML)','BAK') INTO V_BAK_TABNAME FROM DUAL; --EXECUTE IMMEDIATE 'RENAME '||V_TABNAME ||' TO '||V_BAK_TABNAME; --EXECUTE IMMEDIATE 'RENAME '||V_NEW_TABNAME||' TO '||V_TABNAME; --记录日志 PKG_LOG_EVENT.APPEND_RECORDS(RECORD_lOG,',BAK:'||V_BAK_TABNAME); RECORD_lOG.END_TIME:=SYSDATE; PKG_LOG_EVENT.START_EVENT(RECORD_LOG); INSERT INTO DATA_CONTROL_JCJTEST_LOG(SQL_TEXT,EXEC_DATE) VALUES(V_CREATE_SQL||CHR(10)||V_SQL||CHR(10)||V_CONSTRAIN_NAME||CHR(10) ||V_INDEX_SQL||CHR(10)||V_EXEC_INDEX_SQL,SYSDATE); COMMIT; EXCEPTION WHEN OTHERS THEN RECORD_LOG.REMARK:=SQLERRM; PKG_LOG_EVENT.START_EVENT(RECORD_LOG); END; FUNCTION FUNC_LONG_TO_CHAR(VIN_TABNAME VARCHAR2,VIN_DATE DATE) RETURN VARCHAR2 IS V_TABNAME VARCHAR2(32):=UPPER(VIN_TABNAME); V_PARTITION_HIGH_VALUE VARCHAR2(4000); V_STR_DATE DATE:=TRUNC(VIN_DATE,'dd'); V_OUTPUT_PARTITION_NAME VARCHAR2(64); BEGIN FOR I IN( SELECT PARTITION_NAME,HIGH_VALUE FROM USER_TAB_PARTITIONS WHERE TABLE_NAME=V_TABNAME) LOOP SELECT I.PARTITION_NAME,REGEXP_SUBSTR(I.HIGH_VALUE,'\d{4}-\d{2}-\d{2}',1,1) -- \d{2}:\d{2}:\d{2} INTO V_OUTPUT_PARTITION_NAME,V_PARTITION_HIGH_VALUE FROM DUAL; /*RETURN V_PARTITION_HIGH_VALUE;*/ IF V_STR_DATE<TO_DATE(V_PARTITION_HIGH_VALUE,'YYYY-MM-DD') AND V_STR_DATE>=TRUNC(TRUNC(TO_DATE(V_PARTITION_HIGH_VALUE,'YYYY-MM-DD'),'MM')-1,'MM') THEN RETURN V_OUTPUT_PARTITION_NAME; ELSE V_OUTPUT_PARTITION_NAME:='NON-EXISTENT'; END IF; END LOOP; RETURN V_OUTPUT_PARTITION_NAME; END; FUNCTION FUNC_LONG_TO_CHAR_PLUS(VIN_TABNAME VARCHAR2,V_PARTNAME VARCHAR2) RETURN VARCHAR2 IS V_PARTITION_HIGH_VALUE VARCHAR2(512); V_OUTPUT_HIGH_VALUE VARCHAR2(512); BEGIN SELECT HIGH_VALUE INTO V_PARTITION_HIGH_VALUE FROM USER_TAB_PARTITIONS WHERE TABLE_NAME=UPPER(VIN_TABNAME) AND PARTITION_NAME=UPPER(V_PARTNAME); SELECT V_PARTITION_HIGH_VALUE INTO V_OUTPUT_HIGH_VALUE FROM DUAL; RETURN V_OUTPUT_HIGH_VALUE; END; /********************************************************************************** 自动处理异常信息中的varchar2长度不足 =================================================================================== V1.0 2018-11-23 JIANGCHANGJIAN INITIAL ***********************************************************************************/ PROCEDURE PROC_AUTO_MODIFY_VARCHAR2(VIN_SQLERRM VARCHAR2) IS V_SQLERRM VARCHAR2(512):=VIN_SQLERRM; V_SQLERRM_TYPE VARCHAR2(256); V_TABLE_INFO VARCHAR2(256); V_TABNAME VARCHAR2(256); V_COLNAME VARCHAR2(256); V_DATA_TYPE VARCHAR2(256); V_ACTUAL_LENGTH INTEGER:=''; V_SQL VARCHAR2(1024); BEGIN SELECT REGEXP_SUBSTR(V_SQLERRM,'ORA-12899',1,1,'m') INTO V_SQLERRM_TYPE FROM DUAL; IF V_SQLERRM_TYPE='ORA-12899' THEN --截取表相关信息 SELECT REGEXP_SUBSTR(V_SQLERRM,'\"UUPSDB2\"\.\"\w{1,30}\"\.\"\w{1,30}\"',1,1,'m') INTO V_TABLE_INFO FROM DUAL; --截取表名/字段名 SELECT REPLACE(REPLACE(REGEXP_SUBSTR(V_TABLE_INFO,'\.\"\w{1,30}\"\.',1,1,'m'),'."',''),'".',''), REPLACE(REGEXP_SUBSTR(V_TABLE_INFO,'\"\w{1,30}\"$',1,1),'"','') INTO V_TABNAME,V_COLNAME FROM DUAL; --截取字段插入数据的实际长度 SELECT REGEXP_SUBSTR(REGEXP_SUBSTR(V_SQLERRM,'\(actual\:.*\,',1,1,'m') ,'[0-9]{1,5}',1,1,'m') INTO V_ACTUAL_LENGTH FROM DUAL; IF V_ACTUAL_LENGTH<=200 --修改为实际长度的5倍 THEN V_ACTUAL_LENGTH:=V_ACTUAL_LENGTH*5; ELSIF 200<V_ACTUAL_LENGTH AND V_ACTUAL_LENGTH<=1000 --修改为实际长度的2倍 THEN V_ACTUAL_LENGTH:=V_ACTUAL_LENGTH*2; ELSIF 1000<V_ACTUAL_LENGTH AND V_ACTUAL_LENGTH<=3500 --修为实际长度的增加500 THEN V_ACTUAL_LENGTH:=V_ACTUAL_LENGTH+500; END IF; SELECT DATA_TYPE INTO V_DATA_TYPE FROM USER_TAB_COLUMNS WHERE TABLE_NAME=V_TABNAME AND COLUMN_NAME=V_COLNAME; --拼接DDL语句 V_SQL:='ALTER TABLE '||V_TABNAME||' MODIFY('||V_COLNAME||' '||V_DATA_TYPE||'('||V_ACTUAL_LENGTH||'))'; EXECUTE IMMEDIATE V_SQL; END IF; END; PROCEDURE PROC_EXEC_SP(VIN_DATE DATE,SP_NAME VARCHAR2) IS IN_IMPORT_DATE DATE; IN_BUSI_DATE DATE:=VIN_DATE; V_PARAM PROC_PARAM_TYPE; V_EVENT_DESC VARCHAR2(256):=UPPER(SP_NAME); V_EVENT_NAME VARCHAR2(32); RECORD_LOG LOG_EVENT%ROWTYPE; BEGIN SELECT NODE_TABNAME INTO V_EVENT_NAME FROM WF_NODE_CONF WHERE WF_CODE='005' AND SP_NAME=V_EVENT_DESC; PKG_LOG_EVENT.INITEVENT(RECORD_LOG,V_EVENT_NAME,V_EVENT_DESC,IN_BUSI_DATE); V_PARAM:=PROC_PARAM_TYPE(0,'',IN_BUSI_DATE,IN_IMPORT_DATE,''); EXECUTE IMMEDIATE 'BEGIN '||V_EVENT_DESC||'(:A); END;' USING IN OUT V_PARAM; RECORD_LOG.REMARK:=V_PARAM.OUT_RET_MSG; RECORD_LOG.END_TIME:=SYSDATE; PKG_LOG_EVENT.START_EVENT(RECORD_LOG); EXCEPTION WHEN OTHERS THEN RECORD_LOG.REMARK:=SQLERRM; PKG_LOG_EVENT.START_EVENT(RECORD_LOG); END; PROCEDURE PROC_REF_CURSOR_EXEC IS TYPE REF_CUR IS REF CURSOR; L_CURSOR REF_CUR; REF_CURSOR EXEC_PROC_QUEUE%ROWTYPE; BEGIN OPEN L_CURSOR FOR SELECT NODE_TABNAME,STATUS,REMARK FROM EXEC_PROC_QUEUE WHERE STATUS='READY'; FETCH L_CURSOR INTO REF_CURSOR; WHILE L_CURSOR%FOUND LOOP INSERT INTO EXEC_PROC_QUEUE_BAK(NODE_TABNAME,STATUS,REMARK) VALUES(REF_CURSOR.NODE_TABNAME,REF_CURSOR.STATUS,REF_CURSOR.REMARK); COMMIT; UPDATE EXEC_PROC_QUEUE T SET T.STATUS='OK' WHERE T.STATUS='READY' AND T.NODE_TABNAME=REF_CURSOR.NODE_TABNAME; COMMIT; FETCH L_CURSOR INTO REF_CURSOR; END LOOP; CLOSE L_CURSOR; EXCEPTION WHEN OTHERS THEN CLOSE L_CURSOR; END; FUNCTION FUNC_GET_JGXXGXB_INFO(V_XZQHDM VARCHAR2,IN_BUSI_DT DATE)RETURN TYPE_JGXXGXB_CCCL IS V_JGXXGXB_RECORD TYPE_JGXXGXB_CCCL; BEGIN V_JGXXGXB_RECORD:=TYPE_JGXXGXB_CCCL('','',''); SELECT DISTINCT SUPER_MANAGEMENT_ORG_NAM,SUPER_MANAGEMENT_ORG_CODE,SCOPE_BUSINESS INTO V_JGXXGXB_RECORD.SUPER_MANAGEMENT_ORG_NAM, V_JGXXGXB_RECORD.SUPER_MANAGEMENT_ORG_CODE, V_JGXXGXB_RECORD.SCOPE_BUSINESS FROM ODS_IF_MU_JGXXGXB_CCCL WHERE XZQHDM=V_XZQHDM AND BUSI_DT=IN_BUSI_DT; RETURN V_JGXXGXB_RECORD; END; /*FUNCTION FUNC_GET_IDX_COLUMNS(VIN_TABNAME VARCHAR2) RETURN TYPE_GET_IDX_COLUMNS_ARR PIPELINED IS V_TABNAME VARCHAR2(32):=UPPER(VIN_TABNAME); V_TYPE_TAB TYPE_GET_IDX_COLUMNS; BEGIN FOR I IN (SELECT INDEX_NAME,TABLE_NAME, LISTAGG(COLUMN_NAME,',')WITHIN GROUP(ORDER BY COLUMN_POSITION) AS V_COLUMNS FROM USER_IND_COLUMNS WHERE TABLE_NAME=(V_TABNAME) GROUP BY INDEX_NAME,TABLE_NAME) LOOP V_TYPE_TAB.ARR_INDEX_NAME:=I.INDEX_NAME; V_TYPE_TAB.ARR_TABLE_NAME:=I.TABLE_NAME; V_TYPE_TAB.ARR_V_COLUMNS :=I.V_COLUMNS; PIPE ROW (V_TYPE_TAB); END LOOP; END;*/ PROCEDURE FUNC_GET_IDX_COLUMNS_PLUS(VIN_TABNAME VARCHAR2) /*RETURN TYPE_ROWS PIPELINED*/ IS V_TABNAME VARCHAR2(32):=UPPER(VIN_TABNAME); V_TYPE_TABLE TYPE_COLUMNS; V_TYPE_INDEX TYPE_COLUMNS; V_TYPE_COLUMNS TYPE_COLUMNS; V_TYPE_ROWS TYPE_ROWS:=TYPE_ROWS(V_TYPE_TABLE); BEGIN SELECT INDEX_NAME,TABLE_NAME, LISTAGG(COLUMN_NAME,',')WITHIN GROUP(ORDER BY COLUMN_POSITION) AS V_COLUMNS BULK COLLECT INTO V_TYPE_INDEX,V_TYPE_TABLE,V_TYPE_COLUMNS FROM USER_IND_COLUMNS WHERE TABLE_NAME=(V_TABNAME) GROUP BY INDEX_NAME,TABLE_NAME; /*V_TYPE_TABLE :=TYPE_COLUMNS('111','333'); V_TYPE_INDEX :=TYPE_COLUMNS('222','444'); V_TYPE_COLUMNS:=TYPE_COLUMNS('555','666');*/ V_TYPE_ROWS.EXTEND; V_TYPE_ROWS(1):=V_TYPE_TABLE; V_TYPE_ROWS.EXTEND; V_TYPE_ROWS(2):=V_TYPE_INDEX; V_TYPE_ROWS.EXTEND; V_TYPE_ROWS(3):=V_TYPE_COLUMNS; FOR J IN 1 .. 3 LOOP INSERT INTO ARRAY_IND_ROWS VALUES(V_TYPE_ROWS(J)(1),V_TYPE_ROWS(J)(2),V_TYPE_ROWS(J)(3),V_TYPE_ROWS(J)(4), V_TYPE_ROWS(J)(5)); COMMIT; /*FOR I IN 1 .. 5 LOOP DBMS_OUTPUT.PUT_LINE(V_TYPE_ROWS(J)(I)); END LOOP;*/ END LOOP; --RETURN V_TYPE_ROWS; END; PROCEDURE PROC_DATA_ACQUISITION(VIN_TABNAME VARCHAR2) IS V_BRANCH_CD VARCHAR2(20); V_BRANCH_CD_ORG VARCHAR2(20); V_SRC_SYS_NO VARCHAR2(64); V_TABNAME VARCHAR2(32):=UPPER(VIN_TABNAME); V_DATE DATE:=DATE'2018-06-30'; BEGIN EXECUTE IMMEDIATE 'SELECT BRANCH_CD,BRANCH_CD_ORG,SRC_SYS_NO FROM '||V_TABNAME|| ' WHERE ROWNUM=1 AND BUSI_DT=:A AND BRANCH_CD IS NOT NULL' INTO V_BRANCH_CD,V_BRANCH_CD_ORG,V_SRC_SYS_NO USING V_DATE; EXECUTE IMMEDIATE 'INSERT INTO IF_TABLE_BRANCH_CD (NODE_CODE,BRANCH_CD,BRANCH_CD_ORG,SRC_SYS_NO) VALUES('''||V_TABNAME||''','''||V_BRANCH_CD||''', '''||V_BRANCH_CD_ORG||''','''||V_SRC_SYS_NO||''')'; COMMIT; EXCEPTION WHEN OTHERS THEN EXECUTE IMMEDIATE 'INSERT INTO IF_TABLE_BRANCH_CD (NODE_CODE,BRANCH_CD,BRANCH_CD_ORG) VALUES('''||V_TABNAME||''','''||SQLERRM||''','''||SYSDATE||''')'; COMMIT; END; PROCEDURE PROC_UNI_OUTPUT_SQLERRM(PARAM IN OUT PROC_PARAM_TYPE,V_SQLERRM VARCHAR2) IS BEGIN PARAM.OUT_RET :=1; PARAM.OUT_RET_MSG :=V_SQLERRM; END; PROCEDURE PROC_COLUMN_ORDER_CHANGE(VIN_TABNAME VARCHAR2) IS V_TABLE_DDL CLOB; V_COLUMN_NAME_ALL CLOB; V_TABNAME VARCHAR2(32):=UPPER(VIN_TABNAME); --MIN_COL_ORDER NUMBER; --V_COMMENTS VARCHAR2(1000); V_COL_COUNT NUMBER; BEGIN DELETE COLUMN_ORDER_CHANGE T WHERE T.TABLE_NAME=V_TABNAME; COMMIT; SELECT DBMS_METADATA.GET_DDL('TABLE',''||V_TABNAME||'') INTO V_TABLE_DDL FROM DUAL; SELECT COUNT(*) INTO V_COL_COUNT FROM USER_TAB_COLUMNS WHERE TABLE_NAME=V_TABNAME; V_COLUMN_NAME_ALL:=RTRIM(LTRIM(REGEXP_SUBSTR(V_TABLE_DDL, '\(.{0,10}?\".{0,30}?\,.*\".{0,25}'||CHR(10)||'\s{0,20}?\)', 1, 1, 'n'), '('), ')'); INSERT INTO COLUMN_ORDER_CHANGE(TABLE_NAME,COLUMN_NAME,DATA_TYPE,COL_ORDER) SELECT ''||V_TABNAME||'' AS TABLE_NAME, TO_CHAR(REGEXP_SUBSTR(V_COLUMN_NAME_ALL, '[^"]+',1,ROWNUM*2) ) AS COLUMN_NAME, REGEXP_REPLACE(TO_CHAR(REGEXP_SUBSTR(V_COLUMN_NAME_ALL, '[^"]+',1,ROWNUM*2+1) ), '(, '||CHR(10)||' | CONSTRAINT )', '') AS DATA_TYPE, ROWNUM*100 AS COL_ORDER FROM DUAL CONNECT BY LEVEL<= V_COL_COUNT; COMMIT; --DBMS_OUTPUT.PUT_LINE(REGEXP_COUNT(V_COLUMN_NAME_ALL,'"')/2||','||V_COL_COUNT); /* SELECT MIN(COL_ORDER) INTO MIN_COL_ORDER FROM COLUMN_ORDER_CHANGE WHERE COLUMN_NAME IN ('LLB_CODE', 'LLB_CODE_SHORT', 'NAT', 'COUNTRY', 'CUSTOMER_TYPE'); DELETE COLUMN_ORDER_CHANGE WHERE COLUMN_NAME IN ('LLB_CODE', 'LLB_CODE_SHORT', 'NAT', 'COUNTRY', 'CUSTOMER_TYPE'); COMMIT; INSERT \*+APPEND*\ INTO COLUMN_ORDER_CHANGE NOLOGGING (COL_ORDER, TABLE_NAME, COLUMN_NAME, DATA_TYPE) VALUES(''||MIN_COL_ORDER||'', ''||V_TABNAME||'', ''||MIN_COL_ORDER||'', ''||MIN_COL_ORDER||''); COMMIT; SELECT 'COMMENT ON COLUMN '||TABLE_NAME||'.'||COLUMN_NAME||' IS '''||COMMENTS||'''' INTO V_COMMENTS FROM USER_COL_COMMENTS WHERE TABLE_NAME=V_TABNAME; EXECUTE IMMEDIATE V_COMMENTS;*/ END; FUNCTION FUNC_GET_LD_INT_RATE(IN_LD_TYPE VARCHAR2, IN_CURRENCY VARCHAR2, IN_PERIOD VARCHAR2, IN_BUSI_DT DATE) RETURN NUMBER IS V_INT_RATE NUMBER; BEGIN SELECT INT_RATE INTO V_INT_RATE FROM (SELECT T.*,ROW_NUMBER()OVER(PARTITION BY LD_TYPE,CURRENCY,PERIOD,BUSI_DT ORDER BY EFFECTIVE_DT DESC) AS RN FROM ODS_IF_MU_INTEREST_RATE T WHERE LD_TYPE =UPPER(IN_LD_TYPE) AND CURRENCY=UPPER(IN_CURRENCY) AND PERIOD =UPPER(IN_PERIOD) AND EFFECTIVE_DT<=IN_BUSI_DT) WHERE RN=1; RETURN V_INT_RATE; END; FUNCTION FUNC_GET_CITI_DEPO_RATE(IN_CURRENCY VARCHAR2, IN_PERIOD VARCHAR2, IN_BUSI_DT DATE) RETURN NUMBER IS V_INT_RATE NUMBER; BEGIN SELECT INT_RATE INTO V_INT_RATE FROM (SELECT INT_RATE.*,ROW_NUMBER()OVER(PARTITION BY LD_TYPE,CURRENCY,PERIOD,BUSI_DT ORDER BY EFFECTIVE_DT DESC) AS RN FROM ODS_IF_MU_INTEREST_RATE INT_RATE WHERE INT_RATE.CITI_BENCHMARK='C' AND INT_RATE.LD_TYPE='D' AND INT_RATE.CURRENCY=UPPER(IN_CURRENCY) AND INT_RATE.PERIOD =UPPER(IN_PERIOD) AND INT_RATE.EFFECTIVE_DT<=IN_BUSI_DT) WHERE RN=1; RETURN V_INT_RATE; END; FUNCTION FUNC_GET_CITI_LOAN_RATE(IN_CURRENCY VARCHAR2, IN_PERIOD VARCHAR2, IN_BUSI_DT DATE) RETURN NUMBER IS V_INT_RATE NUMBER; BEGIN SELECT INT_RATE INTO V_INT_RATE FROM (SELECT INT_RATE.*,ROW_NUMBER()OVER(PARTITION BY LD_TYPE,CURRENCY,PERIOD,BUSI_DT ORDER BY EFFECTIVE_DT DESC) AS RN FROM ODS_IF_MU_INTEREST_RATE INT_RATE WHERE INT_RATE.CITI_BENCHMARK='C' AND INT_RATE.LD_TYPE='L' AND INT_RATE.CURRENCY=UPPER(IN_CURRENCY) AND INT_RATE.PERIOD =UPPER(IN_PERIOD) AND INT_RATE.EFFECTIVE_DT<=IN_BUSI_DT) WHERE RN=1; RETURN V_INT_RATE; END; FUNCTION FUNC_GET_BM_DEPO_RATE(IN_CURRENCY VARCHAR2, IN_PERIOD VARCHAR2, IN_BUSI_DT DATE) RETURN NUMBER IS V_INT_RATE NUMBER; BEGIN SELECT INT_RATE INTO V_INT_RATE FROM (SELECT INT_RATE.*,ROW_NUMBER()OVER(PARTITION BY LD_TYPE,CURRENCY,PERIOD,BUSI_DT ORDER BY EFFECTIVE_DT DESC) AS RN FROM ODS_IF_MU_INTEREST_RATE INT_RATE WHERE INT_RATE.CITI_BENCHMARK='B' AND INT_RATE.LD_TYPE='D' AND INT_RATE.CURRENCY=UPPER(IN_CURRENCY) AND INT_RATE.PERIOD =UPPER(IN_PERIOD) AND INT_RATE.EFFECTIVE_DT<=IN_BUSI_DT) WHERE RN=1; RETURN V_INT_RATE; END; FUNCTION FUNC_GET_BM_LOAN_RATE(IN_CURRENCY VARCHAR2, IN_PERIOD VARCHAR2, IN_BUSI_DT DATE) RETURN NUMBER IS V_INT_RATE NUMBER; BEGIN SELECT INT_RATE INTO V_INT_RATE FROM (SELECT INT_RATE.*,ROW_NUMBER()OVER(PARTITION BY LD_TYPE,CURRENCY,PERIOD,BUSI_DT ORDER BY EFFECTIVE_DT DESC) AS RN FROM ODS_IF_MU_INTEREST_RATE INT_RATE WHERE INT_RATE.CITI_BENCHMARK='B' AND INT_RATE.LD_TYPE='M' AND INT_RATE.CURRENCY=UPPER(IN_CURRENCY) AND INT_RATE.PERIOD =UPPER(IN_PERIOD) AND INT_RATE.EFFECTIVE_DT<=IN_BUSI_DT) WHERE RN=1; RETURN V_INT_RATE; END; PROCEDURE PROC_BRANCH_CD_COLLECT IS V_COUNT NUMBER; V_BRANCH VARCHAR2(64); BEGIN EXECUTE IMMEDIATE 'TRUNCATE TABLE BRANCH_CD_COLLECT'; FOR I IN (SELECT NODE_CODE FROM WF_NODE_CONF WHERE WF_CODE='005' AND LAYER='IN' AND SRC_SYS_NO NOT IN('DWH','MU')) LOOP EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM '||I.NODE_CODE||' WHERE BRANCH_CD_ORG=''C41'' ' INTO V_COUNT; IF V_COUNT>0 THEN EXECUTE IMMEDIATE 'SELECT BRANCH_CD_ORG FROM '||I.NODE_CODE||' WHERE BRANCH_CD_ORG=''C41'' AND ROWNUM<=1' INTO V_BRANCH; INSERT INTO BRANCH_CD_COLLECT(TABLE_NAME,BRANCH_CD) VALUES(''||I.NODE_CODE||'',''||V_BRANCH||''); COMMIT; END IF; END LOOP; END; PROCEDURE PROC_GET_TABLE_FROM_PKG(VIN_PKGNAME VARCHAR2) IS TYPE V_NESTED_TAB IS TABLE OF USER_DEPENDENCIES.REFERENCED_NAME%TYPE INDEX BY PLS_INTEGER; V_BULK_COLLECT V_NESTED_TAB; V_PKGNAME VARCHAR2(32):=UPPER(VIN_PKGNAME); V_PKG_BODY CLOB; V_PROC_BODY CLOB; V_INSERT_BODY VARCHAR2(512); V_NODE_TABNAME VARCHAR2(256); V_PRENODE_TABNAME VARCHAR2(256); V_SQLERRM VARCHAR2(256); BEGIN SELECT DBMS_METADATA.GET_DDL('PACKAGE_BODY',V_PKGNAME) INTO V_PKG_BODY FROM DUAL; SELECT REFERENCED_NAME BULK COLLECT INTO V_BULK_COLLECT FROM USER_DEPENDENCIES WHERE NAME=VIN_PKGNAME AND REFERENCED_OWNER='UUPSDB2' AND REFERENCED_TYPE='TABLE' AND REGEXP_LIKE(REFERENCED_NAME,'(^ODS\_IN|^ODS\_IF|DML\_SD)'); EXECUTE IMMEDIATE 'TRUNCATE TABLE GET_TABLE_FROM_PKG'; EXECUTE IMMEDIATE 'TRUNCATE TABLE DATA_CONTROL_JCJTEST_LOG'; FOR I IN (SELECT DISTINCT OBJECT_NAME,PACKAGE_NAME FROM USER_ARGUMENTS WHERE PACKAGE_NAME=V_PKGNAME) LOOP SELECT REGEXP_SUBSTR(V_PKG_BODY, 'PROCEDURE\s{1,10}'||I.OBJECT_NAME||'\W.*?SQLERRM.{0,20}?' ||CHR(10)||'{1,20}?.{1,100}?END',1,1,'n') INTO V_PROC_BODY FROM DUAL; INSERT INTO DATA_CONTROL_JCJTEST_LOG(SQL_TEXT,EXEC_DATE,SP_NAME) VALUES(V_PROC_BODY,SYSDATE,I.OBJECT_NAME); COMMIT; FOR Q IN V_BULK_COLLECT.FIRST .. V_BULK_COLLECT.LAST LOOP SELECT REGEXP_SUBSTR(V_PROC_BODY, 'INSERT.{1,40}INTO\s{1,10}'||V_BULK_COLLECT(Q)||'\W?',1,1,'n') INTO V_INSERT_BODY FROM DUAL; SELECT REGEXP_SUBSTR(V_INSERT_BODY,V_BULK_COLLECT(Q),1,1,'n') INTO V_NODE_TABNAME FROM DUAL; SELECT REGEXP_REPLACE(REGEXP_SUBSTR(V_PROC_BODY, '\W'||V_BULK_COLLECT(Q)||'\W', 1, 1, 'n'), '\W', '') INTO V_PRENODE_TABNAME FROM DUAL; IF V_PRENODE_TABNAME IS NOT NULL AND V_NODE_TABNAME IS NOT NULL THEN INSERT INTO GET_TABLE_FROM_PKG(NODE_TABNAME,PRENODE_TABNAME,SP_NAME,PKG_NAME,PROC_NAME) VALUES(V_NODE_TABNAME,V_NODE_TABNAME,I.PACKAGE_NAME||'.' ||I.OBJECT_NAME,I.PACKAGE_NAME,I.OBJECT_NAME); COMMIT; ELSIF V_PRENODE_TABNAME IS NOT NULL AND V_NODE_TABNAME IS NULL THEN INSERT INTO GET_TABLE_FROM_PKG(PRENODE_TABNAME,SP_NAME,PKG_NAME,PROC_NAME) VALUES(V_PRENODE_TABNAME,I.PACKAGE_NAME||'.' ||I.OBJECT_NAME,I.PACKAGE_NAME,I.OBJECT_NAME); COMMIT; END IF; END LOOP; END LOOP; FOR J IN (SELECT NODE_TABNAME,PROC_NAME FROM GET_TABLE_FROM_PKG WHERE NODE_TABNAME IS NOT NULL) LOOP UPDATE GET_TABLE_FROM_PKG T SET T.NODE_TABNAME=J.NODE_TABNAME WHERE T.PROC_NAME=J.PROC_NAME; COMMIT; END LOOP; DELETE GET_TABLE_FROM_PKG T WHERE T.NODE_TABNAME=T.PRENODE_TABNAME; COMMIT; DELETE GET_TABLE_FROM_PKG_HIS WHERE PKG_NAME=V_PKGNAME; COMMIT; INSERT INTO GET_TABLE_FROM_PKG_HIS (SEQ, IN_TIME, NODE_TABNAME, PRENODE_TABNAME, SP_NAME, PKG_NAME, PROC_NAME) SELECT SEQ_LOG_EVENT.NEXTVAL AS SEQ, SYSDATE AS IN_TIME, NODE_TABNAME, PRENODE_TABNAME, SP_NAME, PKG_NAME, PROC_NAME FROM GET_TABLE_FROM_PKG; COMMIT; EXCEPTION WHEN OTHERS THEN V_SQLERRM:=SQLERRM; INSERT INTO GET_TABLE_FROM_PKG_HIS(SEQ,IN_TIME,SP_NAME) VALUES(1,SYSDATE,''||V_SQLERRM||''); COMMIT; END; PROCEDURE PROC_CREATE_IN_TAB(IN_PARAM IN OUT TYPE_CREATE_IN_TAB) IS VIN_ODS_TABNAME VARCHAR2(32); VIN_IN_TABNAME VARCHAR2(32); V_INDEX_NAME VARCHAR2(32); V_IN_IDX_DDL VARCHAR2(256); V_ADD_COL VARCHAR2(256); V_TABCOUNT NUMBER; V_IDXCOUNT NUMBER; V_ODS_TAB_DDL CLOB; V_ODS_COLUMNS CLOB; V_IN_DDL CLOB; BEGIN VIN_ODS_TABNAME :=UPPER(IN_PARAM.V_ODS_TABNAME); VIN_IN_TABNAME :=UPPER(IN_PARAM.V_IN_TABNAME); SELECT COUNT(*) INTO V_TABCOUNT FROM USER_TABLES WHERE TABLE_NAME=VIN_IN_TABNAME; IF V_TABCOUNT=0 THEN V_ADD_COL:='DATA_ID NUMBER, BUSI_DT DATE, BRANCH_CD VARCHAR2(10), BRANCH_CD_ORG VARCHAR2(10), SRC_SYS_NO VARCHAR2(128), INPUT_DT DATE,'; SELECT DBMS_METADATA.GET_DDL('TABLE',''||VIN_ODS_TABNAME||'') INTO V_ODS_TAB_DDL FROM DUAL; V_ODS_COLUMNS:=RTRIM(LTRIM(REGEXP_SUBSTR(V_ODS_TAB_DDL, '\(.{0,10}?\".{0,30}?\,.*\".{0,25}'||CHR(10)||'\s{0,20}?\)', 1, 1, 'n'), '('), ')'); V_IN_DDL:='CREATE TABLE '||VIN_IN_TABNAME||'('||V_ADD_COL||V_ODS_COLUMNS||') TABLESPACE "MDR" NOLOGGING'; EXECUTE IMMEDIATE V_IN_DDL; --PROC_DISP_LONG_STRING(V_IN_DDL); END IF; V_INDEX_NAME:='IDX_'||RTRIM(SUBSTR(VIN_IN_TABNAME,1,23),'_')||'_99'; SELECT COUNT(*) INTO V_IDXCOUNT FROM USER_IND_COLUMNS WHERE TABLE_NAME=VIN_IN_TABNAME AND COLUMN_NAME='BUSI_DT'; IF V_IDXCOUNT=0 THEN V_IN_IDX_DDL:='CREATE INDEX '||V_INDEX_NAME||' ON '||VIN_IN_TABNAME||'(BUSI_DT)'; EXECUTE IMMEDIATE V_IN_IDX_DDL; END IF; DELETE WF_NODE_CONF WHERE NODE_TABNAME=VIN_IN_TABNAME AND WF_CODE='005'; COMMIT; INSERT INTO WF_NODE_CONF (WF_CODE,NODE_CODE,NODE_NAME,TYPE,LAYER,PRIORITY,NODE_TABNAME,ODS_TABNAME, SP_NAME,FREQ,BRANCH_COLUMN,DATE_COLUMN,SRC_SYS_NO,ODS_VERIFY_STATUS, REMARK,UPDATE_BRANCH,BUSINESS_CLASS) SELECT WF_CODE AS WF_CODE, ''||VIN_IN_TABNAME||'' AS NODE_CODE, ''||VIN_IN_TABNAME||'' AS NODE_NAME, TYPE AS TYPE, LAYER AS LAYER, PRIORITY AS PRIORITY, ''||VIN_IN_TABNAME||'' AS NODE_TABNAME, ''||VIN_ODS_TABNAME||'' AS ODS_TABNAME, '' AS SP_NAME, FREQ AS FREQ, ''||IN_PARAM.V_BRANCH_COLUMN||'' AS BRANCH_COLUMN, ''||IN_PARAM.V_DATA_COLUMN||'' AS DATE_COLUMN, ''||IN_PARAM.V_SRC_SYS_NO||'' AS SRC_SYS_NO, ODS_VERIFY_STATUS AS ODS_VERIFY_STATUS, REMARK AS REMARK, UPDATE_BRANCH AS UPDATE_BRANCH, BUSINESS_CLASS AS BUSINESS_CLASS FROM WF_NODE_CONF WHERE WF_CODE='005' AND LAYER='IN' AND ROWNUM=1; COMMIT; DELETE WF_NODE_RELATIONMGR WHERE NODE_CODE=VIN_IN_TABNAME AND WF_CODE='005'; COMMIT; INSERT INTO WF_NODE_RELATIONMGR(WF_CODE,NODE_CODE,PRENODE_CODE,IS_NECESSARY) VALUES('005',''||VIN_IN_TABNAME||'',''||VIN_ODS_TABNAME||'','Y'); COMMIT; --PKG_TOOLS_CONF_JCJ.PROC_DISP_LONG_STRING(V_IN_DDL); EXCEPTION WHEN OTHERS THEN IN_PARAM.OUT_ERRM_MSG:=SQLERRM; DBMS_OUTPUT.PUT_LINE(IN_PARAM.OUT_ERRM_MSG); END; PROCEDURE PROC_CONF_IF_TAB(IN_PARAM IN OUT TYPE_CREATE_IN_TAB) IS VIN_ODS_TABNAME VARCHAR2(32); VIN_IN_TABNAME VARCHAR2(32); VIN_IF_TABNAME VARCHAR2(32); BEGIN VIN_ODS_TABNAME :=UPPER(IN_PARAM.V_ODS_TABNAME); VIN_IN_TABNAME :=UPPER(IN_PARAM.V_IN_TABNAME); VIN_IF_TABNAME :=UPPER(IN_PARAM.V_IF_TABNAME); DELETE WF_NODE_CONF WHERE WF_CODE='005' AND NODE_CODE=VIN_IF_TABNAME; COMMIT; INSERT INTO WF_NODE_CONF (WF_CODE,NODE_CODE,NODE_NAME,TYPE,LAYER,PRIORITY,NODE_TABNAME,ODS_TABNAME, SP_NAME,FREQ,BRANCH_COLUMN,DATE_COLUMN,SRC_SYS_NO,ODS_VERIFY_STATUS, REMARK,UPDATE_BRANCH,BUSINESS_CLASS) SELECT WF_CODE AS WF_CODE, ''||VIN_IF_TABNAME||'' AS NODE_CODE, ''||VIN_IF_TABNAME||'' AS NODE_NAME, TYPE AS TYPE, LAYER AS LAYER, PRIORITY AS PRIORITY, ''||VIN_IF_TABNAME||'' AS NODE_TABNAME, ''||VIN_ODS_TABNAME||'' AS ODS_TABNAME, ''||IN_PARAM.V_SPNAME||'' AS SP_NAME, FREQ AS FREQ, '' AS BRANCH_COLUMN, '' AS DATE_COLUMN, '' AS SRC_SYS_NO, ODS_VERIFY_STATUS AS ODS_VERIFY_STATUS, REMARK AS REMARK, '' AS UPDATE_BRANCH, '' AS BUSINESS_CLASS FROM WF_NODE_CONF WHERE WF_CODE='005' AND LAYER='IF' AND ROWNUM=1; COMMIT; DELETE WF_NODE_RELATIONMGR WHERE WF_CODE='005' AND NODE_CODE=VIN_IF_TABNAME; COMMIT; INSERT INTO WF_NODE_RELATIONMGR(WF_CODE,NODE_CODE,PRENODE_CODE,IS_NECESSARY) VALUES('005',''||VIN_IF_TABNAME||'',''||VIN_IN_TABNAME||'','Y'); COMMIT; EXCEPTION WHEN OTHERS THEN IN_PARAM.OUT_ERRM_MSG:=SQLERRM; END; PROCEDURE PROC_CREATE_PROC_SQLTEXT(IN_PARAM IN OUT TYPE_CREATE_IN_TAB) IS V_PRE_PROC_SQLTEXT CLOB; VIN_IN_TABNAME VARCHAR2(32); VIN_IF_TABNAME VARCHAR2(32); VIN_PROC_NAME VARCHAR2(32); VIN_COMMENTS VARCHAR2(256); VIN_ALTER_DATE VARCHAR2(64); VIN_INSERT_COLS CLOB; VIN_SELECT_COLS CLOB; BEGIN VIN_IN_TABNAME :=UPPER(IN_PARAM.V_IN_TABNAME); VIN_IF_TABNAME :=UPPER(IN_PARAM.V_IF_TABNAME); VIN_PROC_NAME :=REPLACE(VIN_IF_TABNAME,'ODS','PROC'); VIN_COMMENTS :=UPPER(IN_PARAM.V_COMMENTS); VIN_ALTER_DATE :=TO_CHAR(TRUNC(SYSDATE,'DD'),'YYYY-MM-DD'); PKG_TOOLS_CONF_JCJ.PROC_COLUMN_ORDER_CHANGE(IN_PARAM.V_IN_TABNAME); PKG_TOOLS_CONF_JCJ.PROC_COLUMN_ORDER_CHANGE(IN_PARAM.V_IF_TABNAME); SELECT LISTAGG(COLUMN_NAME,','||CHR(10)||' ')WITHIN GROUP(ORDER BY COL_ORDER) AS INSERT_COLUMN, LISTAGG(SELECT_COLS,','||CHR(10)||' ')WITHIN GROUP(ORDER BY COL_ORDER) AS SELECT_COLUMN INTO VIN_INSERT_COLS, VIN_SELECT_COLS FROM (SELECT LEFT_COL.COL_ORDER,LEFT_COL.TABLE_NAME,LEFT_COL.COLUMN_NAME, CASE WHEN REGEXP_SUBSTR(LEFT_COL.DATA_TYPE,'\w{1,30}',1,1,'n')<>REGEXP_SUBSTR(RIGHT_COL.DATA_TYPE,'\w{1,30}',1,1,'n') AND REGEXP_SUBSTR(RIGHT_COL.DATA_TYPE,'\w{1,30}',1,1,'n')='DATE' THEN 'PKG_COMM_UTIL.FUNC_TO_DATE(T.'||LEFT_COL.COLUMN_NAME||',''YYYY-MM-DD'')' WHEN REGEXP_SUBSTR(LEFT_COL.DATA_TYPE,'\w{1,30}',1,1,'n')<>REGEXP_SUBSTR(RIGHT_COL.DATA_TYPE,'\w{1,30}',1,1,'n') AND REGEXP_SUBSTR(RIGHT_COL.DATA_TYPE,'\w{1,30}',1,1,'n')='NUMBER' THEN 'PKG_COMM_UTIL.FUNC_TO_NUMBER(T.'||LEFT_COL.COLUMN_NAME||')' WHEN REGEXP_SUBSTR(LEFT_COL.DATA_TYPE,'\w{1,30}',1,1,'n')='INPUT_DT' THEN 'SYSDATE' ELSE 'T.'||LEFT_COL.COLUMN_NAME END SELECT_COLS FROM COLUMN_ORDER_CHANGE LEFT_COL,COLUMN_ORDER_CHANGE RIGHT_COL WHERE LEFT_COL.COL_ORDER =RIGHT_COL.COL_ORDER AND LEFT_COL.TABLE_NAME =VIN_IN_TABNAME AND RIGHT_COL.TABLE_NAME=VIN_IF_TABNAME ORDER BY COL_ORDER); V_PRE_PROC_SQLTEXT:=' /************************************************************************************** 程序名 : '||VIN_PROC_NAME||' 用途 : '||VIN_COMMENTS||' 数据源 : '||VIN_IN_TABNAME||' 目标表 : '||VIN_IF_TABNAME||' 修改历史: 版本 更改日期 更改人 更改说明 =================================================================================== V1.0 '||VIN_ALTER_DATE||' JIANGCHANGJIAN INIT ************************************************************************************/ PROCEDURE '||VIN_PROC_NAME||'(PARAM IN OUT PROC_PARAM_TYPE) IS BEGIN DELETE '||VIN_IF_TABNAME||' WHERE BUSI_DT=PARAM.IN_BUSI_DT; COMMIT; INSERT INTO '||VIN_IF_TABNAME||' ('||VIN_INSERT_COLS||') SELECT '||VIN_SELECT_COLS||' FROM '||VIN_IN_TABNAME||' T WHERE T.BUSI_DT = PARAM.IN_BUSI_DT; COMMIT; EXCEPTION WHEN OTHERS THEN PKG_COMM_UTIL.PROC_UNI_OUTPUT_SQLERRM(PARAM,SQLERRM); END;'; DELETE PRE_PROC_SQLTEXT WHERE SP_NAME=VIN_PROC_NAME; COMMIT; INSERT INTO PRE_PROC_SQLTEXT(SQLTEXT,SP_NAME,IF_TABNAME,DATETIME) VALUES(V_PRE_PROC_SQLTEXT,VIN_PROC_NAME,VIN_IF_TABNAME,SYSDATE); COMMIT; EXCEPTION WHEN OTHERS THEN IN_PARAM.OUT_ERRM_MSG:=SQLERRM; END; PROCEDURE PROC_EXEC_IF_SP(IN_PARAM IN OUT TYPE_CREATE_IN_TAB) IS SP_PARAM PROC_PARAM_TYPE; V_SPNAME VARCHAR2(128); BEGIN SELECT SP_NAME INTO V_SPNAME FROM WF_NODE_CONF WHERE WF_CODE='005' AND NODE_CODE=UPPER(IN_PARAM.V_IF_TABNAME); SP_PARAM:=IN_PARAM.V_PARAM; EXECUTE IMMEDIATE 'BEGIN '||V_SPNAME||'(:A); END;' USING IN OUT SP_PARAM; END; PROCEDURE PROC_BATCH_CREATE_HISTAB IS V_NEW_TABNAME VARCHAR2(32); V_DATA_COUNT NUMBER; V_DDATE_COUNT NUMBER; V_TAB_COUNT NUMBER; V_IND_COUNT NUMBER; V_OUT_TAB VARCHAR2(256); BEGIN FOR I IN(SELECT NODE_TABNAME FROM WF_NODE_CONF WHERE WF_CODE='005' AND LAYER='IN') LOOP SELECT COUNT(*) INTO V_TAB_COUNT FROM USER_TABLES WHERE TABLE_NAME=REPLACE(I.NODE_TABNAME,'ODS','HIS'); SELECT COUNT(*) INTO V_IND_COUNT FROM USER_INDEXES WHERE INDEX_NAME='HIS_'||SUBSTR(I.NODE_TABNAME,0,25); IF V_TAB_COUNT=0 THEN V_NEW_TABNAME:=REPLACE(I.NODE_TABNAME,'ODS','HIS'); EXECUTE IMMEDIATE 'CREATE TABLE '||V_NEW_TABNAME ||' AS SELECT * FROM '||I.NODE_TABNAME||' WHERE 1=2'; SELECT COUNT(*) INTO V_DATA_COUNT FROM USER_TAB_COLUMNS WHERE TABLE_NAME=V_NEW_TABNAME AND COLUMN_NAME='DATA_DATE'; SELECT COUNT(*) INTO V_DDATE_COUNT FROM USER_TAB_COLUMNS WHERE TABLE_NAME=V_NEW_TABNAME AND COLUMN_NAME='DATA_DATE'; IF V_DATA_COUNT=1 AND V_IND_COUNT=0 THEN EXECUTE IMMEDIATE 'CREATE INDEX HIS_'||SUBSTR(I.NODE_TABNAME,0,25)||' ON '||V_NEW_TABNAME||'(DATA_DATE)'; ELSIF V_DATA_COUNT=0 AND V_DDATE_COUNT=1 AND V_IND_COUNT=0 THEN EXECUTE IMMEDIATE 'CREATE INDEX HIS_'||SUBSTR(I.NODE_TABNAME,0,25)||' ON '||V_NEW_TABNAME||'(DDATE)'; END IF; V_OUT_TAB:=V_OUT_TAB||';'||I.NODE_TABNAME; END IF; END LOOP; --DBMS_OUTPUT.PUT_LINE(V_OUT_TAB); END; PROCEDURE PROC_EAST_PKG_TAB_AUTO_CREATE(V_LDM_TAB VARCHAR2,V_SD_TABNAME VARCHAR2) IS V_COL_DDL CLOB; V_COMM_DDL CLOB; V_TAB_DDL CLOB; V_EAST_PROC CLOB; VIN_INSERT_COLS CLOB; VIN_SELECT_COLS CLOB; V_PRE_COLS VARCHAR2(256); V_IDX_DDL VARCHAR2(512); V_EAST_TAB VARCHAR2(32); V_EAST_TAB_COUNT NUMBER; V_99_IDX_COUNT NUMBER; VIN_LDM_TAB VARCHAR2(32); VIN_SD_TABNAME VARCHAR2(32); VIN_PROC_NAME VARCHAR2(32); VIN_ALTER_DATE VARCHAR2(64); BEGIN VIN_ALTER_DATE :=TO_CHAR(SYSDATE,'YYYY-MM-DD'); VIN_LDM_TAB :=UPPER(V_LDM_TAB); VIN_SD_TABNAME :=UPPER(V_SD_TABNAME); V_EAST_TAB :='DM_EAST_'||RTRIM(SUBSTR(VIN_LDM_TAB,1,22),'_'); FOR I IN (SELECT COL_SEQ,IN_COL,IN_COL_DATA_TY,COMMENTS, CASE WHEN REGEXP_LIKE(SE_COL,'(^PKG|SYSDATE|''|NULL)') THEN NULL ELSE 'T.' END||SE_COL AS SE_COL FROM DEF_EA_IN_SE_CONF WHERE COL_SEQ NOT IN(0.8,0.9) UNION ALL SELECT COL_SEQ,IN_COL,IN_COL_DATA_TY,COMMENTS, CASE WHEN REGEXP_LIKE(SE_COL,'(^PKG|SYSDATE|''|NULL)') THEN NULL ELSE 'T.' END||SE_COL AS SE_COL FROM EA_IN_SE_CONF WHERE LDM_TAB=VIN_LDM_TAB ORDER BY COL_SEQ) LOOP V_COL_DDL :=V_COL_DDL||I.IN_COL||' '||I.IN_COL_DATA_TY||','; V_COMM_DDL :=V_COMM_DDL||'COMMENT ON COLUMN '||V_EAST_TAB||'.' ||I.IN_COL||' IS '''||I.COMMENTS||''''||';'; VIN_INSERT_COLS:=VIN_INSERT_COLS||I.IN_COL||','||CHR(10)||' '; V_PRE_COLS :=I.SE_COL||' AS '||I.IN_COL||','; IF LENGTH(V_PRE_COLS)<50 THEN VIN_SELECT_COLS:=VIN_SELECT_COLS||RPAD(V_PRE_COLS,50,' ')||'--' ||I.COMMENTS||CHR(10)||' '; ELSE VIN_SELECT_COLS:=VIN_SELECT_COLS||V_PRE_COLS||'--' ||I.COMMENTS||CHR(10)||' '; END IF; END LOOP; V_COL_DDL :=RTRIM(V_COL_DDL,','); V_COMM_DDL :=RTRIM(V_COMM_DDL,','); VIN_INSERT_COLS :=RTRIM(VIN_INSERT_COLS,','||CHR(10)||' '); VIN_SELECT_COLS :=RTRIM(TRIM(RTRIM(VIN_SELECT_COLS,'--'||CHR(10)||' ')),','); SELECT COUNT(*) INTO V_EAST_TAB_COUNT FROM USER_OBJECTS WHERE OBJECT_NAME='IDX_'||SUBSTR(V_EAST_TAB,1,23)||'_99' AND OBJECT_TYPE='INDEX'; IF V_EAST_TAB_COUNT=0 THEN V_TAB_DDL:='CREATE TABLE '||V_EAST_TAB||'('||V_COL_DDL||')TABLESPACE MDR'; EXECUTE IMMEDIATE V_TAB_DDL; END IF; FOR I IN( SELECT REGEXP_SUBSTR(TO_CHAR(V_COMM_DDL),'[^;]+',1,ROWNUM) AS COMMENTS FROM DUAL CONNECT BY ROWNUM<=REGEXP_COUNT(V_COMM_DDL,';')) LOOP EXECUTE IMMEDIATE I.COMMENTS; END LOOP; --记录 INSERT INTO DATA_CONTROL_JCJTEST_LOG(SQL_TEXT,EXEC_DATE) VALUES(V_COL_DDL,SYSDATE); COMMIT; SELECT COUNT(*) INTO V_99_IDX_COUNT FROM USER_OBJECTS WHERE OBJECT_NAME='IDX_'||SUBSTR(V_EAST_TAB,1,23)||'_99' AND OBJECT_TYPE='INDEX'; IF V_99_IDX_COUNT=0 THEN V_IDX_DDL:='CREATE INDEX IDX_'||SUBSTR(V_EAST_TAB,1,23)||'_99 ON '||V_EAST_TAB||'(BUSI_DT)'; EXECUTE IMMEDIATE V_IDX_DDL; END IF; VIN_PROC_NAME:='PROC_EAST_'||RTRIM(SUBSTR(VIN_LDM_TAB,1,21),'_'); V_EAST_PROC:=' /************************************************************************************** 程序名 : '||VIN_PROC_NAME||' 用途 : 数据源 : '||VIN_SD_TABNAME||' 目标表 : '||V_EAST_TAB||' 修改历史: 版本 更改日期 更改人 更改说明 =================================================================================== V1.0 '||VIN_ALTER_DATE||' JIANGCHANGJIAN INIT ************************************************************************************/ PROCEDURE '||VIN_PROC_NAME||'(PARAM IN OUT PROC_PARAM_TYPE) IS BEGIN DELETE '||V_EAST_TAB||' WHERE BUSI_DT=PARAM.IN_BUSI_DT; COMMIT; INSERT INTO '||V_EAST_TAB||' ('||VIN_INSERT_COLS||') SELECT '||VIN_SELECT_COLS||' FROM '||VIN_SD_TABNAME||' T WHERE T.BUSI_DT = PARAM.IN_BUSI_DT; COMMIT; EXCEPTION WHEN OTHERS THEN PKG_COMM_UTIL.PROC_UNI_OUTPUT_SQLERRM(PARAM,SQLERRM); END;'; --插入脚本 DELETE PRE_PROC_SQLTEXT WHERE SP_NAME=VIN_PROC_NAME; COMMIT; INSERT INTO PRE_PROC_SQLTEXT(SQLTEXT,SP_NAME,IF_TABNAME,DATETIME) VALUES(V_EAST_PROC,VIN_PROC_NAME,V_EAST_TAB,SYSDATE); COMMIT; END; FUNCTION FUNC_GET_FTZ_FLG(IN_BRANCH VARCHAR2) RETURN VARCHAR2 IS OUT_FTZ_FLG VARCHAR2(1); BEGIN SELECT CASE WHEN IN_BRANCH='C33' THEN 'Y' ELSE 'N' END FTZ_FLG INTO OUT_FTZ_FLG FROM DUAL; RETURN OUT_FTZ_FLG; END; PROCEDURE PROC_GET_MAPPING_DQL(IN_LDM_TAB VARCHAR2,IN_EAST_TAB VARCHAR2,IN_BUSI_DT DATE) IS V_IN_LDM_TAB VARCHAR2(32):=UPPER(IN_LDM_TAB); V_IN_EAST_TAB VARCHAR2(32):=UPPER(IN_EAST_TAB); V_PK_COL_JOIN VARCHAR2(1024); V_IN_EAST_DATE VARCHAR2(64):=TO_CHAR(IN_BUSI_DT,'YYYY-MM-DD'); V_IN_LDM_DATE VARCHAR2(64):=TO_CHAR(IN_BUSI_DT,'YYYYMMDD'); V_NULL_TYPE VARCHAR2(64); V_MAP_COLS CLOB; --V_SELECT_COLS CLOB; V_PREDICATE CLOB; V_MAP_DQL CLOB; V_LDM_OVER CLOB; V_EAST_OVER CLOB; BEGIN /*SELECT A.COLUMN_NAME,A.DATA_TYPE FROM USER_TAB_COLUMNS A,USER_TAB_COLUMNS B WHERE A.COLUMN_NAME=B.COLUMN_NAME AND A.TABLE_NAME=V_IN_LDM_TAB AND B.TABLE_NAME=V_IN_EAST_TAB*/--这是共同字段,按理应该包含所有字段 FOR I IN(SELECT A.COLUMN_NAME,DATA_TYPE FROM USER_TAB_COLUMNS A WHERE A.TABLE_NAME=V_IN_LDM_TAB) LOOP SELECT DECODE(I.DATA_TYPE,'DATE','DATE''9999-12-31''',0) INTO V_NULL_TYPE FROM DUAL; V_MAP_COLS :=V_MAP_COLS||'CASE WHEN NVL(DM_EAST.'||I.COLUMN_NAME||',' ||V_NULL_TYPE||')=NVL(LDM.'||I.COLUMN_NAME||',' ||V_NULL_TYPE||') THEN ''Y'' ELSE DM_EAST.' ||I.COLUMN_NAME||'||'';''||LDM.' ||I.COLUMN_NAME||' END '||I.COLUMN_NAME||','||CHR(10)||' '; --V_SELECT_COLS:=V_SELECT_COLS||I.COLUMN_NAME||','||CHR(10); V_PREDICATE :=V_PREDICATE||I.COLUMN_NAME||'<>''Y'' OR '||CHR(10)||' '; END LOOP; V_MAP_COLS :=RTRIM(V_MAP_COLS,','||CHR(10)||' '); --V_SELECT_COLS :=RTRIM(V_SELECT_COLS,',')||CHR(10); V_PREDICATE :=RTRIM(V_PREDICATE,' OR '||CHR(10)||' '); SELECT LISTAGG('DM_EAST.'||REGEXP_SUBSTR(V_COLUMNS,'[^,]+',1,ROWNUM)|| ' = LDM.' ||REGEXP_SUBSTR(V_COLUMNS,'[^,]+',1,ROWNUM), CHR(10)||' AND ') WITHIN GROUP(ORDER BY V_COLUMNS) AS PK_COL_LIST INTO V_PK_COL_JOIN FROM ( SELECT CONS.CONSTRAINT_NAME,CONS.TABLE_NAME,REPLACE(IND_VIEW.V_COLUMNS,'DATA_DATE,','') AS V_COLUMNS FROM USER_CONSTRAINTS CONS,VIEW_USER_IND_COLUMNS IND_VIEW WHERE CONS.CONSTRAINT_NAME=IND_VIEW.INDEX_NAME AND CONS.TABLE_NAME=IND_VIEW.TABLE_NAME AND CONS.TABLE_NAME=V_IN_LDM_TAB AND CONS.CONSTRAINT_TYPE='P' ) CONNECT BY LEVEL<=REGEXP_COUNT(V_COLUMNS,',')+1; V_MAP_DQL:='SELECT * FROM ( SELECT '||V_MAP_COLS||' FROM '||V_IN_EAST_TAB||' DM_EAST,'||V_IN_LDM_TAB||' LDM WHERE '||V_PK_COL_JOIN||' AND LDM.DATA_DATE='||V_IN_LDM_DATE||' AND DM_EAST.BUSI_DT=DATE'''||V_IN_EAST_DATE||''' ) WHERE ('||V_PREDICATE||')'; V_LDM_OVER:='SELECT * FROM '||V_IN_LDM_TAB||' LDM WHERE NOT EXISTS (SELECT 1 FROM '||V_IN_EAST_TAB||' DM_EAST WHERE '||V_PK_COL_JOIN||' AND DM_EAST.BUSI_DT=DATE'''||V_IN_EAST_DATE||''') AND LDM.DATA_DATE='||V_IN_LDM_DATE||';'; V_EAST_OVER:='SELECT * FROM '||V_IN_EAST_TAB||' DM_EAST WHERE NOT EXISTS (SELECT 1 FROM '||V_IN_LDM_TAB||' LDM WHERE '||V_PK_COL_JOIN||' AND LDM.DATA_DATE='||V_IN_LDM_DATE||') AND DM_EAST.BUSI_DT=DATE'''||V_IN_EAST_DATE||''''; DELETE CITI_GET_MAPPING_DQL WHERE EAST_TABNAME=V_IN_EAST_TAB; COMMIT; INSERT INTO CITI_GET_MAPPING_DQL(MAPPING_DQL,LDM_MORE_DQL,EAST_MORE_DQL,EAST_TABNAME,LDM_TABNAME,INPUT_DT) VALUES (V_MAP_DQL,V_LDM_OVER,V_EAST_OVER,V_IN_EAST_TAB,V_IN_LDM_TAB,SYSDATE); COMMIT; END; /*FUNCTION FUNC_ROW_TURN_COLUMN(V_TABNAME VARCHAR2) RETURN TYPE_ROWS IS V_ONE_ARR TYPE_COLUMNS; V_DIM_ARR TYPE_ROWS:=TYPE_ROWS(V_ONE_ARR); BEGIN V_ONE_ARR:=TYPE_COLUMNS('111','222'); V_DIM_ARR.EXTEND; V_DIM_ARR(1):=V_ONE_ARR; V_ONE_ARR:=TYPE_COLUMNS('333','444'); V_DIM_ARR(2):=V_ONE_ARR; RETURN V_DIM_ARR; END;*/ /*FUNCTION GET_TERM_YEARS RETURN DATE_TABLE PIPELINED IS L_RESULT DATE_RECORD; BEGIN FOR REC IN (SELECT 'QWER' AS YEAR FROM DUAL UNION ALL SELECT 'ASDF' AS YEAR FROM DUAL UNION ALL SELECT 'ZXCV' AS YEAR FROM DUAL) LOOP L_RESULT.NAME := REC.YEAR || '年'; L_RESULT.VALUE := REC.YEAR; PIPE ROW (L_RESULT); --依次返回行 END LOOP; END;*/ /*PROCEDURE PROC_REDEFINITION_PLUS(ORG_TABNAME VARCHAR2,NEW_TABNAME VARCHAR2) IS num_errors PLS_INTEGER; V_USERNAME VARCHAR2(32):='UUPSDB2'; V_ORG_TABNAME VARCHAR2(32):=UPPER(ORG_TABNAME); V_NEW_TABNAME VARCHAR2(32):=UPPER(NEW_TABNAME); V_OPTIONS_FLAG VARCHAR2(256):='dbms_redefinition.cons_use_pk'; BEGIN SYS.DBMS_REDEFINITION.can_redef_table ( uname =>V_USERNAME, tname =>V_ORG_TABNAME, options_flag =>V_OPTIONS_FLAG, part_name =>'' ); DBMS_REDEFINITION.START_REDEF_TABLE ( uname =>V_USERNAME, orig_table =>V_ORG_TABNAME, int_table =>V_NEW_TABNAME, col_mapping =>'', options_flag =>V_OPTIONS_FLAG --orderby_cols =>'', --part_name =>'' ); DBMS_REDEFINITION.REGISTER_DEPENDENT_OBJECT ( uname =>V_USERNAME, orig_table =>V_ORG_TABNAME, int_table =>V_NEW_TABNAME, dep_type =>'', dep_owner =>V_USERNAME, dep_orig_name =>'', dep_int_name =>'' ); DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS ( uname =>V_USERNAME, orig_table =>V_ORG_TABNAME, int_table =>V_NEW_TABNAME, copy_indexes =>0, copy_triggers => TRUE, copy_constraints => TRUE, copy_privileges => TRUE, ignore_errors => FALSE, num_errors =>num_errors --copy_statistics => FALSE, --copy_mvlog => FALSE ); DBMS_REDEFINITION.SYNC_INTERIM_TABLE ( uname =>V_USERNAME, orig_table =>V_ORG_TABNAME, int_table =>V_NEW_TABNAME --part_name =>'' ); DBMS_REDEFINITION.FINISH_REDEF_TABLE ( uname =>V_USERNAME, orig_table =>V_ORG_TABNAME, int_table =>V_NEW_TABNAME --part_name =>'' ); EXCEPTION WHEN OTHERS THEN DBMS_REDEFINITION.ABORT_REDEF_TABLE( uname =>V_USERNAME, orig_table =>V_ORG_TABNAME, int_table =>V_NEW_TABNAME --part_name =>'' ); END; */ END;
All for u