问题
I am running a script in sql plus, I have a for loop in my script:
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;
When I run the script this error came up:
ORA-06550: line 6, column 1: PLS-00103: Encountered the symbol "BEGIN"
Where am I going wrong?
回答1:
Try to add /
after end;
as below:
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;
回答2:
Looking to your logic ,you can even simplify the script based on condition .
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;
/
回答3:
Semicolon is not there after end .Try this
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;
来源:https://stackoverflow.com/questions/13565093/running-loop-in-script-in-sql-plus