2013-11-15 98 views
3
create or replace procedure pro_enroll(sname_in IN varchar, cname_in IN varchar) 
as 
sno STUDENT.snum%type; 
begin 
    SELECT snum INTO sno FROM STUDENT WHERE sname=sname_in; 
    --dbms_output.put_line(sno || chr(9) || sname_in || chr(9) || cname_in); 
    INSERT INTO ENROLLED(snum, cname) VALUES(sno, c_name_in); 
end pro_enroll; 
/

SELECT * FROM ENROLLED; 

begin 
pro_enroll('M.Lee', 'CS448'); 
pro_enroll('A.Smith', 'ENG320'); 
end; 
/

SELECT * FROM ENROLLED; 

爲什麼我得到「ORA-00984列在這裏不允許」? 在就讀:ORA-00984列在PL/SQL過程中不允許在這裏

CREATE TABLE ENROLLED 
(
snum INTEGER NOT NULL, 
cname VARCHAR(30) NOT NULL, 
PRIMARY KEY (snum, cname), 
FOREIGN KEY (snum) REFERENCES STUDENT(snum), 
FOREIGN KEY (cname) REFERENCES CLASS(cname) 
); 

回答

3

您已經在INSERT,但是,你的程序的參數的實際名稱是cname_in使用的說法c_name_in名稱,不_標誌cname之間,這個作品:

create or replace procedure pro_enroll(sname_in IN varchar, cname_in IN varchar) 
as 
sno STUDENT.snum%type; 
begin 
    SELECT snum INTO sno FROM STUDENT WHERE sname=sname_in; 
    --dbms_output.put_line(sno || chr(9) || sname_in || chr(9) || cname_in); 
    INSERT INTO ENROLLED(snum, cname) VALUES(sno, cname_in); 
end pro_enroll; 
/