Ko mamma tev nestāstīja par Oracle MERGE priekšrakstu

Oracle MERGE priekšraksts (jeb upsert) ļauj ar vienu operāciju izmainīt ierakstu vai pievienot to, ja šāds ieraksts vēl neeksistē. Apmēram:

IF ieraksts atrasts
    THEN UPDATE
ELSE
    INSERT;

Kas nav acīmredzams, bet patiesībā loģisks rezultāts: veicot operāciju ar primāro atslēgu “ON” daļā ir iespējams iegūt kļūdu “ORA-00001: unique constraint (…) violated”. Respektīvi – starp brīdi, kad Oracle noskaidro, ka ieraksts neeksistē un veic INSERT, kāds cits process, veicot MERGE operāciju, var paspēt izpildīt INSERT pirmais.

3 Responses to “Ko mamma tev nestāstīja par Oracle MERGE priekšrakstu”

  1. koko says:

    gribu kaut ko tādu arī MySQL :) Laikam nesagaidīt…. Kaut gan kaut kad pasen dzirdēju, ka kaut kas līdzīgs esot, bet nu atrast neizdevās

  2. How much money will a team get if they win the Premiership?

  3. I found your site on del.icio.us today and really liked it.. i bookmarked it and will be back to check it out some more later.

Leave a Reply

You must be logged in to post a comment.