我在sqlplus中遇到問題,無法執行腳本來創建存儲過程。當我嘗試運行該腳本,我得到以下錯誤:Oracle SQL - 無法創建存儲過程
PLS-000103: Encountered the symbol "CREATE" when expecting one of the following: begin function pragma procedure subtype type current cursor delete exists prior external language
我認爲,這可能是沒有運行腳本的簡單情況正常,當我登錄到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;