好的,让我介绍一下主题:我有两个不同的员工表,它们具有不同的字段,我想将它们合并到一个表中。但我想保留旧表并不时执行我的程序来更新我的新表。
这是我到目前为止得到的代码,它在几个小时的错误后终于编译了,但是当我执行我的程序时,我收到消息“未找到条目”。
create type Employee_t as object (
name varchar2(60),
birthdate date,
functions varchar2(40),
monthly_income number,
gender number,
Employeennr number
);
create table Employee of Employee_t (Employeennr primary key);
create type Worker_T as object (
name varchar2(30),
firstname varchar2(30),
birth_month varchar2(5),
incomePerHour number
);
create table Worker of Worker_T;
create type Personal_T as object (
personalnr number,
name varchar2(30),
firstname varchar2(30),
age number,
gender number,
function_code number,
incomePerYear number
);
create table Personal of Personal_T (personalnr primary key);
create type PersonalnrTagging_T as object (
personalnr number,
Employeennr number
);
create table PersonalnrTagging of PersonalnrTagging_T
create type Function_codes_T as object (
code number,
functions varchar2(40)
);
create table Function_codes of Function_codes_T;
create type Gender_T as object (
gender number,
firstname varchar(30)
);
create table Gender of Gender_T;
create sequence Personalnr_Seq start with 1;
create function DateToAge (birthdate date)
return number
is
begin
return floor(months_between(sysdate, birthdate) / 12);
end;
create function StringToAge (birth_month varchar2)
return number
is
begin
return floor(months_between(sysdate, to_date(birth_month, 'MM.YY')) / 12);
end;
create function GetSurname (name varchar2)
return varchar2
is
pos number;
begin
pos := instr(name, ',', 1, 1);
if (pos > 0) then
return substr(name, 0, pos);
end if;
pos := instr(name, ' ', 1, 1);
return substr(name, pos + 1);
end;
create function GetFirstname (name varchar2)
return varchar2
is
pos number;
begin
pos := instr(name, ',', 1, 1);
if (pos > 0) then
return substr(name, pos + 1);
end if;
pos := instr(name, ' ', 1, 1);
return substr(name, 0, pos);
end;
create procedure InsertTables
is
cursor employeer
is select * from Employee;
cursor worker
is select * from Worker;
anr number;
ann varchar2(30);
id number;
bcode number;
persnr number;
gendr number;
begin
for a in employeer
loop
select Employeennr into anr from PersonalnrTagging where Employeennr = a.Employeennr;
if (anr is null) then
select Personalnr_Seq.nextval into id from dual;
select code into bcode from Function_codes where functions = a.functions;
insert into Personal
values (id, GetSurname(a.name), GetFirstname(a.name), DateToAge(a.birthdate), a.gender,
bcode, a.monthly_income * 12);
insert into PersonalnrTagging values (id, a.Employeennr);
else
select code into bcode from Function_codes where functions = a.functions;
select personalnr into persnr from PersonalnrTagging where Employeennr = a.Employeennr;
update Personal
set name = GetSurname(a.name), firstname = GetFirstname(a.name), age = DateToAge(a.birthdate),gender = a.gender,
function_code = bcode, incomePerYear = a.monthly_income * 12
where
personalnr = persnr;
end if;
end loop;
for b in worker
loop
select name into ann from Personal where name = b.name and firstname = b.firstname;
if (ann is null) then
select Personalnr_Seq.nextval into persnr from dual;
select gender into gendr from Gender where firstname = b.firstname;
select code into bcode from Function_codes where functions = 'Worker';
insert into Personal values (persnr, b.name, b.firstname, StringToAge(b.birth_month), gendr, bcode, b.incomePerHour * 40 * 49);
else
select gender into gendr from Gender where firstname = b.firstname;
select code into bcode from Function_codes where functions = 'Worker';
select personalnr into persnr from Personal where name = b.name and firstname = b.firstname;
update Personal
set name = b.name, firstname = b.firstname, age = StringToAge(b.birth_month), gender = gendr,
function_code = bcode, incomePerYear = b.incomePerHour * 40 * 49
where
personalnr = persnr;
end if;
end loop;
end;
insert into Gender values (1, 'Hans');
insert into Gender values (2, 'Petra');
insert into Gender values (0, 'Vali');
insert into Function_codes values (01, 'Professor');
insert into Worker values ('Schulz', 'Hans', '07.87', 1);
insert into Worker values ('Schulz', 'Vali', '11.23', 2);
insert into Employee values ('Herbst, Petra', to_date('76/01/23', 'YY/MM/DD'), 'Professor', 324, 2, 20);
有人看到我犯的错误吗?或者知道问题可能是什么?