2

我在 sql plus 中运行一个脚本,我的脚本中有一个 for 循环:

BEGIN
  FOR count IN 1..100 LOOP
    INSERT INTO CompanyShare VALUES (count, 1, 250);
  END LOOP;
END;

BEGIN
  FOR count IN 101..200 LOOP
    INSERT INTO CompanyShare VALUES (count, 2, 50);
  END LOOP;
END;

当我运行脚本时,出现了这个错误:

ORA-06550:第 6 行,第 1 列:PLS-00103:遇到符号“BEGIN”

我哪里错了?

4

3 回答 3

4

尝试添加/如下end;

BEGIN
  FOR count IN 1..100 LOOP
    INSERT INTO CompanyShare VALUES (count, 1, 250);
  END LOOP;
END;
/ --<-- Here
BEGIN
  FOR count IN 101..200 LOOP
    INSERT INTO CompanyShare VALUES (count, 2, 50);
  END LOOP;
END;
于 2012-11-26T13:07:00.340 回答
3

查看您的逻辑,您甚至可以根据条件简化脚本。

  BEGIN
  FOR count IN 1..200
   LOOP
    INSERT INTO CompanyShare VALUES (count
                                    ,CASE WHEN count<=100 THEN 1   ELSE 2  END
                                    ,CASE WHEN count<=100 THEN 250 ELSE 50 END
                                    );
   END LOOP;
  END;
  /
于 2012-11-26T13:41:12.667 回答
0

结束后没有分号。试试这个

BEGIN
  FOR count IN 1..100 LOOP
   INSERT INTO CompanyShare VALUES (count, 1, 250);
  END LOOP;
END ;   --****
BEGIN
 FOR count IN 101..200 LOOP
  INSERT INTO CompanyShare VALUES (count, 2, 50);
 END LOOP;
END;
于 2012-11-26T12:55:42.167 回答