我是PL / SQL的新手,所以我很确定问题出在某处。
我有两张桌子。对于第一个表中的每一行,我应该使用第二个表中的数据计算值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;
答案 0 :(得分:1)
&#34;我是plsql&#34;
的新手
现在是养成良好习惯的时候了。
一致的缩进不仅仅是迂腐:它可以帮助我们识别代码中的问题。 标签循环:它们确实帮助我们匹配循环的头部和结尾,这对于你在这里的长代码块特别有用。
使用这些技术中的任何一种都可能帮助您发现您有一个孤立的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;