执行过程时程序错误

时间:2016-05-09 06:55:04

标签: oracle stored-procedures plsql

我在我的数据库中创建了以下过程,该过程使用游标在一个数据库表中填充数据。在执行该过程时,我收到错误:

  

ORA-00911:无效字符       ORA-06512:在“SOURCE_PACNET.IPSERVICE_TEST_FINAL”,第43行       ORA-06512:第1行       00911. 00000 - “无效字符”       *原因:标识符可能不以除以外的任何ASCII字符开头                  字母和数字。第一个之后也允许$#_                  字符。双引号括起来的标识符可能包含                  除了双引号之外的任何字符。替代报价                  (q'#...#')不能使用空格,制表符或回车符                  分隔符。对于所有其他上下文,请参阅SQL语言                  参考手册。

有人可以检查并告诉我代码中的错误。

CREATE OR REPLACE PROCEDURE TEST_FINAL AS
    CURSOR Cur_TieredPricing_PCT  IS
          SELECT *
            FROM IPSERVICE_46PRCT_NO4CASES_TST
        ORDER BY BILLPROFILEID, TELSTRA_SERVICE_ID;

    V_ODD_EVN            NUMBER;
    V_ID_CNT             NUMBER;
    V_IN                 VARCHAR(4) := 'In';
    V_OUT                VARCHAR(4) := 'Out';
    insertstatement      VARCHAR2(5000);
    insertstatement_1    VARCHAR2(5000);
    insertstatement_2    VARCHAR2(5000);

    Isp_TR_var           VARCHAR2(100) := 'PACNET_U_IPT_ISP_32483';

    V_CAL_TYPE           IPSERVICE_46PRCT_NO4CASES.CALCULATION__TYPE%TYPE;
BEGIN
    FOR Cur_TieredPricing_PCT_REC IN Cur_TieredPricing_PCT LOOP
        --- select count from tier_id field
        SELECT DISTINCT REGEXP_COUNT Cur_TieredPricing_PCT_REC.TIER_ID, 'EUR|JPY|KRW|GBP|TWD|SGD|HKD|USD|AUD|MYR') INTO V_ID_CNT FROM DUAL;

        DBMS_OUTPUT.put_line('V_ID_CNT is  ' || V_ID_CNT);

        SELECT Cur_TieredPricing_PCT_REC.CALCULATION__TYPE INTO V_CAL_TYPE FROM DUAL;

        DBMS_OUTPUT.put_line('CALCULATION__TYPE  ' || V_CAL_TYPE);

        IF (UPPER(V_CAL_TYPE) = 'MAXIMUM') THEN
            DBMS_OUTPUT.put_line('V_CAL_TYPE is maximum');

            FOR i IN 1 .. V_ID_CNT LOOP
                DBMS_OUTPUT.put_line('inside for loop');
                insertstatement_1      :=    'INSERT INTO  ROC_PCT_IPSERVICE_THRSHLD_TST( THRESHOLDUSAGE,RATEAMOUNT,INOUTCD,ISPID) values (Cur_TieredPricing_PCT_REC.THRESHOLD_USAGE_'
                                          || i
                                          || ',Cur_TieredPricing_PCT_REC.RATE_AMOUNT_'
                                          || i
                                          || ','
                                          || 'V_IN'
                                          || ','
                                          || 'Isp_TR_var'
                                          || ');';

                DBMS_OUTPUT.put_line('insert statement_1  ' || insertstatement_1);

                EXECUTE IMMEDIATE insertstatement_1;

                insertstatement_2      :=    'INSERT INTO  ROC_PCT_IPSERVICE_THRSHLD_TST( THRESHOLDUSAGE,RATEAMOUNT,INOUTCD,ISPID) values (Cur_TieredPricing_PCT_REC.THRESHOLD_USAGE_'
                                          || i
                                          || ',Cur_TieredPricing_PCT_REC.RATE_AMOUNT_'
                                          || i
                                          || ','
                                          || 'V_OUT'
                                          || ','
                                          || 'Isp_TR_var'
                                          || ');';

                DBMS_OUTPUT.put_line('insert statement_2  ' || insertstatement_2);

                EXECUTE IMMEDIATE insertstatement_2;

                COMMIT;
            END LOOP;
        ELSE
            DBMS_OUTPUT.put_line('V_CAL_TYPE is not maximum');

            FOR i IN 1 .. V_ID_CNT LOOP
                DBMS_OUTPUT.put_line('inside for loop');

                insertstatement      :=    'INSERT INTO  ROC_PCT_IPSERVICE_THRSHLD_TST( THRESHOLDUSAGE,RATEAMOUNT,INOUTCD,ISPID) values (Cur_TieredPricing_PCT_REC.THRESHOLD_USAGE_'
                                        || i
                                        || ',Cur_TieredPricing_PCT_REC.RATE_AMOUNT_'
                                        || i
                                        || ',Cur_TieredPricing_PCT_REC.INOUTCD, Isp_TR_var);';

                DBMS_OUTPUT.put_line('insert statement  ' || insertstatement);

                EXECUTE IMMEDIATE insertstatement;

                COMMIT;
            END LOOP;
        END IF;
    END LOOP;
