How to change record values ​​in Oracle SQL?

I have to flip flight numbers for pairs of flights going back and forth from a set of cities, for example, for example:

1439 ATL SFO
1440 SFO ATL

will end as follows:

1440 ATL SFO
1439 SFO ATL

I tried this query (because you cannot UPDATE .. JOIN in Oracle):

UPDATE
   (SELECT f.airline, f.flightno flightno_f, d.airline, d.flightno flightno_d
       FROM flights f
       INNER JOIN flights d ON f.airline = 9 AND
         f.sourceairport = d.destairport AND
         f.destairport = d.sourceairport AND d.airline = 9
       WHERE d.flightno < f.flightno) g
   SET g.flightno_f = g.flightno_d,
     g.flightno_d = g.flightno_f;

where is the airline, flightno is the primary key for flying to the table. The selection gives me the correct set of records that I want to change, but UPDATE ... SET gives me this error:

   SET g.flightno_f = g.flightno_d,
       *
ERROR at line 7:
ORA-01779: cannot modify a column which maps to a non key-preserved table

Any ideas on where I am going wrong?

+5
source share
1 answer

, , , , ; Oracle , . , , , .

, 1, , d.flightno + 1 = f.flightno.

, , ... - , .

UPDATE flights f1
  SET flightno =
    (SELECT flightno
       FROM flights f2
       WHERE f2.airline = f1.airline
         AND f2.sourceairport = f1.destairport
         AND f2.destairport = f1.sourceairport
    )
  WHERE airline = 9;
+6

All Articles