在执行我的代码段时,在第1行出现错误:ORA-01722:无效编号ORA-06512:在第88行

时间:2018-07-09 10:18:58

标签: oracle plsql

DECLARE
    cycCode                                 NUMBER; --3;
    cycInstance                             NUMBER;
    cycYear                                 NUMBER;
    cycStartDate                            VARCHAR2(8);
    cycEndDate                              VARCHAR2(8);
    custKey                                 NUMBER;
    subNo                                   NUMBER;
    custNo                                  NUMBER;
    pcn                                     NUMBER;
    offr                                    NUMBER;
    ofrItm                                  NUMBER;
    ofrInst                                 NUMBER;
    pkgCode                                 VARCHAR2(50);
    activitySeq                             NUMBER;
    rcEffDt                                 DATE;
    rcExptDt                                DATE;
    actvityDt                               DATE;
    noOfDis                                 NUMBER;
    rcRateSeq                               NUMBER;

    CURSOR pop_1  IS
        SELECT rc.customer_key,
               rc.service_receiver_id,
               rc.receiver_customer,
               rc.pay_channel_no,
               getdyna(rc.dynamic_attributes, '#Packaging code'),
               rc.offer,
               rc.offer_item,
               rc.offer_instance,
               rc.insert_activity_seq,
               rc.effective_date,
               rc.expiration_date,
               TRUNC(act.activity_date)
          FROM bl1_rc_rates rc, bl1_activity_history act
         WHERE     rc.cycle_code = cycCode
               AND rc.effective_date - 1 <= TO_DATE(cycEndDate, 'ddmmyyyy')
               AND NVL(rc.expiration_date, TO_DATE(cycStartDate, 'ddmmyyyy')) + 1 >= TO_DATE(cycStartDate, 'ddmmyyyy')
               AND rc.amount > 0
               AND NVL(rc.expiration_date, TO_DATE('31124700', 'ddmmyyyy')) >= rc.effective_date --and rc.receiver_customer=648934805 and rc.charge_code='HS_R_R_ER_WXB6S'
               AND rc.insert_activity_seq = act.activity_seq
               AND rc.effective_date = TRUNC(act.activity_date) + 1 --and rc.customer_key=28
               AND getdyna(rc.dynamic_attributes, 'Product offer ID') IN (SELECT product_offer_id
                                                                            FROM bl9_product_offer
                                                                           WHERE subscriber_type = 'BS');


    CURSOR pop_2  IS
        SELECT CASE WHEN rc1.application_id = 'DSCRC ' THEN rc1.rc_rate_seq_no ELSE rc2.rc_rate_seq_no END AS rc_rate_seq_no
          --,rc1.charge_code, rc1.amount, rc2.charge_code, rc2.amount, rc1.effective_date, rc1.expiration_date, rc2.effective_date, rc2.expiration_date
          FROM bl1_rc_rates rc1, bl1_rc_rates rc2
         WHERE     rc1.customer_key = custKey
               AND rc1.service_receiver_id = subNo
               AND rc1.service_receiver_type = 'S'
               AND rc1.receiver_customer = custNo
               AND rc1.pay_channel_no = pcn
               AND NVL(rc1.expiration_date, TO_DATE('31124700', 'ddmmyyyy')) >= rc1.effective_date
               AND rc1.amount < 0
               AND rc1.effective_date - 1 <= TO_DATE(cycEndDate, 'ddmmyyyy')
               AND NVL(rc1.expiration_date, TO_DATE(cycStartDate, 'ddmmyyyy')) + 1 >= TO_DATE(cycStartDate, 'ddmmyyyy')
               AND getdyna(rc1.dynamic_attributes, 'Base offer id') = offr
               AND getdyna(rc1.dynamic_attributes, 'Base offer item id') = ofrItm
               AND getdyna(rc1.dynamic_attributes, 'Base offer instance id') = ofrInst
               AND rc1.effective_date >= actvityDt
               AND rc2.customer_key = rc1.customer_key
               AND rc2.service_receiver_id = rc1.service_receiver_id
               AND rc2.service_receiver_type = 'S'
               AND rc2.receiver_customer = rc1.receiver_customer
               AND rc2.pay_channel_no = rc1.pay_channel_no
               AND NVL(rc2.expiration_date, TO_DATE('31124700', 'ddmmyyyy')) >= rc2.effective_date
               AND rc2.amount < 0
               AND rc2.effective_date - 1 <= TO_DATE(cycEndDate, 'ddmmyyyy')
               AND NVL(rc2.expiration_date, TO_DATE(cycStartDate, 'ddmmyyyy')) + 1 >= TO_DATE(cycStartDate, 'ddmmyyyy')
               AND getdyna(rc2.dynamic_attributes, 'Base offer id') = getdyna(rc1.dynamic_attributes, 'Base offer id')
               AND getdyna(rc2.dynamic_attributes, 'Base offer item id') = getdyna(rc1.dynamic_attributes, 'Base offer item id')
               AND getdyna(rc2.dynamic_attributes, 'Base offer instance id') = getdyna(rc1.dynamic_attributes, 'Base offer instance id')
               AND rc2.effective_date >= actvityDt
               AND rc1.insert_activity_seq = rc2.insert_activity_seq
               AND rc1.effective_date <= rc2.effective_date
               AND (   rc1.application_id = 'DSCRC '
                    OR rc2.application_id = 'DSCRC ')
               AND rc1.effective_date <= NVL(rc2.expiration_date, TO_DATE('31124700', 'ddmmyyyy'))
               AND NVL(rc1.expiration_date, TO_DATE('31124700', 'ddmmyyyy')) >= rc2.effective_date
               AND getdyna(rc1.dynamic_attributes, '#Packaging code') = getdyna(rc2.dynamic_attributes, '#Packaging code')
               AND getdyna(rc1.dynamic_attributes, '#Savings code') = getdyna(rc2.dynamic_attributes, '#Savings code')
               AND rc1.rc_rate_seq_no <> rc2.rc_rate_seq_no;

    CURSOR pop_3  IS
        SELECT rc.rc_rate_seq_no
          FROM bl1_rc_rates rc
         WHERE     rc.customer_key = custKey
               AND rc.service_receiver_id = subNo
               AND rc.service_receiver_type = 'S'
               AND rc.receiver_customer = custNo
               AND rc.expiration_date IS NOT NULL
               AND rc.pay_channel_no = pcn
               AND NVL(rc.expiration_date, TO_DATE('31124700', 'ddmmyyyy')) >= rc.effective_date
               AND rc.amount < 0
               AND rc.effective_date - 1 <= TO_DATE(cycEndDate, 'ddmmyyyy')
               AND NVL(rc.expiration_date, TO_DATE(cycStartDate, 'ddmmyyyy')) + 1 >= TO_DATE(cycStartDate, 'ddmmyyyy')
               AND getdyna(rc.dynamic_attributes, 'Base offer id') = offr
               AND getdyna(rc.dynamic_attributes, 'Base offer item id') = ofrItm
               AND getdyna(rc.dynamic_attributes, 'Base offer instance id') = ofrInst
               AND NVL(rc.expiration_date, TO_DATE('31124700', 'ddmmyyyy')) > rcExptDt
               AND NOT EXISTS
                       (SELECT 1
                          FROM bl1_rc_rates base
                         WHERE     base.customer_key = rc.customer_key
                               AND base.service_receiver_id = rc.service_receiver_id
                               AND base.service_receiver_type = rc.service_receiver_type
                               AND base.receiver_customer = rc.receiver_customer
                               AND base.pay_channel_no = rc.pay_channel_no
                               AND base.amount > 0
                               AND base.offer = offr
                               AND base.offer_item = ofrItm
                               AND base.offer_instance = ofrInst
                               AND base.effective_date <= rc.effective_date
                               AND NVL(base.expiration_date, TO_DATE('31124700', 'ddmmyyyy')) >= NVL(rc.expiration_date, TO_DATE('31124700', 'ddmmyyyy')));

    CURSOR pop_new  IS
        SELECT cycle_code,
               cycle_instance,
               cycle_year
          FROM bl1_cycle_control
         WHERE     start_date = TRUNC(SYSDATE - 30)
               AND end_date = TRUNC(SYSDATE - 1)
               AND cycle_code NOT IN (77,
                                      36,
                                      88,
                                      29);
