PLS-00103:遇到符号“END”
Posted
技术标签:
【中文标题】PLS-00103:遇到符号“END”【英文标题】:PLS-00103: Encountered the symbol "END" 【发布时间】:2017-04-23 12:33:36 【问题描述】:我是 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;
【问题讨论】:
在最终的end
之前有多余的end loop
。通常正确的代码格式(尤其是缩进)有助于避免 pl/sql 中的此类错误。
为什么是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;
【讨论】:
以上是关于PLS-00103:遇到符号“END”的主要内容,如果未能解决你的问题,请参考以下文章
PLS-00103:在期待 + & = 等时遇到符号“END”
错误:PLS-00103:在预期以下情况之一时遇到符号“END”
ORA-06550:第 13 行,第 4 列:PLS-00103:遇到“UPDATE” ORA-06550:第 15 行,第 3 列:PLS-00103:遇到符号“END”