채신일보 취수 논리

6238 단어
먼저 스토리지 프로세스 CAMP 호출IMPORT_TOT_DATA
스토리지 프로세스 보기
show  procedure  CAMP_IMPORT_TOT_DATA

결과 보기
show  procedure  CAMP_IMPORT_TOT_DATA

--drop PROCEDURE CAMP_IMPORT_TOT_DATA

--SHOW  PROCEDURE	IPAD_BASE_DATA_IMPORT_TOT_DATA

REPLACE PROCEDURE 
	 CAMP_IMPORT_TOT_DATA
	 (IN DEAL_DATE CHAR(8), IN DAYS INTEGER,OUT RTN INTEGER)
	 BEGIN
	   DECLARE P_DAY_COUNT INTEGER DEFAULT 0;
	   DECLARE P_DATE_TEMP DATE;
	   DECLARE DEAL_DATEF DATE;
	   DECLARE CURDATE_DATA_COUNT INTEGER DEFAULT 0;
	   DECLARE INDI_TIME VARCHAR(50);
	  DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
	  BEGIN
	  /**/
	   INSERT INTO IPAD_DATA_ERR_LOG 
	    SELECT ERRORCODE,ERRORTEXT,P_DATE_TEMP,CAST(CURRENT_TIMESTAMP AS VARCHAR(19)) FROM DBC.ERRORMSGS WHERE ERRORCODE = SQLCODE;
	    
	  END;
	
	  UPDATE CAMP_DATA_IS_UPDATE_VW SET IS_UPDATE = '1',OPT_DT = CAST(CURRENT_TIMESTAMP AS VARCHAR(19)) WHERE ID = 1;
	  
	
	  SELECT TRIM(SUBSTRING(DEAL_DATE  FROM 1 FOR 4) || '-' || SUBSTRING(DEAL_DATE  FROM 5 FOR 2) || '-' || SUBSTRING(DEAL_DATE  FROM 7 FOR 2)) INTO :DEAL_DATEF;
	 
	 SET P_DAY_COUNT = DAYS;
	   SET P_DATE_TEMP = DEAL_DATEF - P_DAY_COUNT; 
	   
	   SELECT CAST(CURRENT_TIMESTAMP AS VARCHAR(19)) INTO :INDI_TIME;
	   
 data_loop_label: LOOP
	
	
	  IF P_DAY_COUNT = -1 THEN
	    LEAVE data_loop_label;
	   END IF;
	   
	  DELETE FROM CAMP_C_ALL_MTER_NEW_VW WHERE DEAL_DATE = P_DATE_TEMP;
	   
	   SELECT COUNT(*) INTO :CURDATE_DATA_COUNT FROM CAMP_C_ALL_MTER_NEW_VW WHERE DEAL_DATE = P_DATE_TEMP AND REGION_CODE = '00';
	   
	   INSERT INTO CAMP_C_MART3_DATA_LOG_VW VALUES(P_DATE_TEMP,'      :' || TRIM(CURDATE_DATA_COUNT) || ' ',INDI_TIME);
	   
	   IF CURDATE_DATA_COUNT < 650 THEN
	    
	    INSERT INTO CAMP_C_ALL_MTER_NEW_VW
	     SELECT DISTINCT * FROM RPTMARTVW3.TB_SMS_VAT_TOT_MTER_DAY A
	      WHERE DEAL_DATE = CAST(P_DATE_TEMP AS DATE)
	      AND CITY_CODE = '00'
	      AND REGION_CODE IS NOT NULL
	      AND ITEM_CODE IS NOT NULL
	      AND DEAL_DATE IS NOT NULL
	      AND ABS(ITEM_VALUE) IN (
	      
	      SELECT MAX(ABS(ITEM_VALUE)) FROM RPTMARTVW3.TB_SMS_VAT_TOT_MTER_DAY
	      WHERE DEAL_DATE = CAST(P_DATE_TEMP AS DATE)
	      AND CITY_CODE = '00'
	      AND REGION_CODE IS NOT NULL
	      AND ITEM_CODE IS NOT NULL
	      AND DEAL_DATE IS NOT NULL
	      AND A.REGION_CODE = REGION_CODE
	      AND A.ITEM_CODE = ITEM_CODE
	      GROUP BY REGION_CODE,CITY_CODE,ITEM_CODE
	      
	      );
	   
	     
	  
	      
	      
	CALL CAMP_DATA_NEATEN_FOR_TRENDS(P_DATE_TEMP,0);
	 /**
	  CALL CAMP_CT_BASE_DATA_IMPORT(DEAL_DATE,0);
	  */
	  SELECT COUNT(*) INTO :CURDATE_DATA_COUNT FROM CAMP_C_ALL_MTER_NEW_VW WHERE DEAL_DATE = P_DATE_TEMP AND REGION_CODE = '00';
	      
	  IF CURDATE_DATA_COUNT = 0 THEN
	   UPDATE CAMP_C_MART3_DATA_LOG_VW SET DATA_INFO = (DATA_INFO || ',     !')
	   WHERE DATA_DATE = P_DATE_TEMP 
	   AND OPT_DT = INDI_TIME;
	   select 0 into RTN;
	  ELSE
	   UPDATE CAMP_C_MART3_DATA_LOG_VW SET DATA_INFO = (DATA_INFO || ',       !')
	   WHERE DATA_DATE = P_DATE_TEMP 
	   AND OPT_DT = INDI_TIME;
	   select 1 into RTN;
	   
	update  k_report_status set REPORT_STATUS='0',report_flag='0'  ,REPORT_DATE=P_DATE_TEMP,DEAL_DATE=date where REPORT_TYPE='zengzhi';

