CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.

Publicaciones

  • UPDATE with JOIN in ORACLE

    Suppose we want to update in our ORACLE database the costs fields of the fact table FAC_TABLE with the unit cost of our table COSTS.

    We can do this in two ways:

    1. (Slow, but valid for a few data or to sporadic uses)

    update FAC_TABLE ft  set UNIT_COST = (select distinct UNIT_COST from COSTS ct  where (ft.id_article = ct.id_article);

    2. (The best way is this, and the performance is ideal if you have constraints)

    UPDATE ( SELECT ft.UNIT_COST AS old_cost,  ct.UNIT_COST AS new_cost FROM FAC_TABLE ft  INNER JOIN COSTS ct ON ft.id_article ct = ct.id_article) )  SET old_cost = new_cost;

    To the proper functionality of this second option you need a UNIQUE or PRIMARY KEY constraint on ct.id_articulo. 
    If you don't have this constraint, you can use the hint / * + BYPASS_UJVC * / after the word UPDATE (Bypass update join view constraint).

    The performance increase if we have the constraint but even without it, the second option should run quite faster than the first option.

     

  • UPDATE con JOIN en SQLServer

    Supongamos que queremos actualizar en nuestra bbdd SQLServer el campo de costes de la tabla de hechos FAC_TABLE con el coste unitario de nuestra tabla de COSTES.

    UPDATE FAC_TABLE
    SET COSTE_UNITARIO = ct.COSTE_UNITARIO
    FROM COSTES ct
    WHERE FAC_TABLE.id_articulo = ct.id_articulo

     

    Algo más sencillo que en Oracle.

     

    Espero que os ayude.

    Héctor Minguet.

  • UPDATE con JOIN en ORACLE SQL

    Supongamos que queremos actualizar en nuestra base de datos ORACLE el campo de costes de la tabla de hechos FAC_TABLE con el coste unitario de nuestra tabla de COSTES.

    Con Oracle SQL podemos hacerlo de dos maneras:

    • Consulta Lenta, pero si es para pocos datos o para lanzarlo esporádicamente nos puede valer
    update FAC_TABLE ft set COSTE_UNITARIO =
       (select distinct COSTE_UNITARIO
        from COSTES ct
        where (ft.id_articulo = ct.id_articulo); 

     

    • La mejor manera es esta, y el rendimimento es óptimo si tiene constraints)
    UPDATE (SELECT ft.COSTE_UNITARIO AS old_coste,
                   ct.COSTE_UNITARIO AS new_coste 
            FROM FAC_TABLE ft INNER JOIN COSTES ct ON ft.id_articulo = ct.id_articulo)
           ) SET old_coste = new_coste;

    Para que esta segunda opción funcione necesitamos tener UNIQUE or PRIMARY KEY constraint en ct.id_articulo.

    Si no tienes esta constraint, puedes utilizar el hint /*+BYPASS_UJVC*/ después de la palabra UPDATE (bypass update join view constraint).