Oracle
 sql >> Teknologi Basis Data >  >> RDS >> Oracle

Tindak lanjut T:Bandingkan Baris di Tabel Oracle dan perbarui Baris yang Cocok

update your_table
   set status='Matched'
 where id in(
    with IDS(id1,id2,grp,num,rnum) as(
     select a.id,b.id,
            rank() over(order by a.tdate,a.price,a.product,a.quantity),
            case when a.id=lag(a.id) over(partition by a.tdate,a.price,a.product,a.quantity order by a.id)
            then 0
            else dense_rank() over(partition by a.tdate,a.price,a.product,a.quantity order by a.id) end,
            row_number() over(partition by a.tdate,a.price,a.product,a.quantity order by a.id)
       from your_table a, your_table b
      where a.tdate=b.tdate and a.price=b.price and a.product=b.product 
        and a.quantity=b.quantity
        and a.buysell='Sell' and b.buysell='Buy' and a.description!=b.description
    ),
    Q(id1,id2,grp,num,used) as(
      select id1,id2,grp,num,','||id2||','
        from IDS where rnum=1
      union all
      select I.id1,R.column_value,Q.grp,Q.num+1,Q.used||R.column_value||','
        from Q, IDS I,
             table(cast(multiset(
                select min(id2) id from IDS N
                 where N.id1=I.id1
                   and Q.used not like '%,'||N.id2||',%'
             ) as sys.ODCINumberList)) R
       where I.grp=Q.grp and I.num=Q.num+1
    )
 select decode(X,1,id1,id2)
   from Q,
        (select 1 X from DUAL union all select 2 from DUAL)
  where id2 is not null
)



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Nilai CLOB masuk/kembali dari plsql (penentu lokasi LOB tidak valid:ORA-22275)

  2. Oracle 11g - Tanpa Pivot

  3. Cara mengembalikan patch setelah fase cutover gagal di R12.2

  4. hapus pernyataan tidak menghapus catatan

  5. Cara yang benar untuk memberi pengguna akses ke skema tambahan di Oracle