insert into k_report_status_his (REPORT_TYPE, REPORT_STATUS, report_flag,REPORT_DATE, REMARK, DEAL_DATE)
values ('zengzhi','0','0',P_DATE_TEMP,  '  ',date );
	   

	  END IF;
	   END IF;
	   
	
	   SET P_DAY_COUNT = P_DAY_COUNT - 1;
	   SET P_DATE_TEMP = DEAL_DATEF - P_DAY_COUNT;
	
	  END LOOP data_loop_label;
	  
	  UPDATE CAMP_DATA_IS_UPDATE_VW SET IS_UPDATE = '0',OPT_DT = CAST(CURRENT_TIMESTAMP AS VARCHAR(19)) WHERE ID = 1;
	  
	 END;

관련 표
     show table      WAPBI.IPAD_DATA_ERR_LOG

CREATE SET TABLE WAPBI.IPAD_DATA_ERR_LOG ,NO FALLBACK ,
     NO BEFORE JOURNAL,
     NO AFTER JOURNAL,
     CHECKSUM = DEFAULT
     (
      SQL_CODE INTEGER,
      SQL_MSG VARCHAR(1000) CHARACTER SET LATIN NOT CASESPECIFIC,
      ERR_DATA_DATE INTEGER,
      ERR_DT TIMESTAMP(6))
PRIMARY INDEX ( SQL_CODE );
show table      WAPBI.IPAD_DATA_ERR_LOG

CREATE SET TABLE WAPBI.IPAD_DATA_ERR_LOG ,NO FALLBACK ,
     NO BEFORE JOURNAL,
     NO AFTER JOURNAL,
     CHECKSUM = DEFAULT
     (
      SQL_CODE INTEGER,
      SQL_MSG VARCHAR(1000) CHARACTER SET LATIN NOT CASESPECIFIC,
      ERR_DATA_DATE INTEGER,
      ERR_DT TIMESTAMP(6))
PRIMARY INDEX ( SQL_CODE );
show table   WAPBI.CAMP_DATA_IS_UPDATE

CREATE MULTISET TABLE WAPBI.CAMP_DATA_IS_UPDATE ,NO FALLBACK ,
     NO BEFORE JOURNAL,
     NO AFTER JOURNAL,
     CHECKSUM = DEFAULT
     (
      ID INTEGER NOT NULL,
      IS_UPDATE CHAR(1) CHARACTER SET LATIN CASESPECIFIC TITLE '      ' NOT NULL,
      OPT_DT TIMESTAMP(6) TITLE '    ' NOT NULL)
PRIMARY INDEX ( ID );
show table camp_c_all_mter_new

CREATE MULTISET TABLE WAPBI.camp_c_all_mter_new ,NO FALLBACK ,
     NO BEFORE JOURNAL,
     NO AFTER JOURNAL,
     CHECKSUM = DEFAULT
     (
      DEAL_DATE DATE FORMAT 'YYYY-MM-DD' TITLE '    ' NOT NULL,
      REGION_CODE CHAR(2) CHARACTER SET LATIN CASESPECIFIC TITLE '    ' NOT NULL,
      CITY_CODE CHAR(2) CHARACTER SET LATIN CASESPECIFIC TITLE '    ',
      BRAND_CODE CHAR(2) CHARACTER SET LATIN CASESPECIFIC TITLE '      ',
      ITEM_CODE CHAR(10) CHARACTER SET LATIN CASESPECIFIC TITLE '    ' NOT NULL,
      ITEM_NAME CHAR(40) CHARACTER SET LATIN CASESPECIFIC TITLE '    ',
      ITEM_VALUE DECIMAL(18,2) TITLE '   (   )',
      ITEM_VALUE_T DECIMAL(18,2) TITLE '   (  )',
      NOTE VARCHAR(200) CHARACTER SET LATIN CASESPECIFIC TITLE '  ',
      BAK_FIELD1 DECIMAL(14,2) TITLE '    1',
      BAK_FIELD2 CHAR(20) CHARACTER SET LATIN CASESPECIFIC TITLE '    2')
PRIMARY INDEX ( DEAL_DATE ,REGION_CODE ,CITY_CODE )
PARTITION BY RANGE_N(DEAL_DATE  BETWEEN DATE '2005-01-01' AND DATE '2050-12-31' EACH INTERVAL '1' DAY )
INDEX MTER_IDX ( DEAL_DATE );

좋은 웹페이지 즐겨찾기