我在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”
我哪里错了?
答案 0 :(得分: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;
答案 1 :(得分: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;
/
答案 2 :(得分: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;