用于填充表的PL / SQL过程

时间:2016-11-29 22:18:05

标签: oracle plsql

我正在尝试创建一个带有循环的过程,使用来自三个不同表的值来填充具有x个不同值的表:FIRSTNAME,LASTNAME和LOCATION_DATA。但是,我一直收到错误:

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.`

这是我到目前为止所做的:

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;

提前谢谢。

1 个答案:

答案 0 :(得分:1)

每个BEGIN语句都必须具有匹配的END语句。如果你计算代码中的BEGIN和ENDs,你会发现你有四个中的第一个和后两个。

最简单的解决方案是移动内部BEGIN ... END块。你没有从中获得任何价值。