-1
CREATE OR REPLACE PACKAGE BODY BAS_NUMB_UPD AS
PROCEDURE BAS_NUM_UPDN AS
CURSOR cur IS
    SELECT DISTINCT o.obj_id,LTRIM(substr(convert_171_to_711(cp.T_C_CP),1,7),'0')  bas_n
      FROM t_obj o, mat_tea_rel mpr, coorg_tea cp
     WHERE o.obj_type = 'Resin' 
       AND o.obj_id = mpr.obj_id
       AND mpr.p_k_id = cp.p_k_id;

    l_b_num_attr_id  number(10) := get_attribute_id('Ba Nu');
    flag1 VARCHAR2(10);

    BEGIN
        FOR x IN cur LOOP
            dbms_output.put_line(x.obj_id||'contains b n'||x.bas_n);
            SELECT flag INTO flag1
              FROM t_xc_s_values
             WHERE attr_id = l_b_num_attr_id 
               AND Obj_id = x.obj_id
               AND VALUE = x.bas_n;

            EXCEPTION 
               WHEN NO_DATA_FOUND THEN 
                  flag1 :='Nothing'; 
               WHEN OTHERS THEN
                   raise_application_error(-20011,'Unknown Exception in PROCEDURE');
            END;

            IF flag1 = 1 THEN 
                dbms_output.put_line('flag equal to one');
            ELSE
                INSERT INTO t_xc_s_values (obj_id, at_id, VALUE,)
                VALUES (x.obj_id, l_b_num_attr_id, x.bas_n);
            END IF;
        END LOOP;
    END;
    END BAS_NUM_UPDN;
END BAS_NUMB_UPD;

这些是错误

错误(28,1):PLS-00103:在预期以下情况之一时遇到符号“EXCEPTION”:begin case declare end exit for goto if loop mod null pragma raise return select update while with << close current delete fetch lock insert打开回滚
保存点设置 sql 执行提交 forall 合并管道

错误(35,1):PLS-00103:在预期以下情况之一时遇到符号“IF”:结束而不是编译指示最终实例化顺序覆盖静态成员构造函数映射

错误(47,3):PLS-00103:在预期以下情况之一时遇到符号“END”:;

4

2 回答 2

2

您的代码未正确嵌套:

  • 如果你有一个 EXCEPTION 部分,你需要在同一级别上有三重 BEGIN / EXCEPTION / END。所以你可能需要在 LOOP 之后插入一个 BEGIN。

  • 每个 END 必须匹配一个 BEGIN。除了前面提到的缺少 BEGIN 之外,最后还有太多 END 语句。删除倒数第三行的那个。

这些只是语法错误。我没有检查该程序是否符合您的意图。

于 2012-07-27T09:55:34.470 回答
1

您得到的错误非常简单。您有一个EXCEPTION ... END但没有匹配的BEGIN. 你想为你的标志选择捕获 no_data_found ,所以用一个BEGIN

(为什么要使用WHEN OTHERS?为什么要捕获它然后说它是“未知”?错误永远不会未知。)

BEGIN
     FOR x IN cur LOOP
         dbms_output.put_line(x.obj_id||'contains b n'||x.bas_n);
         BEGIN -- added here
           SELECT flag INTO flag1
             FROM t_xc_s_values
            WHERE attr_id = l_b_num_attr_id
              AND Obj_id = x.obj_id
              AND VALUE = x.bas_n;
          EXCEPTION
             WHEN NO_DATA_FOUND THEN
                flag1 :='Nothing';
             WHEN OTHERS THEN
                raise_application_error(-20011,'Unknown Exception in PROCEDURE');
         END;

下一个错误:您的插入语句有一个逗号太多:

INSERT INTO t_xc_s_values (obj_id, at_id, VALUE,)

下一个错误:一个END太多

    END LOOP;
    END;  -- this will END your procedure block
    END BAS_NUM_UPDN; -- this will complain it has to match the procedure begin

您的 PLSQL 代码也是不必要的。您可以将逻辑编写为 SQL 语句,从而提高性能。

PROCEDURE BAS_NUM_UPDN AS 
IS
   l_b_num_attr_id  number(10) := get_attribute_id('Ba Nu');
BEGIN
   INSERT INTO t_xc_s_values (obj_id, at_id, VALUE)
   SELECT DISTINCT o.obj_id,
                   l_b_num_attr_id,
                   LTRIM(substr(convert_171_to_711(cp.T_C_CP),1,7),'0') bas_n
     FROM t_obj o, mat_tea_rel mpr, coorg_tea cp
    WHERE o.obj_type = 'Resin'
      AND o.obj_id = mpr.obj_id
      AND mpr.p_k_id = cp.p_k_id;
      AND NOT EXISTS (SELECT flag
                        FROM t_xc_s_values
                       WHERE attr_id = l_b_num_attr_id
                         AND Obj_id = o.obj_id
                         AND VALUE = LTRIM(substr(convert_171_to_711(cp.T_C_CP),1,7),'0'));           
END;
于 2012-07-27T10:00:05.933 回答