這裏是我的簡單的PL/SQL程序:問題簡單的PL/SQL程序
DECLARE
CURSOR c1 is
SELECT typ, specifikacia_typu, spz FROM Auta
WHERE (substr(spz, 1, 2) = 'KE' OR substr(spz, 1, 2) = 'KS') AND ROWNUM <= 2;
CURSOR c2 is
SELECT typ, specifikacia_typu, spz FROM Auta
WHERE substr(spz, 1, 2) <> 'KE' AND substr(spz, 1, 2) <> 'KS';
my_typ CHAR(10);
my_specifikacia_typu CHAR(15);
my_spz CHAR(8);
BEGIN
-- vytovirt potrebne tabulky pre kosicke a nekosicke auta
CREATE TABLE Kosicke (
typ CHAR(10),
specifikacia_typu CHAR(15),
spz CHAR(8)
);
CREATE TABLE Ostatne (
typ CHAR(10),
specifikacia_typu CHAR(15),
spz CHAR(8)
);
-- prve dve auta z Kosic vlozit do tabulky Kosicke
OPEN c1;
FOR i IN 1..2 LOOP
FETCH c1 INTO my_typ, my_specifikacia_typu, my_spz;
EXIT WHEN c1%NOTFOUND;
INSERT INTO Kosice VALUES(my_typ, my_specifikacia_typu, my_spz);
COMMIT;
END LOOP;
CLOSE c1;
-- auta, ktore nie su z Kosic vlozit do tabulky Ostatne
OPEN c2;
LOOP
FETCH c2 INTO my_typ, my_specifikacia_typu, my_spz;
EXIT WHEN c2%NOTFOUND;
INSERT INTO Ostatne VALUES(my_typ, my_specifikacia_typu, my_spz);
COMMIT;
END LOOP;
CLOSE c1;
END;
/
當我運行的Oracle 10g Express Edition的,我得到這個錯誤:
ORA-06550: line 16, column 5:
PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:
begin case declare exit for goto if loop mod null pragma
raise return select update while with
<<
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe
1. DECLARE
2.
3. CURSOR c1 is
我不知道問題出在哪裏,這是我在PL/SQL中編寫的第一個程序,所以我有點失落。我用從Oracle網站這個範例程序編寫這個程序:http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96624/a_samps.htm#563
編輯:
此外,當我創建程序以外的表,然後再運行該程序,我得到這個錯誤:
ORA-06550: line 17, column 21:
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 17, column 9:
PL/SQL: SQL Statement ignored
1. DECLARE
2. CURSOR c1 is
3. SELECT typ, specifikacia_typu, spz FROM Auta
由於表「Auta」存在,所以沒有任何意義,程序中使用的所有表都存在。
解決,謝謝! – 2009-11-05 11:20:17
然後您應該發佈您的答案,並且請不要編輯標題以表明問題已解決。 – 2009-11-05 11:22:28