0

我已经看到了一些类似的问题,但没有太多帮助。我已经有两个过程,我需要合并它,并将内部表 TT_SERIES 替换为名为 DB_WEEK_SERIES 的数据库表。我试图合并但有错误。以下是我的2个程序:-

第一个程序:

 PROCEDURE 
 "AFS_BASE"."AFS_BASE.KPI.DASHBOARD::PR_REV_CTRL_BOX_ORDER_BY_STAGE" 
 (  
    IN TT_INPUT "OPS_SCHEMA"."AM.OPS.CORE.TABLETYPES::GTT_INPUT", 
   OUT TT_DASHBOARD "OPS_SCHEMA"."AM.OPS.CORE.TABLETYPES::GTT_GENERIC_DASHBOARD"
)
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER 
DEFAULT SCHEMA AFS_BASE
AS

LV_TAB          NVARCHAR(50) ;
lv_measure      nvarchar(50) ;
lv_report_date  date ;
LV_UID          NVARCHAR(255);
LV_SUB_HEADING  NVARCHAR(255);
LV_START_DATE   DATE := ADD_DAYS (LAST_DAY (ADD_MONTHS(CURRENT_DATE, -4)), 
1);
LV_END_DATE     DATE := LAST_DAY (CURRENT_DATE);
LV_WEEKEND      NVARCHAR(10) := 'FRIDAY';

/**********************************
Created by Junaid on 13th May 2017
**********************************/

BEGIN

SELECT VALUE INTO LV_UID FROM :TT_INPUT WHERE VARIABLE = 'UID';
SELECT VALUE INTO LV_TAB FROM :TT_INPUT WHERE VARIABLE = 'TAB';
SELECT IFNULL(NULLIF(VALUE,''),:LV_START_DATE) INTO LV_START_DATE FROM 
:TT_INPUT where VARIABLE = 'START_DATE';  
SELECT IFNULL(NULLIF(VALUE,''),:LV_END_DATE) INTO LV_END_DATE FROM :TT_INPUT 
where VARIABLE = 'END_DATE';

