2017-04-23 74 views
0

我在PL/SQL方面很新穎,所以我非常肯定問題出在語法上。PLS-00103:遇到符號「END」

我有兩個表。對於第一個表中的每一行,我應該使用第二個表中的數據計算值X,Y,Z,並將其插入到第一個表中。在第二個表中,時間值不相同,所以我應該使用距離它最近的較小值。

我得到「遇到符號」END「」錯誤或頁面剛剛死亡,如果我改變了一些東西。任何人都可以幫助我?

我的代碼如下所示:

DECLARE 

Nr Varchar(5) := 'G01'; /*manuali*/ 
pi NUMBER :=3.14159265359; 
A NUMBER; 
tk NUMBER; 
time NUMBER; 
n0 NUMBER; 
n NUMBER; 
M NUMBER; 
E NUMBER; 
i NUMBER; 
E_old NUMBER; 
dE NUMBER; 
v NUMBER; 
phi NUMBER; 
u NUMBER; 
r NUMBER; 
x1 NUMBER; 
y1 NUMBER; 
x NUMBER; 
y NUMBER; 
z JP_BROAD_KOORD.z%TYPE; 
GM NUMBER := 3.986005e14; /*m^3/s^2*/ 
Omegae_dot NUMBER := 7.2921151467e-5; /*rad/s*/ 
M0 JP_BROADCAST_NAV2.MO%TYPE; 
roota JP_BROADCAST_NAV2.SQRTA%TYPE; 
deltan JP_BROADCAST_NAV2.DELTA_N%TYPE; 
ecc JP_BROADCAST_NAV2.ECCENTRICITY%TYPE; 
omega JP_BROADCAST_NAV2.OMEGA%TYPE; 
cuc JP_BROADCAST_NAV2.CUC%TYPE; 
cus JP_BROADCAST_NAV2.CUS%TYPE; 
crc JP_BROADCAST_NAV2.CRC%TYPE; 
crs JP_BROADCAST_NAV2.CRS%TYPE; 
i0 JP_BROADCAST_NAV2.IO%TYPE; 
idot JP_BROADCAST_NAV2.IDOT%TYPE; 
cic JP_BROADCAST_NAV2.CIC%TYPE; 
cis JP_BROADCAST_NAV2.CIS%TYPE; 
Omega0 JP_BROADCAST_NAV2.OMEGA2%TYPE; 
Omegadot JP_BROADCAST_NAV2.OMEGA_DOT%TYPE; 
toe JP_BROADCAST_NAV2.TOE%TYPE; 
CURSOR BrCursor is 
select TIME 
from JP_BROAD_KOORD; 
CURSOR NavCursor is 
select Mo, Sqrta, delta_n, eccentricity, omega, cuc, cus, crc, crs, io, idot, cic, cis, omega2, omega_dot, toe 
from JP_BROADCAST_NAV2 
where toe=(select max(toe) from JP_BROADCAST_NAV2 where toe < TIME and Satelita_nr=Nr) and Satelita_nr=Nr; 
BEGIN 
FOR item in BrCursor 
LOOP 
OPEN NavCursor; 
A := roota*roota; 
tk := time-toe; 
n0 := sqrt(GM/(A*A*A)); 
n := n0+deltan; 
M := M0+n*tk; 
M := remainder(M+2*pi,2*pi); 
E := M; 
loop 
    E_old := E; 
    E := M+ecc*sin(E); 
    dE := remainder(E-E_old,2*pi); 
    exit when abs(dE) < 1.e-12; 
    end loop; 
E := remainder(E+2*pi,2*pi); 
v := atan2(sqrt(1-ecc*ecc)*sin(E), cos(E)-ecc); 
phi := v+omega; 
phi := remainder(phi,2*pi); 
u := phi    + cuc*cos(2*phi)+cus*sin(2*phi); 
r := A*(1-ecc*cos(E)) + crc*cos(2*phi)+crs*sin(2*phi); 
i := i0+idot*tk  + cic*cos(2*phi)+cis*sin(2*phi); 
Omega := Omega0+(Omegadot-Omegae_dot)*tk-Omegae_dot*toe; 
Omega := remainder(Omega+2*pi,2*pi); 
x1 := cos(u)*r; 
y1 := sin(u)*r; 
x := 0.000001*(x1*cos(Omega)-y1*cos(i)*sin(Omega)); 
y := 0.000001*(x1*sin(Omega)+y1*cos(i)*cos(Omega)); 
z := 0.000001*(y1*sin(i)); 
INSERT INTO JP_BROAD_KOORD (X, Y, Z) 
VALUES (x, y, z); 
CLOSE NavCursor; 
end loop; 
end loop; 
END; 
+3

在最後的'end'之前有多餘的'end loop'。通常正確的代碼格式(特別是縮進)有助於避免pl/sql中的這類錯誤。 –

+0

爲什麼'n NUMBER'但是'M NUMBER;'?你的命名系統是什麼? –

回答

1

「我在PLSQL很新」

現在是收購的好習慣的時間。

一致的縮進不僅僅是簡單:它可以幫助我們識別代碼中的問題。 標籤循環:它們確實可以幫助我們匹配循環的頭部和尾部,這對於像您這樣的長塊代碼特別有用。

採用這些技術可能會幫助你發現你有一個孤兒END LOOP聲明。

DECLARE 
    Nr Varchar(5) := 'G01'; /*manuali*/ 
    ... 
    toe JP_BROADCAST_NAV2.TOE%TYPE; 
    CURSOR BrCursor is 
     select TIME 
     from JP_BROAD_KOORD;  
    CURSOR NavCursor is 
     select Mo, Sqrta, delta_n, eccentricity, omega, cuc, cus, crc, crs, io, idot, cic, cis, omega2, omega_dot, toe 
     from JP_BROADCAST_NAV2 
     where toe=(select max(toe) 
        from JP_BROADCAST_NAV2 
        where toe < TIME 
        and Satelita_nr=Nr) 
     and Satelita_nr=Nr; 
BEGIN 
    <<br_koord>> 
    FOR item in BrCursor LOOP 
     OPEN NavCursor; 
     A := roota*roota; 
     ... 
     E := M; 
     <<de_calc>> 
     LOOP 
      E_old := E; 
      ... 
      exit when abs(dE) < 1.e-12; 
     END LOOP de_calc; 
     E := remainder(E+2*pi,2*pi); 
     ... 
     z := 0.000001*(y1*sin(i)); 
     INSERT INTO JP_BROAD_KOORD (X, Y, Z) 
     VALUES (x, y, z); 
     CLOSE NavCursor; 
    END LOOP br_koord; 
END; 
相關問題