PL/SQL procedure to populate table

I am attempting to create a procedure with a loop to populate a table with x amount of distinct values using values from three different tables: FIRSTNAME, LASTNAME, and LOCATION_DATA. However, I keep receiving the error:

Error(34,14): PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:    
( begin case declare end exit for goto if loop mod null    
pragma raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
continue close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe purge.`

This is what I have so far:

CREATE OR REPLACE PROCEDURE LOOP_TEST 
IS
    FNLOOP int := 1;
    LNLOOP int := 1;
    LOCLOOP int := 1;
BEGIN
    WHILE FNLoop <= (SELECT MAX(ID) FROM FIRSTNAME) LOOP
    BEGIN
        WHILE LNLoop <= (SELECT MAX(ID) FROM LASTNAME) LOOP
            BEGIN
                WHILE LOCLOOP <= (SELECT MAX(ID) FROM LOCATION_DATA) LOOP
                    BEGIN
                        SELECT 
                              FirstName
                              , (SELECT LastName 
                                 FROM LASTNAME B 
                                 WHERE LNLOOP = B.ID)
                             , (SELECT City 
                               FROM LOCATION_DATA C
                               WHERE LOCLOOP = C.ID)
                            , (SELECT State 
                               FROM LOCATION_DATA C
                                WHERE LOCLOOP = C.ID)
                        INTO RANDOM_DATA
                        FROM FIRSTNAME A
                        WHERE FNLOOP = A.ID;
                        LOCLOOP := LOCLOOP + 1;
                         --WAITFOR DELAY '00:00:01' 
                  END;
            LNLOOP := LNLOOP + 1;
            LOCLOOP := 1;
            END LOOP;
      FNLOOP := FNLOOP + 1;
      LNLOOP := 1;
      END LOOP;
  END LOOP;
END LOOP_TEST;

Thank you in advance.

Upvotes: 0

Views: 732

Answers (1)

APC
APC

Reputation: 146289

Every BEGIN statement must having a matching END statement. If you count the BEGINs and ENDs in your code you'll find you have four of the first and only two of the latter.

Easiest solution is to move the internal BEGIN ... END blocks. You're not getting any value from them.

Upvotes: 1

Related Questions