我有这个SQL语句,但我不知道如何在Oracle中编写它(Oracle不支持多表更新):
UPDATE sscanner.sis_emp_card ec, sscanner.sis_cards c, sscanner.sis_employees e
SET e.firstname='x', e.lastname='y', e.car_number=NULL, c.card_number='12345', e.email='x.y@xyz.com', ec.active='1'
WHERE ec.id_card = c.id_card AND ec.id_emp=e.id_employee AND id=1;
sis_cards:id_card(PK)..
sis_employees:id_employee(PK)..
sis_emp_card:id(PK),id_card(FK)引用sis_cards,id_employee(FK)引用sis_employees
答案 0 :(得分:1)
尝试逐个更新,如下面的代码
begin
for R in (select e.rowid ERecId, c.rowid CRecId, ec.rowid ECRecId
from sscanner.sis_emp_card ec, sscanner.sis_cards c,
sscanner.sis_employees e
where ec.id_card = c.id_card
and ec.id_emp = e.id_employee
and id = 1) loop
update sscanner.sis_employees
set firstname = 'x',
lastname = 'y',
car_number = null,
email = 'x.y@xyz.com'
where rowid = R.ERecid;
update sscanner.sis_cards
set card_number = '12345'
where rowid = R.CRecId;
update sscanner.sis_emp_card ec
set ec.active = '1'
where rowid = R.ECRecId;
end loop;
end;
答案 1 :(得分:1)
我知道问题已经得到解答,但有一些Oracle语法用于更新。最后一个是更新连接视图。
UPDATE sscanner.sis_employees e
SET e.firstname='x',
e.lastname='y',
e.car_number=NULL,
e.email = 'x.y@xyz.com'
WHERE EXISTS (
SELECT *
FROM sscanner.sis_emp_card ec, sscanner.sis_cards c
WHERE ec.id_card = c.id_card AND ec.id_employee=e.id_employee AND ec.id=1);
UPDATE sscanner.sis_cards c
SET c.card_number = '12345'
WHERE EXISTS(
SELECT *
FROM sscanner.sis_emp_card ec, sscanner.sis_employees e
WHERE c.id_card = ec.id_card AND ec.id_employee=e.id_employee AND ec.id=1);
UPDATE (
SELECT e.firstname, e.lastname, e.car_number, e.email,
c.card_number, ec.active
FROM sscanner.sis_emp_card ec, sscanner.sis_cards c, sscanner.sis_employees e
WHERE ec.id_card = c.id_card AND ec.id_employee=e.id_employee AND ec.id=1
) ec SET
ec.active='1';