我的程序:
CREATE OR REPLACE PROCEDURE akcia_nepozicane_s_kurzorom
(denny_poplatok IN NUMBER,
kilometrovy_poplatok IN NUMBER)
AS
my_id_auto NUMBER(5);
my_poplatok_denny NUMBER(4);
my_poplatok_km NUMBER(2);
CURSOR c1 IS
SELECT id_auto, poplatok_denny, poplatok_km FROM Auta;
BEGIN
OPEN c1;
LOOP
FETCH c1 INTO my_id_auto, my_poplatok_denny, my_poplatok_km;
EXIT WHEN c1%NOTFOUND;
IF my_poplatok_km >= 10 THEN
UPDATE Auta SET
poplatok_denny = denny_poplatok,
poplatok_km = kilometrovy_poplatok
WHERE id_auto = my_id_auto;
ELSE
UPDATE Auta SET
poplatok_denny = denny_poplatok,
WHERE id_auto = my_id_auto;
END IF;
COMMIT;
END LOOP;
CLOSE c1;
END;
当我尝试在Oracle 10g Express Edition中运行该代码时,我收到此错误:
ERROR at line 23: PL/SQL: ORA-01747: invalid user.table.column, table.column, or column specification
1. CREATE OR REPLACE PROCEDURE akcia_nepozicane_s_kurzorom
2. (denny_poplatok IN NUMBER,
3. kilometrovy_poplatok IN NUMBER)
4. AS
我的代码中没有看到任何保留字,为什么我会收到此错误?
答案 0 :(得分:5)
如果你遵循黄金法则,你可能会避免错误:当你可以使用SQL时不要使用PL / SQL
CREATE OR REPLACE PROCEDURE akcia_nepozicane_s_kurzorom
(denny_poplatok IN NUMBER,
kilometrovy_poplatok IN NUMBER)
AS
BEGIN
UPDATE Auta
Set poplatok_denny = akcia_nepozicane_s_kurzorom.denny_poplatok,
poplatok_km = Case When Auta.poplatok_km >= 10
then akcia_nepozicane_s_kurzorom.kilometrovy_poplatok
Else Auta.poplatok_km
End;
COMMIT;
END akcia_nepozicane_s_kurzorom ;
未检查语法(或者它是否恰好与您的逻辑完全匹配),但这比显式游标方法更快,更简单。光标内部的提交也是非常糟糕的做法。
答案 1 :(得分:4)
上有一个无关的逗号
UPDATE Auta SET
poplatok_denny = denny_poplatok,
WHERE id_auto = my_id_auto;