PL / SQL过程错误ORA-00900:无效的SQL语句

时间:2016-05-15 15:42:50

标签: oracle plsql

我是PL / SQL的新手,我正在尝试用2个游标创建一个程序,我不知道为什么会出现这个错误: ORA-00900:无效的SQL语句

PROCEDURE filme_pret IS
CURSOR planificari_pret_redus (pret_propus NUMBER) IS   
SELECT * FROM planificare WHERE pret < pret_propus ;
obiect planificari_pret_redus%rowtype;
CURSOR planificari_pret_normal IS  
SELECT * FROM planificare;
obiect2 planificari_pret_normal%rowtype;
    BEGIN
    dbms_output.put_line('Filme cu pret redus');
    for obiect in planificari_pret_redus(100) 
    LOOP
        dbms_output.put_line(obiect.idplanificare || ' ' || obiect.idfilm  || ' ' || obiect.pret);
    END LOOP;
for obiect2 in planificari_pret_normal
    LOOP
        dbms_output.put_line(obiect2.idplanificare || ' ' || obiect2.idfilm  || ' ' || obiect2.pret);
    END LOOP;

    END;

谢谢。

2 个答案:

答案 0 :(得分:0)

这是一个错字吗?

obiect planificari%rowtype;

似乎planificari不存在。

答案 1 :(得分:0)

你的代码的主要部分是好的,你只需要决定如何使用它;如果你想创建一个程序而不存储它,你需要一个完整的DECLARE...BEGIN...END块:

DECLARE
    /* declare your procedure */
    PROCEDURE filme_pret IS
        CURSOR planificari_pret_redus(pret_propus NUMBER) IS
            SELECT *
              FROM planificare
             WHERE pret < pret_propus;

        obiect     planificari_pret_redus%ROWTYPE;

        CURSOR planificari_pret_normal  IS
            SELECT * FROM planificare;

        obiect2    planificari_pret_normal%ROWTYPE;
    BEGIN
        DBMS_OUTPUT.put_line('Filme cu pret redus');

        FOR obiect IN planificari_pret_redus(100) LOOP
            DBMS_OUTPUT.put_line(obiect.idplanificare || ' ' || obiect.idfilm || ' ' || obiect.pret);
        END LOOP;

        FOR obiect2 IN planificari_pret_normal LOOP
            DBMS_OUTPUT.put_line(obiect2.idplanificare || ' ' || obiect2.idfilm || ' ' || obiect2.pret);
        END LOOP;
    END;
BEGIN
    /* CALL YOU PROCEDURE */        
    filme_pret;
END;
/

这样你的程序就不会存储在DB中,你总是需要使用整个块;如果要创建存储过程,则需要以下语法:

CREATE OR REPLACE PROCEDURE filme_pret IS
    CURSOR planificari_pret_redus(pret_propus NUMBER) IS
        SELECT *
          FROM planificare
         WHERE pret < pret_propus;

    obiect     planificari_pret_redus%ROWTYPE;

    CURSOR planificari_pret_normal  IS
        SELECT * FROM planificare;

    obiect2    planificari_pret_normal%ROWTYPE;
BEGIN
    DBMS_OUTPUT.put_line('Filme cu pret redus');

    FOR obiect IN planificari_pret_redus(100) LOOP
        DBMS_OUTPUT.put_line(obiect.idplanificare || ' ' || obiect.idfilm || ' ' || obiect.pret);
    END LOOP;

    FOR obiect2 IN planificari_pret_normal LOOP
        DBMS_OUTPUT.put_line(obiect2.idplanificare || ' ' || obiect2.idfilm || ' ' || obiect2.pret);
    END LOOP;
END;
/

在此之后,您只需在PL / SQL块中调用您的过程:

begin
    filme_pret;
end;
/