END TEST_FINAL;

1 个答案:

答案 0 :(得分:0)

在调用REGEXP_COUNT时,您缺少左括号;此外,您不需要查询变量V_CAL_TYPE的分配:

CREATE OR REPLACE PROCEDURE TEST_FINAL AS
    CURSOR Cur_TieredPricing_PCT  IS
          SELECT *
            FROM IPSERVICE_46PRCT_NO4CASES_TST
        ORDER BY BILLPROFILEID, TELSTRA_SERVICE_ID;

    V_ODD_EVN            NUMBER;
    V_ID_CNT             NUMBER;
    V_IN                 VARCHAR(4) := 'In';
    V_OUT                VARCHAR(4) := 'Out';
    insertstatement      VARCHAR2(5000);
    insertstatement_1    VARCHAR2(5000);
    insertstatement_2    VARCHAR2(5000);

    Isp_TR_var           VARCHAR2(100) := 'PACNET_U_IPT_ISP_32483';

    V_CAL_TYPE           IPSERVICE_46PRCT_NO4CASES.CALCULATION__TYPE%TYPE;
BEGIN
    FOR Cur_TieredPricing_PCT_REC IN Cur_TieredPricing_PCT LOOP
        --- select count from tier_id field
        SELECT DISTINCT REGEXP_COUNT (Cur_TieredPricing_PCT_REC.TIER_ID, 'EUR|JPY|KRW|GBP|TWD|SGD|HKD|USD|AUD|MYR') INTO V_ID_CNT FROM DUAL;

        DBMS_OUTPUT.put_line('V_ID_CNT is  ' || V_ID_CNT);

        /* no need for a query
        SELECT Cur_TieredPricing_PCT_REC.CALCULATION__TYPE INTO V_CAL_TYPE FROM DUAL;
        */
        V_CAL_TYPE := Cur_TieredPricing_PCT_REC.CALCULATION__TYPE;

        DBMS_OUTPUT.put_line('CALCULATION__TYPE  ' || V_CAL_TYPE);

        IF (UPPER(V_CAL_TYPE) = 'MAXIMUM') THEN
            DBMS_OUTPUT.put_line('V_CAL_TYPE is maximum');

            FOR i IN 1 .. V_ID_CNT LOOP
                DBMS_OUTPUT.put_line('inside for loop');
                insertstatement_1      :=    'INSERT INTO  ROC_PCT_IPSERVICE_THRSHLD_TST( THRESHOLDUSAGE,RATEAMOUNT,INOUTCD,ISPID) values (Cur_TieredPricing_PCT_REC.THRESHOLD_USAGE_'
                                          || i
                                          || ',Cur_TieredPricing_PCT_REC.RATE_AMOUNT_'
                                          || i
                                          || ','
                                          || 'V_IN'
                                          || ','
                                          || 'Isp_TR_var'
                                          || ');';

                DBMS_OUTPUT.put_line('insert statement_1  ' || insertstatement_1);

                EXECUTE IMMEDIATE insertstatement_1;

                insertstatement_2      :=    'INSERT INTO  ROC_PCT_IPSERVICE_THRSHLD_TST( THRESHOLDUSAGE,RATEAMOUNT,INOUTCD,ISPID) values (Cur_TieredPricing_PCT_REC.THRESHOLD_USAGE_'
                                          || i
                                          || ',Cur_TieredPricing_PCT_REC.RATE_AMOUNT_'
                                          || i
                                          || ','
                                          || 'V_OUT'
                                          || ','
                                          || 'Isp_TR_var'
                                          || ');';

                DBMS_OUTPUT.put_line('insert statement_2  ' || insertstatement_2);

                EXECUTE IMMEDIATE insertstatement_2;

                COMMIT;
            END LOOP;
        ELSE
            DBMS_OUTPUT.put_line('V_CAL_TYPE is not maximum');

            FOR i IN 1 .. V_ID_CNT LOOP
                DBMS_OUTPUT.put_line('inside for loop');

                insertstatement      :=    'INSERT INTO  ROC_PCT_IPSERVICE_THRSHLD_TST( THRESHOLDUSAGE,RATEAMOUNT,INOUTCD,ISPID) values (Cur_TieredPricing_PCT_REC.THRESHOLD_USAGE_'
                                        || i
                                        || ',Cur_TieredPricing_PCT_REC.RATE_AMOUNT_'
                                        || i
                                        || ',Cur_TieredPricing_PCT_REC.INOUTCD, Isp_TR_var);';

                DBMS_OUTPUT.put_line('insert statement  ' || insertstatement);

                EXECUTE IMMEDIATE insertstatement;

                COMMIT;
            END LOOP;
        END IF;
    END LOOP;
END TEST_FINAL;