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列”?
在ENROLLED中:
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)
);
最佳答案
您已经在c_name_in
中使用了参数的INSERT
名称,但是,过程的参数的实际名称是cname_in
,而在_
和c
之间没有name
符号,这有效:
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;
/