I tried to model inheritance relationship in SQL. Patron is the parent class of Faculty and these are their definitions.
CREATE TABLE Patron(
fname varchar2(25) NOT NULL,
lname varchar2(25) NOT NULL,
id number(10) NOT NULL,
status varchar2(25) NOT NULL,
country_name varchar2(50) NOT NULL,
CONSTRAINT fk_patron_nationality FOREIGN KEY (country_name) REFERENCES Nationality (country_name),
CONSTRAINT pk_patron PRIMARY KEY (id),
CONSTRAINT chk_status CHECK(status IN ('GOOD','BAD'))
);
CREATE TABLE Faculty (
category varchar2(25) NOT NULL,
id number(10) NOT NULL,
CONSTRAINT pk_faculty PRIMARY KEY (id),
CONSTRAINT fk_faculty FOREIGN KEY (id) REFERENCES Patron (id),
CONSTRAINT fk_faculty_category FOREIGN KEY (category) REFERENCES Faculty_Category (category)
);
I use the following function call to insert data into these tables.
CREATE or replace FUNCTION insert_faculty (fname in varchar2,lname in varchar2,id in number,
status in varchar2,country_name in varchar2,category in varchar2) return integer
is
pragma autonomous_transaction;
begin
insert into patron values (fname,lname,id,status,country_name);
commit;
insert into faculty values (category,id);
commit;
return 1;
end;
Executing the above procedure sometimes gives me the following error.
ORA-00060: deadlock detected while waiting for resource
ORA-06512: at "SMNATARA.INSERT_FACULTY", line 8
00060. 00000 - "deadlock detected while waiting for resource"
*Cause: Transactions deadlocked one another while waiting for resources.
*Action: Look at the trace file to see the transactions and resources
involved. Retry if necessary.
This error doesn't happen always. What is the reason for this error?