BEGIN

    DECLARE EXIT HANDLER FOR SQL_ERROR_CODE 1299

    LV_SUB_HEADING := '';
    SELECT VALUE INTO LV_SUB_HEADING FROM :TT_INPUT WHERE VARIABLE = 
    'SUB_HEADING';

    END;


    TT_HDR = SELECT DISTINCT SERIAL_NUMBER 
        FROM "AFS_BASE"."AFS_BASE.TRENDS.TABLES::OPV_KPI_MEASURES"
        WHERE MEASURE_DATE BETWEEN :LV_START_DATE AND :LV_END_DATE;

   TT_ZOOM =    SELECT 'ATTRIBUTE' AS ZOOM_TYPE,
                    Z.ATTRIBUTE AS ZOOM_ATTRIBUTE,
                    Z.ATTRIBUTE_VALUE AS ZOOM_ATTRIBUTE_VALUE
              FROM "BASE_SCHEMA"."AM.BASE.TABLES::DB_TAB_ZOOM_VALUES" Z
             WHERE Z.TAB_NAME = :LV_TAB 
               AND Z.SCENARIO_NUMBER = SESSION_CONTEXT('$vssod_scenario')
               AND Z.SESSION_ID = SESSION_CONTEXT('$vssod_sid') 
               AND Z.USER_NAME = SESSION_USER
               AND Z.ATTRIBUTE IN (SELECT ATTRIBUTE FROM 
               "BASE_SCHEMA"."AM.BASE.TABLES::DB_CONFIG_ATTRIBUE"
                                   WHERE CLIENT = SESSION_CONTEXT('CLIENT') 
             AND DISPLAY = 'Y')
             UNION ALL
            SELECT 'TAG' AS ZOOM_TYPE,
                   Z.ATTRIBUTE AS ZOOM_ATTRIBUTE,
                   Z.ATTRIBUTE_VALUE AS ZOOM_ATTRIBUTE_VALUE
              FROM "BASE_SCHEMA"."AM.BASE.TABLES::DB_TAB_ZOOM_VALUES" Z
             WHERE TAB_NAME = :LV_TAB 
               AND Z.SCENARIO_NUMBER= SESSION_CONTEXT('$vssod_scenario')
               AND Z.SESSION_ID = SESSION_CONTEXT('$vssod_sid') 
               AND Z.USER_NAME = SESSION_USER
               AND Z.ATTRIBUTE IN (SELECT TAG_NAME FROM 
             "BASE_SCHEMA"."AM.BASE.TABLES::DB_CONFIG_TAGS"
                                   WHERE CLIENT = SESSION_CONTEXT('CLIENT') 
             AND DISPLAY = 'Y'); 

             CALL "AFS_BASE"."AFS_BASE.TRENDS.CORE/PR_KPI_FILTER_WITH_ZOOM"
             (:TT_INPUT, :TT_ZOOM, :TT_HDR, TT_FSN);

            TT_SERIES = SELECT GENERATED_PERIOD_START AS REPORT_DATE,
                     week(add_days(generated_period_start , 2)) as 
            report_week, current_date as week_end --added ABHOOT
               FROM SERIES_GENERATE_DATE ( 'INTERVAL 1 DAY', :LV_START_DATE, 

           ADD_DAYS(coalesce(current_date,:LV_END_DATE), 1));

           TT_WEEK_END = select report_week, max(report_date) as week_end
                  from :TT_SERIES
                  group by report_week ;


           TT_SERIES = select S.report_date, w.report_week, w.week_end
               from :TT_WEEK_END W
               inner join :TT_SERIES S
               on w.report_week = s.report_week ;

          select SUBSTR_AFTER(:lv_uid, ':') into lv_measure from dummy ;
          select SUBSTR_BEFORE (:lv_uid, ':') into lv_report_date from dummy 
          ;

         IF :LV_UID = 'ALL' THEN
         TT_INVOICED = SELECT 0 as serial_number , week_end as REPORT_DATE, 
         SUM(MEASURE_AMOUNT) AS INV_AMT
                    FROM 
         "AFS_BASE"."AFS_BASE.TRENDS.TABLES::OPV_KPI_MEASURES" K
                    INNER JOIN :TT_SERIES TS
                    ON TS.REPORT_DATE = K.MEASURE_DATE
                    where MEASURE = 'Invoiced'
                    and k.serial_number in (select distinct serial_number 
         from :TT_FSN )
                    GROUP BY week_end;

    TT_INVOICE = SELECT REPORT_DATE, 'Invoiced' AS MEASURE, SUM(INV_AMT) AS 
    AMT
                    FROM :TT_INVOICED I
                    GROUP BY report_date ;

    TT_REMAINING = SELECT 0 as SERIAL_NUMBER, ts.week_end as REPORT_DATE, 
    MEASURE, SUM(MEASURE_AMOUNT) AS AMT
                    FROM 
   "AFS_BASE"."AFS_BASE.TRENDS.TABLES::OPV_KPI_MEASURES" K
                    INNER JOIN :TT_week_end TS
                    ON TS.WEEK_END BETWEEN K.VALID_FROM_DATE AND 
    K.VALID_TO_DATE
                    where k.MEASURE IN ('In Pick', 'In Production', 'In 
    Transit', 'Late', 'Not Covered', 'On Hand', 'Open Direct Ship')
                    and k.serial_number in (select distinct serial_number 
    from :TT_FSN )
                    GROUP BY TS.week_end, MEASURE ;


    TT_DATA = SELECT REPORT_DATE, MEASURE, SUM(AMT) AS TOT_AMT, 1 AS SORT 
    FROM :TT_INVOICE
                GROUP BY REPORT_DATE, MEASURE
                UNION ALL
                SELECT REPORT_DATE, MEASURE, SUM(AMT) AS TOT_AMT, 2 AS SORT 
    FROM :TT_REMAINING
                GROUP BY REPORT_DATE, MEASURE;

  ELSEIF  :lv_measure =  'Invoiced' THEN        
    TT_DRILLDOWN = SELECT K.serial_number, week_end as REPORT_DATE, k.measure, SUM(MEASURE_AMOUNT) AS AMT
                    FROM "AFS_BASE"."AFS_BASE.TRENDS.TABLES::OPV_KPI_MEASURES" K
                    INNER JOIN :TT_SERIES TS
                    ON TS.REPORT_DATE = K.MEASURE_DATE
                    and ts.week_end = :lv_report_date
                    where MEASURE = 'Invoiced'
                    and k.serial_number in (select distinct serial_number from :TT_FSN )
                    GROUP BY week_end, k.measure, K.serial_number ;
  ELSEIF  :lv_measure <> 'Invoiced' THEN  
    TT_DRILLDOWN = SELECT k.SERIAL_NUMBER, :lv_report_date as  REPORT_DATE, MEASURE, SUM(MEASURE_AMOUNT) AS AMT
                    FROM "AFS_BASE"."AFS_BASE.TRENDS.TABLES::OPV_KPI_MEASURES" K
                    where k.MEASURE = :lv_measure
                    and :lv_report_date BETWEEN K.VALID_FROM_DATE AND K.VALID_TO_DATE
                    and k.serial_number in (select distinct serial_number from :TT_FSN )
                    GROUP BY MEASURE, K.serial_number ;
  END IF ;


    /* TT_WEEKLY = SELECT REPORT_DATE, COALESCE(ADD_DAYS(LAG(REPORT_DATE,1) OVER (ORDER BY REPORT_DATE), 1), :LV_START_DATE) AS PREV_REPORT_DATE
                FROM ( SELECT REPORT_DATE FROM :TT_SERIES WHERE DAYNAME(REPORT_DATE) = 'FRIDAY'); */


    IF :LV_UID = 'ALL' THEN

    TT_DASHBOARD =       SELECT REPORT_DATE AS "NAME",
                          NULL AS "HEADING",
                          'GRAPH' AS "SUB_HEADING", 
                          MEASURE AS "SUB_CAT1",
                          NULL AS "SUB_CAT2",
                          SORT AS "SORT1",
                          NULL AS "SORT2", 
                          ROUND(TOT_AMT/1000000, 2) AS "VALUE",
                          NULL AS "SERIAL_NUMBER",
                          NULL AS "UNIT",
                          TO_CHAR (REPORT_DATE) || ':' || measure AS "UID",
                          NULL AS FREQUENCY,
                          'DRILL_DOWN' AS "HYPER_LINK",
                          '$POST=M$;$Y=Value in M$' AS "AI",        
                          NULL AS "TYPE",
                          NULL AS SIZE
                          FROM :TT_DATA
                          ORDER BY REPORT_DATE;

    ELSE

    TT_DASHBOARD =       SELECT NULL AS "NAME",
                          NULL AS "HEADING",
                          NULL AS "SUB_HEADING", 
                          NULL AS "SUB_CAT1",
                          NULL AS "SUB_CAT2",
                          NULL AS "SORT1",
                          NULL AS "SORT2", 
                          NULL AS "VALUE",
                          SERIAL_NUMBER AS "SERIAL_NUMBER",
                          NULL AS "UNIT",
                          NULL AS "UID",
                          NULL AS FREQUENCY,
                          NULL AS "HYPER_LINK",
                          NULL AS "AI",         
                          NULL AS "TYPE",
                          NULL AS SIZE
                          FROM :TT_DRILLDOWN ORDER BY AMT DESC
                          LIMIT 10000;

    END IF;

    END;

程序2:-

    CREATE PROCEDURE bhavya.zz_get_series()

    LANGUAGE SQLSCRIPT AS
   --SQL SECURITY INVOKER 
   --DEFAULT SCHEMA <default_schema_name>

LV_START_DATE   DATE    := '2010-01-01' ;
LV_END_DATE     DATE    := '2031-01-01' ;

BEGIN
DECLARE REPORT_WEEK_INIT integer := ABS(WEEKDAY(LV_START_DATE) - 4);

TT_SERIES = 
(SELECT 
    GENERATED_PERIOD_START AS REPORT_DATE,
    CASE WHEN WEEKDAY(GENERATED_PERIOD_START) > 4 THEN 
        ADD_DAYS(GENERATED_PERIOD_START, WEEKDAY(GENERATED_PERIOD_START) + 
        CASE WHEN WEEKDAY(GENERATED_PERIOD_START)=5 THEN 1 ELSE -1 END) 
    ELSE 
        ADD_DAYS(GENERATED_PERIOD_START, 4-WEEKDAY(GENERATED_PERIOD_START)) 
    END AS WEEK_END
FROM SERIES_GENERATE_DATE ( 'INTERVAL 1 DAY', :LV_START_DATE, COALESCE(:LV_END_DATE, CURRENT_DATE)));

INSERT INTO  "BHAVYA"."AFS_BASE.KPI.TABLES::DB_WEEK_SERIES"( REPORT_DATE, REPORT_WEEK, WEEK_END )
SELECT REPORT_DATE, WEEK(WEEK_END), WEEK_END
FROM :TT_SERIES;

END;

任何帮助表示赞赏。谢谢。我下面的代码显示了我如何尝试合并但失败:-

 PROCEDURE 
"AFS_BASE"."AFS_BASE.KPI.DASHBOARD::PR_REV_CTRL_BOX_ORDER_BY_STAGE_V1" 
(  
IN TT_INPUT "OPS_SCHEMA"."AM.OPS.CORE.TABLETYPES::GTT_INPUT", 
OUT TT_DASHBOARD 
"OPS_SCHEMA"."AM.OPS.CORE.TABLETYPES::GTT_GENERIC_DASHBOARD" 
)

LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER 
DEFAULT SCHEMA AFS_BASE
AS



LV_TAB          NVARCHAR(50) ;
lv_measure      nvarchar(50) ;
lv_report_date  date ;
LV_UID          NVARCHAR(255);
LV_SUB_HEADING  NVARCHAR(255);
LV_START_DATE   DATE    := '2010-01-01' ; 
LV_END_DATE     DATE    := '2031-01-01' ;
LV_WEEKEND      NVARCHAR(10) := 'FRIDAY';

/**********************************
Created by Junaid on 13th May 2017
**********************************/

BEGIN

DECLARE REPORT_WEEK_INIT integer := ABS(WEEKDAY(LV_START_DATE) - 4);

TT_SERIES = 
(SELECT 
    GENERATED_PERIOD_START AS REPORT_DATE,
    CASE WHEN WEEKDAY(GENERATED_PERIOD_START) > 4 THEN 
        ADD_DAYS(GENERATED_PERIOD_START, WEEKDAY(GENERATED_PERIOD_START) + 
        CASE WHEN WEEKDAY(GENERATED_PERIOD_START)=5 THEN 1 ELSE -1 END) 
    ELSE 
        ADD_DAYS(GENERATED_PERIOD_START, 4-WEEKDAY(GENERATED_PERIOD_START)) 
    END AS WEEK_END
FROM SERIES_GENERATE_DATE ( 'INTERVAL 1 DAY', :LV_START_DATE, 
COALESCE(:LV_END_DATE, CURRENT_DATE))) ;


SELECT VALUE INTO LV_UID FROM :TT_INPUT WHERE VARIABLE = 'UID';
SELECT VALUE INTO LV_TAB FROM :TT_INPUT WHERE VARIABLE = 'TAB';
SELECT IFNULL(NULLIF(VALUE,''),:LV_START_DATE) INTO LV_START_DATE FROM 
:TT_INPUT where VARIABLE = 'START_DATE';  
SELECT IFNULL(NULLIF(VALUE,''),:LV_END_DATE) INTO LV_END_DATE FROM :TT_INPUT 
where VARIABLE = 'END_DATE';

BEGIN

    DECLARE EXIT HANDLER FOR SQL_ERROR_CODE 1299

    LV_SUB_HEADING := '';
    SELECT VALUE INTO LV_SUB_HEADING FROM :TT_INPUT WHERE VARIABLE = 
'SUB_HEADING';

END;




TT_HDR =
    SELECT DISTINCT SERIAL_NUMBER 
    FROM "AFS_BASE"."AFS_BASE.TRENDS.TABLES::OPV_KPI_MEASURES"
    WHERE MEASURE_DATE BETWEEN :LV_START_DATE AND :LV_END_DATE;

TT_ZOOM =   
    SELECT 
        'ATTRIBUTE' AS ZOOM_TYPE,
        Z.ATTRIBUTE AS ZOOM_ATTRIBUTE,
        Z.ATTRIBUTE_VALUE AS ZOOM_ATTRIBUTE_VALUE
    FROM "BASE_SCHEMA"."AM.BASE.TABLES::DB_TAB_ZOOM_VALUES" Z
    WHERE 
        Z.TAB_NAME = :LV_TAB 
        AND Z.SCENARIO_NUMBER = SESSION_CONTEXT('$vssod_scenario')
        AND Z.SESSION_ID = SESSION_CONTEXT('$vssod_sid') 
        AND Z.USER_NAME = SESSION_USER
        AND Z.ATTRIBUTE IN (
            SELECT ATTRIBUTE 
            FROM "BASE_SCHEMA"."AM.BASE.TABLES::DB_CONFIG_ATTRIBUE"
            WHERE CLIENT = SESSION_CONTEXT('CLIENT') AND DISPLAY = 'Y')

    UNION ALL

    SELECT 
        'TAG' AS ZOOM_TYPE,
        Z.ATTRIBUTE AS ZOOM_ATTRIBUTE,
        Z.ATTRIBUTE_VALUE AS ZOOM_ATTRIBUTE_VALUE
    FROM "BASE_SCHEMA"."AM.BASE.TABLES::DB_TAB_ZOOM_VALUES" Z
    WHERE 
        TAB_NAME = :LV_TAB 
        AND Z.SCENARIO_NUMBER= SESSION_CONTEXT('$vssod_scenario')
        AND Z.SESSION_ID = SESSION_CONTEXT('$vssod_sid') 
        AND Z.USER_NAME = SESSION_USER
        AND Z.ATTRIBUTE IN (
            SELECT TAG_NAME 
            FROM "BASE_SCHEMA"."AM.BASE.TABLES::DB_CONFIG_TAGS"
            WHERE CLIENT = SESSION_CONTEXT('CLIENT') AND DISPLAY = 'Y'); 

CALL "AFS_BASE"."AFS_BASE.TRENDS.CORE/PR_KPI_FILTER_WITH_ZOOM"(:TT_INPUT, 
:TT_ZOOM, :TT_HDR, TT_FSN);


SELECT SUBSTR_AFTER(:lv_uid, ':') into lv_measure from dummy ;
SELECT SUBSTR_BEFORE (:lv_uid, ':') into lv_report_date from dummy ;

IF :LV_UID = 'ALL' THEN
    TT_INVOICED = 
        SELECT 
            0 as serial_number, 
            week_end as REPORT_DATE, 
            SUM(MEASURE_AMOUNT) AS INV_AMT
        FROM "AFS_BASE"."AFS_BASE.TRENDS.TABLES::OPV_KPI_MEASURES" K
        INNER JOIN "AFS_BASE"."AFS_BASE::DB_WEEK_SERIES" TS
            ON TS.REPORT_DATE = K.MEASURE_DATE
        WHERE 
            MEASURE = 'Invoiced'
            and k.serial_number in (select distinct serial_number from 
   :TT_FSN )
        GROUP BY week_end;

    TT_INVOICE = 
        SELECT REPORT_DATE, 'Invoiced' AS MEASURE, SUM(INV_AMT) AS AMT
                    FROM :TT_INVOICED I
                    GROUP BY report_date ;

    TT_REMAINING = 
        SELECT 
            0 as SERIAL_NUMBER, 
            ts.week_end as REPORT_DATE, 
            MEASURE, SUM(MEASURE_AMOUNT) AS AMT
        FROM "AFS_BASE"."AFS_BASE.TRENDS.TABLES::OPV_KPI_MEASURES" K
        INNER JOIN :TT_week_end TS
            ON TS.WEEK_END BETWEEN K.VALID_FROM_DATE AND K.VALID_TO_DATE
        WHERE 
            k.MEASURE IN ('In Pick', 'In Production', 'In Transit', 'Late', 
      'Not Covered', 'On Hand', 'Open Direct Ship')
            and k.serial_number in (select distinct serial_number from 
      :TT_FSN )
        GROUP BY TS.week_end, MEASURE ;


      TT_DATA = 
        SELECT REPORT_DATE, MEASURE, SUM(AMT) AS TOT_AMT, 1 AS SORT FROM 
     :TT_INVOICE
        GROUP BY REPORT_DATE, MEASURE

        UNION ALL

        SELECT REPORT_DATE, MEASURE, SUM(AMT) AS TOT_AMT, 2 AS SORT FROM 
   :TT_REMAINING
        GROUP BY REPORT_DATE, MEASURE;

   ELSEIF  :lv_measure =  'Invoiced' THEN        
    TT_DRILLDOWN = 
        SELECT 
            K.serial_number, week_end as REPORT_DATE, 
            k.measure, SUM(MEASURE_AMOUNT) AS AMT
        FROM "AFS_BASE"."AFS_BASE.TRENDS.TABLES::OPV_KPI_MEASURES" K
        INNER JOIN "AFS_BASE"."AFS_BASE::DB_WEEK_SERIES" TS
            ON TS.REPORT_DATE = K.MEASURE_DATE and ts.week_end = 
      :lv_report_date
        where 
            MEASURE = 'Invoiced'
            and k.serial_number in (select distinct serial_number from 
      :TT_FSN )
        GROUP BY week_end, k.measure, K.serial_number ;
ELSEIF  :lv_measure <> 'Invoiced' THEN  
    TT_DRILLDOWN = 
        SELECT 
            k.SERIAL_NUMBER, :lv_report_date as  REPORT_DATE, 
            MEASURE, SUM(MEASURE_AMOUNT) AS AMT
        FROM "AFS_BASE"."AFS_BASE.TRENDS.TABLES::OPV_KPI_MEASURES" K
        where 
            k.MEASURE = :lv_measure
            and :lv_report_date BETWEEN K.VALID_FROM_DATE AND 
     K.VALID_TO_DATE
            and k.serial_number in (select distinct serial_number from 
   :TT_FSN )
        GROUP BY MEASURE, K.serial_number ;
  END IF ;

IF :LV_UID = 'ALL' THEN

    TT_DASHBOARD =       
        SELECT 
            REPORT_DATE AS "NAME",
            NULL AS "HEADING",
            'GRAPH' AS "SUB_HEADING", 
            MEASURE AS "SUB_CAT1",
            NULL AS "SUB_CAT2",
            SORT AS "SORT1",
            NULL AS "SORT2", 
            ROUND(TOT_AMT/1000000, 2) AS "VALUE",
            NULL AS "SERIAL_NUMBER",
            NULL AS "UNIT",
            TO_CHAR (REPORT_DATE) || ':' || measure AS "UID",
            NULL AS FREQUENCY,
            'DRILL_DOWN' AS "HYPER_LINK",
            '$POST=M$;$Y=Value in M$' AS "AI",          
            NULL AS "TYPE",
            NULL AS SIZE
            FROM :TT_DATA
            ORDER BY REPORT_DATE;

    ELSE

    TT_DASHBOARD =       
        SELECT 
            NULL AS "NAME",
            NULL AS "HEADING",
            NULL AS "SUB_HEADING", 
            NULL AS "SUB_CAT1",
            NULL AS "SUB_CAT2",
            NULL AS "SORT1",
            NULL AS "SORT2", 
            NULL AS "VALUE",
            SERIAL_NUMBER AS "SERIAL_NUMBER",
            NULL AS "UNIT",
            NULL AS "UID",
            NULL AS FREQUENCY,
            NULL AS "HYPER_LINK",
            NULL AS "AI",       
            NULL AS "TYPE",
            NULL AS SIZE
            FROM :TT_DRILLDOWN ORDER BY AMT DESC
            LIMIT 10000;

    END IF;

  INSERT INTO "AFS_BASE"."AFS_BASE::DB_WEEK_SERIES" ( REPORT_DATE, 
  REPORT_WEEK, WEEK_END )
SELECT REPORT_DATE, WEEK(WEEK_END), WEEK_END
FROM :TT_SERIES;


END;

错误显示在 SERIES_GENERATE_DATE 附近并显示语法错误。“;” 不正确或放错地方。我认为这是错误的。但我不知道如何解决它。

4

0 回答 0