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 列”?在已注册:

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) 
);
4

1 回答 1

3

您在 中使用c_name_in了参数名称INSERT,但是,您的过程参数的实际名称是cname_in,没有 and 之间的符号_,这是有效的: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;
/
于 2013-11-15T01:06:34.680 回答