这是我成功存储的程序
CREATE OR REPLACE Procedure add_student
(ns_sid IN STUDENTS.sid%type,
ns_firstname IN STUDENTS.firstname%type,
ns_lastname IN STUDENTS.lastname%type,
ns_status IN STUDENTS.status%type,
ns_gpa IN STUDENTS.gpa%type,
ns_email IN STUDENTS.email%type)
IS
BEGIN
INSERT INTO STUDENTS (sid, firstname, lastname, status, gpa, email)
VALUES (ns_sid, ns_firstname, ns_lastname, ns_status, ns_gpa, ns_email);
END;
/
这里是首先生成表格的电话
create table students (sid char(4) primary key check (sid like 'B%'),
firstname varchar2(15) not null, lastname varchar2(15) not null, status varchar2(10)
check (status in ('freshman', 'sophomore', 'junior', 'senior', 'graduate')),
gpa number(3,2) check (gpa between 0 and 4.0), email varchar2(20) unique);
最初我尝试使用一些预定义的参数调用存储过程。
BEGIN
add_student("B100", "Steve", "Stevenson", "senior", 2.31, "Ssteve@edu");
END;
/
这导致错误" PLS-00201:标识符' B100'必须声明"
我是PL / SQL新手,无法修复此问题。我尝试添加DECLARE语句
DECLARE
ns_sid STUDENTS.sid%type;
BEGIN
ns_sid := "B100";
add_student(ns_sid, "Steve", "Stevenson", "senior", 2.31, "Ssteve@edu");
END;
/
这仍会导致错误" PLS-00201:标识符' B100'必须宣布"但它说" PL / SQL:声明被忽略"然后说" PLS-00201:标识符' Steve'必须声明"
进一步挖掘我试图将firstname声明为varchar并查看它是否可行。掠夺者,它没有。
DECLARE
ns_sid STUDENTS.sid%type;
ns_fn varchar(15);
BEGIN
ns_sid := "B100";
ns_fn := "Steve";
add_student(ns_sid, ns_fn, "Stevenson", "senior", 2.31, "Ssteve@edu");
END;
/
这给了三个PLS-00201说" B100","史蒂夫"和史蒂文森"必须宣布。
我希望有人可以解释我的误解。谢谢!
答案 0 :(得分:2)
在处理Oracle中的字符串时,不要使用双引号,而应使用单引号,例如
BEGIN
add_student('B100', 'Steve', 'Stevenson', 'senior', 2.31, 'Ssteve@edu');
END;
/