Oracle SQL - 无法创建存储过程

时间:2016-12-05 00:22:05

标签: sql oracle stored-procedures sqlplus

我在sqlplus中遇到问题,我无法执行脚本来创建存储过程。当我尝试运行脚本时,出现以下错误:

  

PLS-000103:遇到以下任何一种情况时遇到符号“CREATE”:       begin function pragma procedure子类型当前游标删除存在于先前的外部语言

我认为这可能是一个不能正确运行脚本的简单情况 - 当我登录sqlplus时,我只需输入以下内容:

@ASSIGN_PILOT.sql

有什么理由不应该运行吗?是否有一种不同的方式可以调用脚本来创建存储过程,或类似的东西?我的脚本如下。我知道它可能有很多错误,但是一旦我开始运行这个东西,我会很乐意解决它们。

create or replace procedure ASSIGN_PILOT (param_flno int, param_distance int, param_origin char) as

--get all pilot/aircraft combos that can make the trip (call it pilots)
CREATE TABLE pilots
AS
SELECT e.eid, ename, a.aid, cruisingrange
FROM employees1 e
INNER JOIN certified1 c
ON e.eid=c.eid
INNER JOIN aircraft a
ON c.aid=a.aid
ORDER BY cruisingrange ASC;

DECLARE
    CURSOR pl_cur IS
        SELECT * FROM pilots
        ORDER BY cruisingrange ASC;

    pl_row pilots%ROWTYPE;
    is_assigned number;

BEGIN 
    DBMS_OUTPUT.PUT_LINE('hi from SP assign_pilot, param_flno = '||param_flno);

    --loop cursor through pilots
    FOR pl_row IN pl_cur LOOP
        --see if the range is long enough
        IF (pl_row.cruisingrange >= param_distance) THEN
            --see if pilot is available (not present in flight_assignments)
            SELECT COUNT(*)
            INTO is_assigned
            FROM flight_assignments FA
            WHERE FA.eid = pl_row.eid;

            --if pilot is available
            IF(is_assigned = 0) THEN
                --add fight to flight_assignments;
                INSERT INTO flight_assignments(flno, aid, eid)
                VALUES(param_flno, pl_cur.aid, pl_cur.eid);
                END;
            END IF;
        END IF;
    END LOOP;

    --if we reach this point, no one is available.
    --add flight to delayed_flights;
    INSERT INTO delayed_flights
    VALUES(param_flno);
END;
/
show errors;

0 个答案:

没有答案