BEGIN
    DBMS_OUTPUT.ENABLE(10000000);

    OPEN pop_new;

    LOOP
        FETCH pop_new
            INTO cycCode,
                 cycInstance,
                 cycYear;

        EXIT WHEN pop_new%NOTFOUND;

        SELECT TO_CHAR(start_date, 'ddmmyyyy'), TO_CHAR(end_date, 'ddmmyyyy')
          INTO cycStartDate, cycEndDate
          FROM bl1_cycle_control
         WHERE     cycle_code = cycCode
               AND cycle_instance = cycInstance
               AND cycle_year = cycYear;

        OPEN pop_1;

        LOOP
            FETCH pop_1
                INTO custKey,
                     subNo,
                     custNo,
                     pcn,
                     pkgCode,
                     offr,
                     ofrItm,
                     ofrInst,
                     activitySeq,
                     rcEffDt,
                     rcExptDt,
                     actvityDt;

            EXIT WHEN pop_1%NOTFOUND;
            noOfDis    := 0;

            --DBMS_OUTPUT.PUT_LINE ('Record: '||custKey||','||subNo||','||custNo||','||pcn||','||offr||','||ofrItm||','||ofrInst||','||activitySeq||','||rcEffDt||','||actvityDt);

            SELECT COUNT(1)
              INTO noOfDis
              FROM bl1_rc_rates rc
             WHERE     rc.customer_key = custKey
                   AND rc.service_receiver_id = subNo
                   AND rc.service_receiver_type = 'S'
                   AND rc.receiver_customer = custNo
                   AND rc.pay_channel_no = pcn
                   AND rc.effective_date = rcEffDt - 1
                   AND NVL(rc.expiration_date, TO_DATE('31124700', 'ddmmyyyy')) >= rc.effective_date
                   AND rc.amount < 0
                   AND rc.effective_date - 1 <= TO_DATE(cycEndDate, 'ddmmyyyy')
                   AND NVL(rc.expiration_date, TO_DATE(cycStartDate, 'ddmmyyyy')) + 1 >= TO_DATE(cycStartDate, 'ddmmyyyy')
                   AND NVL(rc.expiration_date, TO_DATE('31124700', 'ddmmyyyy')) >= rc.effective_date
                   AND getdyna(rc.dynamic_attributes, 'Base offer id') = offr
                   AND getdyna(rc.dynamic_attributes, 'Base offer item id') = ofrItm
                   AND getdyna(rc.dynamic_attributes, 'Base offer instance id') = ofrInst;


            IF (noOfDis > 0)
            THEN
                UPDATE bl1_rc_rates rc
                   SET effective_date     = TO_DATE(TO_CHAR(rcEffDt - 1, 'dd-mm-yyyy'), 'dd-mm-yyyy'),
                       sys_update_date    = SYSDATE,
                       operator_id        = '90',
                       application_id     = 'BRC'
                 WHERE     rc.customer_key = 'custKey'
                       AND rc.service_receiver_type = 'S'
                       AND rc.service_receiver_id = 'subNo'
                       AND rc.receiver_customer = 'custNo'
                       AND rc.pay_channel_no = 'pcn'
                       AND rc.offer = 'offr'
                       AND rc.offer_item = 'ofrItm'
                       AND rc.offer_instance = 'ofrInst'
                       AND rc.effective_date = TO_DATE(TO_CHAR(rcEffDt, 'dd-mm-yyyy'), 'dd-mm-yyyy')
                       AND getdyna(rc.dynamic_attributes, '#Packaging code') = 'pkgCode'
                       AND operator_id <> '90';
            END IF;

            OPEN pop_2;

            LOOP
                FETCH pop_2 INTO rcRateSeq;

                EXIT WHEN pop_2%NOTFOUND;

                UPDATE bl1_rc_rates rc
                   SET rc.expiration_date    = rc.effective_date - 1,
                       operator_id           = '90',
                       application_id        = 'BDC'
                 WHERE     rc.customer_key = 'custKey'
                       AND rc.rc_rate_seq_no = 'rcRateSeq'
                       AND rc.operator_id <> '90';
            END LOOP;

            CLOSE pop_2;

            OPEN pop_3;

            LOOP
                FETCH pop_3 INTO rcRateSeq;

                EXIT WHEN pop_3%NOTFOUND;

                UPDATE bl1_rc_rates rc
                   SET rc.expiration_date    = TO_DATE(TO_CHAR(rcExptDt, 'dd-mm-yyyy'), 'dd-mm-yyyy'),
                       operator_id           = '90',
                       application_id        = 'ORDC'
                 WHERE     rc.customer_key = 'custKey'
                       AND rc.rc_rate_seq_no = 'rcRateSeq'
                       AND rc.operator_id <> '90';
            END LOOP;

            CLOSE pop_3;
        END LOOP;

        CLOSE pop_1;
    END LOOP;

    CLOSE pop_new;
END;
/

1 个答案:

答案 0 :(得分:0)

您似乎在隐式投射和进行日期操作。

我猜bl1_rc_rates.effective_date不是真正的日期列,而是varchar2或number(8)。

如果您运行查询

select bc.effective_date, bc.effective_date - 1
from bl1_rc_rates bc;

它运行没有错误吗?

找到包含错误数据的列并进行修复,您的过程将再次运行。您还可以对数据输入进行一些检查,以确保所输入的内容具有有效日期。

将来,我建议尝试从该过程中删除某些部分,然后自行运行它们以缩小错误范围。在这种情况下,它会为您提供行号,该行号应该可以很好地满足您的需求。