我试图运行我编写的以下存储过程来满足此要求: 编写过程ProcedureName(p_snum,p_CallNum)以添加/注册学生到课程。
Create or Replace Procedure ThreeOne(
p_snum number,
p_CallNum number
) AS
Begin
insert into Students (snum) values (p_snum);
insert into SchClasses (callnum) values (p_callnum);
commit;
rollback;
end;
/
set SERVEROUTPUT on
Execute ThreeOne(500,10500)
但是,在这样做的时候,我在Oracle Developer中遇到以下错误,而且我不确定如何解决这个问题。这可能是显而易见的,但我想了解改善我的技术的原因:
Error starting at line : 17 in command -
Execute ThreeOne(500,10500)
Error report -
ORA-00001: unique constraint (CORY.SYS_C0012641) violated
ORA-06512: at "CORY.THREEONE", line 9
ORA-06512: at line 1
00001. 00000 - "unique constraint (%s.%s) violated"
*Cause: An UPDATE or INSERT statement attempted to insert a duplicate key.
For Trusted Oracle configured in DBMS MAC mode, you may see
this message if a duplicate entry exists at a different level.
*Action: Either remove the unique restriction or do not insert the key.
我的数据库表创建文件数据:
drop table enrollments;
drop table prereq;
drop table schclasses;
drop table courses;
drop table students;
drop table majors;
-----
-----
create table MAJORS
(major varchar2(3) Primary key,
mdesc varchar2(30));
insert into majors values ('ACC','Accounting');
insert into majors values ('FIN','Finance');
insert into majors values ('IS','Information Systems');
insert into majors values ('MKT','Marketing');
create table STUDENTS
(snum varchar2(3) primary key,
sname varchar2(10),
standing number(1),
major varchar2(3) constraint fk_students_major references majors(major),
gpa number(2,1),
major_gpa number(2,1));
insert into students values ('101','Andy',4,'IS',2.8,3.2);
insert into students values ('102','Betty',2,null,3.2,null);
insert into students values ('103','Cindy',3,'IS',2.5,3.5);
insert into students values ('104','David',2,'FIN',3.3,3.0);
insert into students values ('105','Ellen',1,null,2.8,null);
insert into students values ('106','Frank',3,'MKT',3.1,2.9);
create table COURSES
(dept varchar2(3) constraint fk_courses_dept references majors(major),
cnum varchar2(3),
ctitle varchar2(30),
crhr number(3),
standing number(1),
primary key (dept,cnum));
insert into courses values ('IS','300','Intro to MIS',3,2);
insert into courses values ('IS','301','Business Communicatons',3,2);
insert into courses values ('IS','310','Statistics',3,2);
insert into courses values ('IS','355','Networks',3,3);
insert into courses values ('IS','380','Database',3,3);
insert into courses values ('IS','385','Systems',3,3);
insert into courses values ('IS','480','Adv Database',3,4);
insert into courses values ('IS','340','Application Programming',3,4);
create table SCHCLASSES (
callnum number(5) primary key,
year number(4),
semester varchar2(3),
dept varchar2(3),
cnum varchar2(3),
section number(2),
capacity number(3));
alter table schclasses
add constraint fk_schclasses_dept_cnum foreign key
(dept, cnum) references courses (dept,cnum);
insert into schclasses values (10110,2013,'Sp','IS','300',1,45);
insert into schclasses values (10115,2013,'Sp','IS','300',2,35);
insert into schclasses values (10120,2013,'Sp','IS','380',3,35);
insert into schclasses values (10125,2013,'Fa','IS','300',1,118);
insert into schclasses values (10130,2013,'Fa','IS','301',1,33);
insert into schclasses values (10135,2014,'Fa','IS','310',1,35);
insert into schclasses values (10140,2014,'Fa','IS','310',2,35);
insert into schclasses values (10145,2014,'Fa','IS','340',1,30);
insert into schclasses values (10150,2014,'Fa','IS','380',1,33);
insert into schclasses values (10155,2014,'Fa','IS','385',1,35);
insert into schclasses values (10160,2014,'Fa','IS','480',1,35);
create table PREREQ
(dept varchar2(3),
cnum varchar2(3),
pdept varchar2(3),
pcnum varchar2(3),
primary key (dept, cnum, pdept, pcnum));
alter table Prereq
add constraint fk_prereq_dept_cnum foreign key
(dept, cnum) references courses (dept,cnum);
alter table Prereq
add constraint fk_prereq_pdept_pcnum foreign key
(pdept, pcnum) references courses (dept,cnum);
insert into prereq values ('IS','380','IS','300');
insert into prereq values ('IS','380','IS','301');
insert into prereq values ('IS','380','IS','310');
insert into prereq values ('IS','385','IS','310');
insert into prereq values ('IS','340','IS','300');
insert into prereq values ('IS','480','IS','380');
create table ENROLLMENTS (
snum varchar2(3) constraint fk_enrollments_snum references students(snum),
callnum number(5) constraint fk_enrollments_callnum references schclasses(callnum),
grade varchar2(2),
primary key (snum, callnum));
insert into enrollments values (101,10110,'A');
insert into enrollments values (102,10110,'B');
insert into enrollments values (103,10120,'A');
insert into enrollments values (101,10125,null);
insert into enrollments values (102,10130,null);
insert into enrollments values (104,10150,'A');
insert into enrollments values (102,10155,'C');
insert into enrollments values (101,10150,'B');
insert into enrollments values (103,10155,'A');
insert into enrollments values (101,10155,'B');
insert into enrollments values (103,10150,'A');
create table S (
S# varchar2(3),
SNAME varchar2(20),
STATUS number(5),
CITY varchar2(20),
primary key (S#)
);
insert into S values ('S1','Smith',20,'London');
insert into S values ('S2','Jones',10,'Paris');
insert into S values ('S3','Blake',30,'Paris');
insert into S values ('S4','Clark',20,'London');
insert into S values ('S5','Adams',30,'Athens');
create table P (
P# varchar2(3),
PNAME varchar2(20),
COLOR varchar2(20),
WEIGHT number(5),
CITY varchar2(20),
primary key (P#)
);
insert into P values ('P1','Nut','Red',12,'London');
insert into P values ('P2','Bolt','Green',17,'Paris');
insert into P values ('P3','Screw','Blue',17,'Rome');
insert into P values ('P4','Screw','Red',14,'London');
insert into P values ('P5','Cam','Blue',12,'Paris');
insert into P values ('P6','Cog','Red',19,'London');
create table SP (
S# varchar2(3),
P# varchar2(3),
QTY number(10),
primary key (S#,P#)
);
alter table SP
add constraint fk_inventory_supplier foreign key (S#) references S (S#);
alter table SP
add constraint fk_inventory_product foreign key (P#) references P (P#);
insert into SP values ('S1','P1',300);
insert into SP values ('S1','P2',200);
insert into SP values ('S1','P3',400);
insert into SP values ('S1','P4',200);
insert into SP values ('S1','P5',100);
insert into SP values ('S1','P6',100);
insert into SP values ('S2','P1',300);
insert into SP values ('S2','P2',400);
insert into SP values ('S3','P2',200);
insert into SP values ('S4','P2',200);
insert into SP values ('S4','P4',300);
insert into SP values ('S4','P5',400);
create table CUSTOMERS (
CNUM varchar2(3),
CNAME varchar2(20),
ACCOUNTBALANCE number(12,2),
TOTALMILAGE number(10),
primary key (CNUM)
);
insert into CUSTOMERS values ('101','Andy',85.25,2152);
insert into CUSTOMERS values ('102','Betty',170.00,108);
insert into CUSTOMERS values ('103','Cindy',-55.13,3);
insert into CUSTOMERS values ('104','David',1308.02,5510);
insert into CUSTOMERS values ('105','Ellen',99.77,11150);
insert into CUSTOMERS values ('106','Frank',-0.02,80);
commit;
任何指针都会非常感激。
答案 0 :(得分:0)
经过研究,我意识到我实际上是在尝试插入已经存在的重复数据。此外,我意识到我对参数类型使用了错误的赋值,并且不允许适当传递适当数量的空间和数据类型。
感谢大家的帮助!