oracle 如何在Appex中使用JOIN执行UPDATE语句[duplicate]

wnavrhmk  于 2023-02-21  发布在  Oracle
关注(0)|答案(2)|浏览(195)
    • 此问题在此处已有答案**:

Update statement with inner join on Oracle(15个答案)
47分钟前就关门了。
我已经尝试添加此查询,但系统不接受。我如何可以修复它请。
我想更新整个部分在预订使用加入
我的表是我创建了一个叫做res的表

CREATE TABLE res
AS
   (SELECT booking.car_regestration_num,
           rent.cost_per_day,
           (booking_date - return_day) AS amount
      FROM rent
           JOIN booking
              ON booking.car_regestration_num = rent.car_regestration_num);

和预订表为

CREATE TABLE booking
(
   return_day             DATE NOT NULL,
   booking_date           DATE NOT NULL,
   cus_num                NUMBER REFERENCES customer (cus_num),
   loc_num                NUMBER REFERENCES c_location (loc_num),
   ins_num                NUMBER REFERENCES insurance (ins_num),
   booking_num            NUMBER PRIMARY KEY,
   car_regestration_num   NUMBER REFERENCES cars (car_regestration_num),
   amount                 BINARY_FLOAT
);

4.我已经试过我给你看的东西了,我同意尽可能地解决这个问题
此问题的目的是将预订表中的金额与值相加

UPDATE BOOKING JOIN res  
ON BOOKING.CAR_REGESTRATION_NUM = res.CAR_REGESTRATION_NUM
SET BOOKING.amount = res.amount;
wqsoz72f

wqsoz72f1#

merge看起来很简单:

MERGE INTO booking b
     USING res r
        ON (r.car_regestration_num = b.car_regestration_num)
WHEN MATCHED
THEN
   UPDATE SET b.amount = r.amount;
mepcadol

mepcadol2#

Oracle不支持在UPDATE语句中使用JOIN。您可以改用相关子查询。
如果要更新所有行:

UPDATE BOOKING b
SET amount = ( SELECT amount
               FROM   res r
               WHERE  b.CAR_REGESTRATION_NUM = r.CAR_REGESTRATION_NUM );

如果只想更新匹配的行:

UPDATE BOOKING b
SET   amount = ( SELECT amount
                 FROM   res r
                 WHERE  b.CAR_REGESTRATION_NUM = r.CAR_REGESTRATION_NUM )
WHERE EXISTS(
                 SELECT 1
                 FROM   res r
                 WHERE  b.CAR_REGESTRATION_NUM = r.CAR_REGESTRATION_NUM
            );

相关问题