2

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?

3
  • 1
    you missed a ; at the END of first block. And I would not use count as variable name, as it is a sql reserved word. Commented Nov 26, 2012 at 12:48
  • Rectified it but still giving me the same error Commented Nov 26, 2012 at 13:02
  • 1
    add also a / as parado says. Commented Nov 26, 2012 at 13:10

3 Answers 3

4

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;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks...Now my script is running
3

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;
  /

Comments

0

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.