开发者

Oracle 10g - ORA-01747 Error

My procedure:

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;

When I try run that code in Oracle 10g Express Edition, I get this error though:

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

I don't see any reserved words in my code so why am I getting this error?


Probably a mistake you would have avoided if you followed the Golden Rule: Never use PL/SQL when you can use 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 ; 

Not checked for syntax (or that it exactly matches your logic incidentally), but this is faster and less complex than the explicit cursor methodology. also the commit inside the cursor is very bad practice.


You have an extraneous comma at

        UPDATE Auta SET
            poplatok_denny = denny_poplatok,
        WHERE id_auto = my_id_auto;        
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