Update with Outer Join

Is it possible to do an update that involves an outer join on the updated table?

Here's what I mean - now, I have something like:

UPDATE table_1 t1
SET col_1 =
(
SELECT t2.col_2
IN table_2 t2
WHERE t2.t1_key = t1.t1_key
)
WHERE THERE ARE
(
SELECT t2.*
IN table_2 t2
WHERE t2.t1_key = t1.t1_key
);
--
UPDATE table_1 t1
SET col_1 = 0
WHERE THERE IS NO
(
SELECT t2.*
IN table_2 t2
WHERE t2.t1_key = t1.t1_key
);

Yes, I could set all values of table_1.col_1 = 0 first and then perform the update first, but it is inefficient because of the number of records in the table that could be updated twice.

Is it possible to combine these two updates in a single update statement?

You can simply use your first update and omit the WHERE EXISTS clause since you want to update all rows in table_1 anyway.

If the subquery finds a match, it will update the selected value. Normally, a non-match would set the column to a null value, but you can solve this with NVL:

SQL> select * from table_1;

              T1_KEY                COL_1
-------------------- --------------------
                   1                    1
                   2                    1
                   3                    1
                   4                    1
                   5                    1
                   6                    1
                   7                    1
                   8                    1
                   9                    1

9 rows selected.

SQL> select * from table_2;

              T2_KEY                COL_2
-------------------- --------------------
                   1                    9
                   3                    9
                   5                    9

SQL> UPDATE table_1 t1
  2  SET    col_1 = nvl (
  3                       (SELECT t2.col_2
  4                        FROM   table_2 t2
  5                        WHERE  t2.t2_key = t1.t1_key
  6                       ),0
  7                     )
  8  ;

9 rows updated.

SQL> select * from table_1;

              T1_KEY                COL_1
-------------------- --------------------
                   1                    9
                   2                    0
                   3                    9
                   4                    0
                   5                    9
                   6                    0
                   7                    0
                   8                    0
                   9                    0

9 rows selected.

Tags: Database

Similar Questions

  • Update with Outer Join, round 2

    Thanks for those of you who have helped me out on the first (I never thought that you could use a SELECTION of a line like that).

    However, here is a new version of my problem:

    I have three tables.
    Table_1 has a column that must be updated based on the Table_2 and Table_3 values.
    Table_1 both Table_2 have values used to determine which line of Table_3 to use.
    However, not all the rows in Table_1 has a corresponding line of Table_3, in which case the value of Table_3 to use is assumed to be 1.

    The tables and the corresponding columns are:

    TABLE_1
    value_1 - value update
    key_2 - a pointer to TABLE_2
    key_3a - a pointer to a TABLE_3 or a dummy value if there is no record of the TABLE_3

    TABLE_2
    key_2 - the primary key
    key_3b - a secondary pointer to TABLE_3
    Value_2 - a value to use in the calculation of TABLE_1.value_1

    TABLE_3
    key_3a - the first part of the unique key
    ley_3b - the second part of the unique key
    value_3 - a value to use in the calculation of TABLE_1.value_1

    If there is a line in table_3 which matches the values table_1.key_3a and table_2.key_3b (where table_2.key_2 = table_1.key_2):
    Set table_1.value_1 = table_2.value_2 * table_3.value_3
    If there is no such line in table_3:
    Set table_1.value_1 = table_2.value_2

    I want to do something like this:

    UPDATE table_1 t1
    SET = Value_1
    (
    SELECT T2.value_2 * NVL (t3.value_3, 1)
    IN table_2 t2
    LEFT JOIN t3 table_3
    WE (t3.key_3b = t2.key_3b and t3.key_3a = t1.key_3a)
    WHERE t2.key_2 = t1.key_2
    )

    However, Oracle does not t1 to be referenced in the outer join clause.
    (Assume that each value of key_2 in table_1 is table_2 as well: it is only the key_3 value that can be a model.)

    If I move "t3.key_3 = t1.key_3" to the WHERE clause, so t1.value_1 is null for lines without the corresponding value of the table_3.

    I can do it with a clone of table_1 using ROWID:

    UPDATE table_1 t1
    SET = Value_1
    (
    SELECT T2.value_2 * NVL (t3.value_3, 1)
    FROM table_1 t1a
    JOIN the t2 table_2
    ON t2.key_2 = t1a.key_2
    LEFT JOIN t3 table_3
    WE (t3.key_3b = t2.key_3b and t3.key_3a = t1a.key_3a)
    WHERE t1a.row_id = t1.row_id
    )

    However, is there an easier way to do it using ANSI joins (i.e. without (+) syntax)?
    I have this feeling I'm missing something obvious here.

    Sorry, I'm not sure understand your scenario this time. It is early and I did have my 64 ounces of caffiene still.

    I didn't look at the statement, you were trying to run and reformatting:

    SQL> UPDATE table_1 t1
      2  SET    value_1 = (SELECT t2.value_2 * NVL((select t3.value_3
      3                                             from   table_3 t3
      4                                             where  t3.key_3b = t2.key_3b
      5                                             and    t3.key_3a = t1.key_3a)
      6                                          ,1)
      7                    FROM   table_2 t2
      8                    WHERE  t2.key_2 = t1.key_2
      9                   )
     10  ;
    
    0 rows updated.
    

    I don't know if it will work for you, but at least it is syntactically correct.

  • BAD RESULTS WITH OUTER JOINS AND TABLES WITH A CHECK CONSTRAINT

    HII All,
    Could any such a me when we encounter this bug? Please help me with a simple example so that I can search for them in my PB.


    Bug:-8447623

    Bug / / Desc: BAD RESULTS WITH OUTER JOINS AND TABLES WITH a CHECK CONSTRAINT


    I ran the outer joins with check queries constraint 11G 11.1.0.7.0 and 10 g 2, but the result is the same. Need to know the scenario where I will face this bug of your experts and people who have already experienced this bug.


    Version: -.
    SQL> select * from v$version;
    
    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE    11.1.0.7.0      Production
    TNS for Solaris: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - Production

    Why do you not use the description of the bug test case in Metalink (we obviously can't post it here because it would violate the copyright of Metalink)? Your test case is not a candidate for the elimination of the join, so he did not have the bug.

    Have you really read the description of the bug in Metalink rather than just looking at the title of the bug? The bug itself is quite clear that a query plan that involves the elimination of the join is a necessary condition. The title of bug nothing will never tell the whole story.

    If you try to work through a few tens of thousands of bugs in 11.1.0.7, of which many are not published, trying to determine whether your application would be affected by the bug? Wouldn't be order of magnitude easier to upgrade the application to 11.1.0.7 in a test environment and test the application to see what, if anything, breaks? Understand that the vast majority of the problems that people experience during an upgrade are not the result of bugs - they are the result of changes in behaviour documented as changes in query plans. And among those who encounter bugs, a relatively large fraction of the new variety. Even if you have completed the Herculean task of verifying each bug on your code base, which would not significantly easier upgrade. In addition, at the time wherever you actually performed this analysis, Oracle reportedly released 3 or 4 new versions.

    And at this stage would be unwise to consider an upgrade to 11.2?

    Justin

  • How to manage the update/insert in display with Outer Join object?

    Hello

    I have a problem in the treatment of update/insert in the original Version that contains two EOs with right outer join. The first EO values are inserted before and I want if second values EO already exists, it will update and if not a new record created.

    Error when I commit after entering values is: ' entity line with null key is not found in SecondEO. "

    What is the solution?

    Thank you

    Hello

    Make sure that your view object, you have included the key attributes of the two entity objects.

    Kind regards

    Saif Khan.

  • Problem with Outer join and filter

    Hello

    I join two tables in the source using a left outer join. Outside of the join, I have a filter specified with condition TabA.C1 > TabB.C2.

    Now, when ODI generates the query it puts the left outer join on the filter condition as well. So he puts filter as

    where
    (1 = 1)
    And ((TabA.C1 = TabB.C1 (+)) AND)
    (TabA.C2 = TabB.C2 (+))
    And TabA.C10 > TabB.C14 (+)

    How to avoid this problem. I tried this performance on stage as well, always generated query remains the same.

    I use the incremental update of the IKM Oracle. My source and target are both on the same PB.


    ~ Chikk

    Hi Chikk,

    If you analyze the data, you'll see it's OK to have the "(+)" to the filter...

    Anyway, if you want to drop it, leave it as inner join and put the "(+)" manually to the join object.

    This help you?

  • Doubt with OUTER JOIN behavior

    I thought I knew all about OUTER JOINS to this scenario. Can pls someone explain how Oracle behaves in the following SQL code:

    WITH t1 AS
    (SELECT 1 as empid from dual
    union all
    select 2 from dual),
    t2 as
    (select 1 as empid from dual)
    select *
    from t1 
    left outer join
    t2
    on (
    t1.empid = t2.empid AND t1.empid=2
    );
    

    Expected O/P

    EMPID EMPID_1
    2NULL VALUE

    Real O/P

    EMPID EMPID_1
    1NULL VALUE
    2NULL VALUE

    In this way...

    SQL > ed
    A written file afiedt.buf

    1 t1 WITH (SELECT empid from all double union 1
    2. Select 2 double),
    3 t2 (select 1 as double empid)
    4  --
    5 Select
    6 T1
    7 * a left outer join t2 (t1.empid = t2.empid) and t1.empid = 2
    SQL > /.

    EMPID EMPID
    ---------- ----------
    2
    1

    the "t1.empid = 2' is part of the OUTER JOIN condition.

    In this way...

    SQL > ed
    A written file afiedt.buf

    1 t1 WITH (SELECT empid from all double union 1
    2. Select 2 double),
    3 t2 (select 1 as double empid)
    4  --
    5 Select
    6 T1
    left outer join 7 t2 on (t1.empid = t2.empid)
    8 * where t1.empid = 2
    SQL > /.

    EMPID EMPID
    ---------- ----------
    2

    the "t1.empid = 2" belongs to the filtering conditions

    When it is part of the OUTER JOIN condition, he says that he should join t2 records where all conditions are met, otherwise the join should not be made, it does not say it to filter the overall results.

    Maybe this helps clarify...

    SQL > ed
    A written file afiedt.buf

    1 t1 WITH (SELECT empid from all double union 1
    2. Select 2 double),
    3 t2 (select empid Union 1 double all the)
    4. Select 2 of the double)
    5  --
    6 select *.
    7 T1
    8 * a left outer join t2 (t1.empid = t2.empid) and t1.empid = 2
    SQL > /.

    EMPID EMPID
    ---------- ----------
    2          2
    1

    Here we have 1 and 2 records in both tables, but the records in t2 are joined only where the record of t1 has an empid 2, so, although t2 has an empid 1, which is not reached because the join condition is not met.

  • Max() with outer join

    I have a couple of tables XX_PERS and XX_ADDRESS as shown below. I would like to return more recent 'city' for each person on the xx_pers table. If no record matching in xx_address, there should always be the id of the person, name of city as null.

    CREATE TABLE xx_pers

    (Key primary ID number,)

    name varchar2 (100)

    );

    CREATE TABLE xx_address

    (

    addr_id PRIMARY KEY NUMBER,

    pers_id NUMBER,

    City VARCHAR2 (25).

    FOREIGN KEY (pers_id) REFERENCES xx_pers (id)

    );

    insert into xx_pers values (1, 'Messi');

    insert into xx_pers values (2, 'Muller');

    insert into xx_pers values (3, 'Ronaldo');

    insert into xx_address values (100.1, "Argentina");

    insert into xx_address values (102.1, "Madrid");

    insert into xx_address values (101.2, "Germany");

    insert into xx_address values (103.2, "Munich - OF");

    The following query returns the most recent 'city' for person 1 and 2 but do not know how to get the 3rd person.

    SELECT ID, name, city

    of xx_pers xx

    , xx_address y

    Where xx.id = y.pers_id

    and y.addr_id in (select max (addr_id) of the xx_address by pers_id group);

    Hello

    Here is another way, which is similar to what you have tried initially, but it uses an outer join to a subquery instead of an IN subquery:

    WITH got_max_addr_id AS

    (

    SELECT pers_id

    MAX (addr_id) AS max_addr_id

    OF xx_address

    GROUP BY pers_id

    )

    SELECT p.id

    p.name

    a.city

    OF xx_pers p

    LEFT OUTER JOIN got_max_addr_id ON m.pers_id = p.id m

    A LEFT OUTER JOIN xx_address ON a.pers_id = m.pers_id

    AND a.addr_id = m.max_addr_id

    ORDER BY p.id

    ;

    It is also very similar to the solution in response #2 above.

    Note Although all 4 of these solutions something in common that is different from the query you posted: they use all of the outer joins.  You obviousy has estimated that an outer join outer join would be useful here, because you mentioned an outer join in the title of the thread, but you are not one yourself.

  • need help with outer join filter.

    Need a little help to filter a result set and I can't seem to find a good way to do this.
    /*table*/
    
    create table invoice( farinvc_invh_code varchar2(100),
                                  farinvc_item varchar2(100),
                                  farinvc_po varchar2(100)
                                  )
       create table po( 
            supplier_number varchar2(60),
            supplier_invoice_no varchar2(60),
            po_number varchar2(60),
            run_date varchar2(60),
            PO_LINE_NUMBER varchar2(60) );
    /*data*/
    
    INSERT INTO "INVOICE" (FARINVC_INVH_CODE, FARINVC_ITEM, FARINVC_PO_ITEM) VALUES ('I0554164', '1', 'P0142245');
    INSERT INTO "INVOICE" (FARINVC_INVH_CODE, FARINVC_ITEM, FARINVC_PO_ITEM) VALUES ('I0554164', '3', 'P0142245');
    INSERT INTO "INVOICE" (FARINVC_INVH_CODE, FARINVC_ITEM, FARINVC_PO) VALUES ('I0554165', '1', 'P0142246');
    INSERT INTO "INVOICE" (FARINVC_INVH_CODE, FARINVC_ITEM, FARINVC_PO) VALUES ('I0554165', '2', 'P0142246');
    
    
    
    
    
    INSERT INTO "PO" (SUPPLIER_NUMBER, SUPPLIER_INVOICE_NO, PO_NUMBER, RUN_DATE, PO_LINE_NUMBER) VALUES ('914100121', '529132260', 'P0142245', '21-NOV-12', '1');
    INSERT INTO "PO" (SUPPLIER_NUMBER, SUPPLIER_INVOICE_NO, PO_NUMBER, RUN_DATE, PO_LINE_NUMBER) VALUES ('914100121', '529137831', 'P0142245', '21-NOV-12', '3');
    INSERT INTO "PO" (SUPPLIER_NUMBER, SUPPLIER_INVOICE_NO, PO_NUMBER, RUN_DATE, PO_LINE_NUMBER) VALUES ('914100121', '529137831', 'P0142245', '21-NOV-12', '2');
    INSERT INTO "PO" (SUPPLIER_NUMBER, SUPPLIER_INVOICE_NO, PO_NUMBER, RUN_DATE, PO_LINE_NUMBER) VALUES ('914100122', '145678', 'P0142246', '22-NOV-12', '1');
    INSERT INTO "PO" (SUPPLIER_NUMBER, SUPPLIER_INVOICE_NO, PO_NUMBER, RUN_DATE, PO_LINE_NUMBER) VALUES ('914100122', '145679', 'P0142246', '22-NOV-12', '2');
    query execution of im.

    SELECT  farinvc_invh_code,
                    supplier_number,
                    supplier_invoice_no,
                    farinvc_item, 
                    farinvc_po ,
                    po_number,
                    run_date,
                    PO_LINE_NUMBER
            FROM INVOICE, PO
            WHERE PO_NUMBER = FARINVC_PO(+)
            AND FARINVC_ITEM(+) = PO_LINE_NUMBER
            
    result
    "FARINVC_INVH_CODE"           "SUPPLIER_NUMBER"             "SUPPLIER_INVOICE_NO"         "FARINVC_ITEM"                "FARINVC_PO"                  "PO_NUMBER"                   "RUN_DATE"                    "PO_LINE_NUMBER"              
    "I0554165"                    "914100122"                   "145678"                      "1"                           "P0142246"                    "P0142246"                    "22-NOV-12"                   "1"                           
    "I0554165"                    "914100122"                   "145679"                      "2"                           "P0142246"                    "P0142246"                    "22-NOV-12"                   "2"                           
    "I0554164"                    "914100121"                   "529132260"                   "1"                           "P0142245"                    "P0142245"                    "21-NOV-12"                   "1"                           
    "I0554164"                    "914100121"                   "529137831"                   "3"                           "P0142245"                    "P0142245"                    "21-NOV-12"                   "3"                           
    ""                            "914100121"                   "529137831"                   ""                            ""                            "P0142245"                    "21-NOV-12"                   "2"                           
    It is a much larger table, and I took an excerpt in order to keep things clear and understanding. I would like to filter the result set to only show lines that have po numbers are the same and line are the same but there is an additional element. in other words as such.
    "FARINVC_INVH_CODE"           "SUPPLIER_NUMBER"             "SUPPLIER_INVOICE_NO"         "FARINVC_ITEM"                "FARINVC_PO"                  "PO_NUMBER"                   "RUN_DATE"                    "PO_LINE_NUMBER"              
    "I0554164"                    "914100121"                   "529132260"                   "1"                           "P0142245"                    "P0142245"                    "21-NOV-12"                   "1"                           
    "I0554164"                    "914100121"                   "529137831"                   "3"                           "P0142245"                    "P0142245"                    "21-NOV-12"                   "3"                           
    ""                            "914100121"                   "529137831"                   ""                            ""                            "P0142245"                    "21-NOV-12"                   "2"                           

    Hello

    Let me assure you that I understand.
    Last time, we were looking for the PO_NUMBERs who have been partially put into correspondence , i.e. groups of rows in the order table with the same po_number, which some had corresponding lines in the table Bill, and some of whom have not. It was essential that there is at least 1 line and 1 row without connections with the same purchase order.
    Now that you are interested SUPPLIER_INVOICE_NOs who are partially paired, i.e. groups of rows in the table of po with the same po_number and supplier_invoice_no, some of which have corresponding lines in the invoice table, and some are not. ("Supplier_Invoice_No" is quite a mouthful. "We'll abbreviate as sin in the future.) However, the final selection is based on po_numbers: If a po_number has partially matched sins, then we are interested all po_number. For example, the result set must include = 529132260 SIN, even if that sin is completely, because there is a partially matching sin (529137831) with the same po_number (P0142245).

    As this problem revolves around partially matching sins, let's call them Cardinal sins . We can calculate match_cnt and total_cnt based NAS as well as po_number. Then, we can use another analytic function so see if the po_number has all cardinal_sins, like this:

    WITH    joined_data     AS
    (
         SELECT     i.farinvc_invh_code
         ,     p.supplier_number
         ,     p.supplier_invoice_no
         ,     i.farinvc_item
         ,     i.farinvc_po
         ,     p.po_number
         ,     p.run_date
         ,     p.po_line_number
         ,     COUNT (i.farinvc_po) OVER ( PARTITION BY  p.po_number
                                            ,                  p.supplier_invoice_no
                               )     AS match_cnt
         ,     COUNT (*)           OVER ( PARTITION BY  p.po_number
                                            ,                  p.supplier_invoice_no
                                          )     AS total_cnt
         FROM           po       p
         LEFT OUTER JOIN  invoice  i  ON   i.farinvc_po    = p.po_number
                                      AND  i.farinvc_item  = p.po_line_number
    )
    ,     got_cardinal_sin_cnt     AS
    (
         SELECT  joined_data.*
         ,     SUM ( CASE
                        WHEN  match_cnt  >= 1
                     AND     match_cnt  <  total_cnt
                     THEN  1
                    END
                  ) OVER (PARTITION BY  po_number)     AS cardinal_sin_cnt
         FROM    joined_data
    )
    SELECT    farinvc_invh_code
    ,       supplier_number
    ,       supplier_invoice_no
    ,       farinvc_item
    ,       farinvc_po
    ,       po_number
    ,       run_date
    ,       po_line_number
    FROM       got_cardinal_sin_cnt
    WHERE       cardinal_sin_cnt     > 0
    ORDER BY  po_number
    ,            farinvc_item
    ;
    
  • Update with INNER JOIN

    Hello

    My update with the inner join does not seem to work.

    UPDATE RECAP R SET R.FLAVOR = (SELECT FN. FLAVOR_NDC FN FLAVOR, REPLACE CAP R WHERE R.NDC11 = FN. NDC11)

    When I write the query above, the inner circle question (SELECT FN. FLAVOR_NDC FN FLAVOR, REPLACE CAP R WHERE R.NDC11 = FN. NDC11) returns multiple lines, and it's a new syntax for me (as I was Teradata and SQL server).

    Can you please how this request can be written to make it work?

    I get the error message below

    SQL error: ORA-01427: einreihig subquery returns multiple rows
    01427 00000 - "einreihig subquery returns several lines.

    1. fix your code:

    UPDATE RECAP R SET R.FLAVOR = (SELECT FN.FLAVOR FROM FLAVOR_NDC FN WHERE R.NDC11 = FN.NDC11)
    

    2. you can use the fusion

    merge into RECAP R
    using FLAVOR_NDC FN
    on(R.NDC11 = FN.NDC11)
    when matched then
         update
         set R.FLAVOR = FN.FLAVOR
    

    Kind regards
    Malakshinov Sayan

  • Interactive reports on views with outer joins.

    We tried to create an interactive report on a view with an outer join. It generated an error indicating that there is not a single column to identify the row. What APEX rule uses to identify the column that should be identify the line? Select statement should the correct column in the table that provides the extra lines to be one that is identified in the view?

    This is your link to the unique view of the record.

    Delete the link; make your view preserved key (so you can use rowid) or identify a column to uniquely identify these lines for Apex.

    This is done in the link column settings in the report attributes.

    SW

  • Need help with outer joins

    I have the following table structure,

    _ Table - 1
    ---------------------------------
    ID | Information
    ---------------------------------
    1. abcadskasasa
    2. asdasdasdasd
    3. saeqdfdvsfcsc
    ---------------------------------


    _ Table - 2
    ---------------------------------
    ID | NEST
    ---------------------------------
    1. 12
    1. 13
    2. 14
    1. 15
    1. 16
    2. 12
    ---------------------------------



    _ Table - 3
    ---------------------------------
    ID | THIERRY
    ---------------------------------
    1. 12
    2. 14
    1. 15
    ---------------------------------

    Now, I want to choose for each ID in table 1 and the number of MIP in the table 2-number of THIERRY of table 3.

    Desired output:_

    ---------------------------------------------------------------------------------------------------
    ID | COUNT_PID | COUNT_PARID
    ---------------------------------------------------------------------------------------------------
    1. 4. 2
    2. 2. 1
    3. 0 | 0
    ---------------------------------------------------------------------------------------------------

    Could someone please help me with this. I'm doing using outer joins, but as I work mainly at the edge of the end, not able to reach an appropriate solution to that above.

    Thanks in advance,
    Tejas

    You should not outer join... That should do it...

    select ID , (select count(PID) from table2  t2 where t2.id = t1.id) , (select count(PARID) from table3  t3 where t3.id = t1.id)
    from table1
    
  • Need help with outer join

    Hello

    I have a requirement in which I need to get data from a third table where a date of the third table is higher than a date in the second array.

    Ex:

    SELECT t1.column1, t3.column2
    FROM t1, t2, t3
    WHERE t1.id = t2.foreign_id
    AND t1.id ( + ) = t3.foreign_id
    AND t3.some_date_column > t2.another_date_column
    
    

    However, using the query above returns no results if the date condition is not met. I still need to show t1.column1 and a null t3.column2.

    How should I do this?

    Thank you

    Allen

    Edit: Added information about the requirement.

    Hi Allen

    1. SELECT t1.column1, t3.column2
    2. T1, t2, t3
    3. WHERE t1.id = t2.foreign_id
    4. AND t1.id = t3.foreign_id (+)
    5. AND t3.some_date_column (+) > t2.another_date_column

    I guess that this t1.column1 must not be null. Or am I wrong? The + sign must be placed on the side where draws are accepted. You must repeat it for each condition on the table.

    Alternativlely you can use the LEFT OUT JOIN syntax. If the two columns are allowed null you need a FULL OUTER JOIN.

    BTW: The join to t2 is not required if a refefernce constraint forced.

  • Update with the join and group by

    Hi all

    I'm currently updating multiple columns in a table from an inner join query.
    First one recover the affected rows and values that I need for the update (which I call this subquery ED_Query).
    It is important to note that this subquery has a group of and and the having clause.

    My first attempt (using the query running in the SQL Server query) fails:

    SQL > update ED_Update
    2 set ED_Update.dtHoraInicioReal = ED_Query.dtHoraInicioReal,
    3 ED_Update.dtHoraFinReal = ED_Query.dtHoraFinReal,
    4 ED_Update.fPorcentajeRealizado = ED_Query.fPorcentajeRealizado
    HISTORICOS_AVANZA 5. HSAE_HIS_EXPEDICIONDIARIA ED_Update
    inner join 6)
    7. select distinct ED.iIdExpedicion, ED.iIdExpedicionDiaria,
    8 MAX (PT.iOrdenEnTrayecto) + 1 as iNumParadas,
    9 MAX (HPP.iOrden) as iOrdenUltimaParada,
    10 MIN (dtHora_LlegadaReal + iTiempoEnParada /(24*60*60)) as dtHoraInicioReal,
    11 MAX (dtHora_LlegadaReal) as dtHoraFinReal,
    12 100 * cast ((MAX (HPP.iOrden) + 1) as float) / cast ((MAX (PT.iOrdenEnTrayecto) + 1) as float) as fPorcentajeRealizado
    13 of HISTORICOS_AVANZA. ED HSAE_HIS_EXPEDICIONDIARIA
    14 left join HISTORICOS_AVANZA. HSAE_HIS_HORAPASOPARADA HPP
    15 ED.iIdExpedicion = HPP.iIdExpedicion and ED.dtJornada = HPP.dtJornada
    16 left join AVANZA. SAE_URB_PARADASTRAYECTO PT on ED.iIdLinea = PT.iIdLinea and ED.iIdTrayecto = PT.iIdTrayecto
    17 where ED.dtJornada = TO_DATE (January 14, 2013 ',' DD/MM/YYYY ') and ED.iIdExpedicion in (-131076)
    18 ED.iIdExpedicion, ED.iIdExpedicionDiaria, ED.dtHoraInicioReal, ED.dtHoraFinReal group
    19 having ED.dtHoraInicioReal <>min (dtHora_LlegadaReal + iTiempoEnParada /(24*60*60))
    20 or ED.dtHoraFinReal <>max (dtHora_LlegadaReal)
    (21) ED_Query
    22 we ED_Update.iIdExpedicionDiaria = ED_Query.iIdExpedicionDiaria;

    ERROR on line 5:
    ORA-00933: SQL not correctly completed command.

    Subquery (ED_Query) work fine in Oracle, so I suspect that the problems are when I mix with the update clause.

    SQL > select distinct ED.iIdExpedicion, ED.iIdExpedicionDiaria,.
    2 MAX (PT.iOrdenEnTrayecto) + 1 as iNumParadas,
    3 MAX (HPP.iOrden) as iOrdenUltimaParada,
    4 MIN (dtHora_LlegadaReal + iTiempoEnParada /(24*60*60)) as dtHoraInicioReal,
    5 MAX (dtHora_LlegadaReal) as dtHoraFinReal,
    6 100 * cast ((MAX (HPP.iOrden) + 1) as float) / cast ((MAX (PT.iOrdenEnTrayecto) + 1) as float) as fPorcentajeRealizado,
    7 ED.dtHoraInicioReal ED_dtHoraInicioReal, ED.dtHoraFinReal as ED_dtHoraFinReal, ED.fPorcentajeRealizado as ED_fPorcentajeRealizado
    8 of HISTORICOS_AVANZA. ED HSAE_HIS_EXPEDICIONDIARIA
    9 left join HISTORICOS_AVANZA. HSAE_HIS_HORAPASOPARADA HPP
    10 on ED.iIdExpedicion = HPP.iIdExpedicion and ED.dtJornada = HPP.dtJornada
    11 left join AVANZA. SAE_URB_PARADASTRAYECTO PT on ED.iIdLinea = PT.iIdLinea and ED.iIdTrayecto = PT.iIdTrayecto
    where the ED.dtJornada 12 = TO_DATE (January 14, 2013 ',' DD/MM/YYYY ') and ED.iIdExpedicion in (-131076)
    13 group of ED.iIdExpedicion, ED.iIdExpedicionDiaria, ED.dtHoraInicioReal, ED.dtHoraFinReal, ED.fPorcentajeRealizado
    14 after ED.dtHoraInicioReal <>min (dtHora_LlegadaReal + iTiempoEnParada /(24*60*60))
    15 or ED.dtHoraFinReal <>max (dtHora_LlegadaReal);

    IIDEXPEDICION IIDEXPEDICIONDIARIA INUMPARADAS IORDENULTIMAPARADA DTHORAINI
    ------------- ------------------- ----------- ------------------ ---------
    DTHORAFIN FPORCENTAJEREALIZADO ED_DTHORA ED_DTHORA ED_FPORCENTAJEREALIZADO
    --------- -------------------- --------- --------- -----------------------
    -131076 5662 406 15 JANUARY 13
    15 JANUARY 13 JANUARY 15, 13 15 JANUARY 13 0

    -131076 5663 406 15 JANUARY 13
    15 JANUARY 13 JANUARY 15, 13 15 JANUARY 13 0

    -131076 5664 406 15 JANUARY 13
    15 JANUARY 13 JANUARY 15, 13 15 JANUARY 13 0

    After reading this forum, I have change the query and try the following:

    SQL > UPDATE
    () 2
    3. select distinct ED.iIdExpedicion, ED.iIdExpedicionDiaria,
    4 MAX (PT.iOrdenEnTrayecto) + 1 as iNumParadas,
    5 MAX (HPP.iOrden) as iOrdenUltimaParada,
    6 MIN (dtHora_LlegadaReal + iTiempoEnParada /(24*60*60)) as dtHoraInicioReal,
    7 MAX (dtHora_LlegadaReal) as dtHoraFinReal,
    8 100 * cast ((MAX (HPP.iOrden) + 1) as float) / cast ((MAX (PT.iOrdenEnTrayecto) + 1) as float) as fPorcentajeRealizado,
    9 ED.dtHoraInicioReal ED_dtHoraInicioReal, ED.dtHoraFinReal as ED_dtHoraFinReal, ED.fPorcentajeRealizado as ED_fPorcentajeRealizado
    HISTORICOS_AVANZA 10. ED HSAE_HIS_EXPEDICIONDIARIA
    11 left join HISTORICOS_AVANZA. HSAE_HIS_HORAPASOPARADA HPP
    12 on ED.iIdExpedicion = HPP.iIdExpedicion and ED.dtJornada = HPP.dtJornada
    13 left join AVANZA. SAE_URB_PARADASTRAYECTO PT on ED.iIdLinea = PT.iIdLinea and ED.iIdTrayecto = PT.iIdTrayecto
    14 where ED.dtJornada = TO_DATE (January 14, 2013 ',' DD/MM/YYYY ') and ED.iIdExpedicion in (-131076)
    Group 15 of ED.iIdExpedicion, ED.iIdExpedicionDiaria, ED.dtHoraInicioReal, ED.dtHoraFinReal, ED.fPorcentajeRealizado
    16 having ED.dtHoraInicioReal <>min (dtHora_LlegadaReal + iTiempoEnParada /(24*60*60))
    17 or ED.dtHoraFinReal <>max (dtHora_LlegadaReal)
    18)
    19 SET ED_dtHoraInicioReal = dtHoraInicioReal,
    20 ED_dtHoraFinReal = dtHoraFinReal,
    21 ED_fPorcentajeRealizado = fPorcentajeRealizado;

    ERROR on line 2:
    ORA-01732: operation non-legal data manipulation on this point of view

    Little help?

    Thanl in advance.

    Published by: 984483 on 28-ene-2013 01:48

    Hello

    Thanks for posting the CREATE TABLE and INSERT.
    Don't forget to post the desired results of these sample data, i.e. the content of the or the tables changed after the UPDATE is made.

    Is that what you want ed_update to look like after that everyhting is finished?

    DATE01      NUMBERMAX  NUMBERSUM
    ---------- ---------- ----------
    01/01/2013         30         60
    02/01/2013          0          0
    03/01/2013          0          0
    

    If so, here's a way to do it:

    UPDATE     ed_update     u
    SET     (numbermax, numbersum) =
         (
                 SELECT  MAX (number01)
              ,     SUM (number01)
              FROM     ed_query
              WHERE     date01     = u.date01
         )
    WHERE     date01     = TO_DATE ('01/01/2013', 'DD/MM/YYYY')   -- If wanted
    ;
    

    In Oracle, INNER JOIN works only in the FROM clause of a SELECT statement.
    When you want to update a table with values from another table, you can do a subquery correlated (as I showed above) or use the MERGER instead of UPDATE.

  • error in the update with a join query

    Hi all

    IM using oracle 10g on windows.

    im not able to use this update query with join...

    UPDATE
    b
    SET
    b.is_stud = 1
    Of
    b Boy
    JOIN IN-HOUSE
    the relationship r
    WE
    b.ID = r.boy_id;

    Thank you very much...
    MERGE into emp trg
    using(Select distinct b.ename ename,a.empno empno from emp a,
                 emp_status b where  a.empno=b.empno) src
    on
    (trg.empno=src.empno)
    when matched then
    update
    SET trg.name = src.ename;
    
  • Can I delete my old windows xp updated with out affecting my preformance?

    just to help the memory space. I have and old computer. Reference Dell latitude c610

    just to help the memory space. I have and old computer. Reference Dell latitude c610

    Windows updates not are not (shouldn't be) which is too much your space.

    Do not uninstall them.  They're going to compromise security if deleted in some cases, stability in others.

    The size of a hard drive do you have?  How much free space?

    Do a house cleaning and the dust of this hard drive:

    You can free up disk space (will also help get rid of the things that you do not use) through the following steps:

    Windows XP should take between 4.5 and 20 GB * with * an Office suite, editing Photo software, alternative Internet browser (s), various Internet plugins and a host of other things installed.  Everything else — and really for most running Windows XP, everything beyond 10 GB, 20 GB of used space - is personal folders.  Archive, move them to a second physical drive, etc.  Or just buy a disc of séraphine, use the app they provide to clone your system as-is to him and continue with the largest disk.

    If you are comfortable with the stability of your system, you can delete the uninstall of patches which has installed Windows XP...
    http://www3.TELUS.NET/dandemar/spack.htm
    (Especially of interest here - #4)
    (Variant: http://www.dougknox.com/xp/utils/xp_hotfix_backup.htm )

    You can run disk - integrated into Windows XP - cleanup to erase everything except your last restore point and yet more 'free '... files cleaning

    How to use disk cleanup
    http://support.Microsoft.com/kb/310312

    You can disable hibernation if it is enabled and you do not...

    When you Hibernate your computer, Windows saves the contents of the system memory in the hiberfil.sys file. As a result, the size of the hiberfil.sys file will always be equal to the amount of physical memory in your system. If you don't use the Hibernate feature and want to reclaim the space used by Windows for the hiberfil.sys file, perform the following steps:

    -Start the Control Panel Power Options applet (go to start, settings, Control Panel, and then click Power Options).
    -Select the Hibernate tab, uncheck "Activate the hibernation", and then click OK. Although you might think otherwise, selecting never under "Hibernate" option on the power management tab does not delete the hiberfil.sys file.
    -Windows remove the "Hibernate" option on the power management tab and delete the hiberfil.sys file.

    You can control the amount of space your system restore can use...

    1. Click Start, right click my computer and then click Properties.
    2. click on the System Restore tab.
    3. highlight one of your readers (or C: If you only) and click on the button "settings".
    4 change the percentage of disk space you want to allow... I suggest moving the slider until you have about 1 GB (1024 MB or close to that...)
    5. click on OK. Then click OK again.

    You can control the amount of space used may or may not temporary Internet files...

    Empty the temporary Internet files and reduce the size, that it stores a size between 64 MB and 128 MB...

    -Open a copy of Microsoft Internet Explorer.
    -Select TOOLS - Internet Options.
    -On the general tab in the section 'Temporary Internet files', follow these steps:
    -Click on 'Delete the Cookies' (click OK)
    -Click on "Settings" and change the "amount of disk space to use: ' something between 64 MB and 128 MB. (There may be many more now.)
    -Click OK.
    -Click on 'Delete files', then select "Delete all offline content" (the box), and then click OK. (If you had a LOT, it can take 2 to 10 minutes or more).
    -Once it's done, click OK, close Internet Explorer, open Internet Explorer.

    You can use an application that scans your system for the log files and temporary files and use it to get rid of those who:

    CCleaner (free!)
    http://www.CCleaner.com/
    (just disk cleanup - do not play with the part of the registry for the moment)

    Other ways to free up space...

    SequoiaView
    http://www.win.Tue.nl/SequoiaView/

    JDiskReport
    http://www.jgoodies.com/freeware/JDiskReport/

    Those who can help you discover visually where all space is used. Then, you can determine what to do.

    After that - you want to check any physical errors and fix everything for efficient access"

    CHKDSK
    How to scan your disks for errors* will take time and a reboot.

    Defragment
    How to defragment your hard drives* will take time

    Cleaning the components of update on your Windows XP computer

    While probably not 100% necessary-, it is probably a good idea at this time to ensure that you continue to get the updates you need. This will help you ensure that your system update is ready to do it for you.

    Download and run the MSRT tool manually:
    http://www.Microsoft.com/security/malwareremove/default.mspx
    (Ignore the details and download the tool to download and save to your desktop, run it.)

    Reset.

    Download/install the latest program Windows installation (for your operating system):
    (Windows XP 32-bit: WindowsXP-KB942288-v3 - x 86 .exe )
    (Download and save it to your desktop, run it.)

    Reset.

    and...

    Download the latest version of Windows Update (x 86) agent here:
    http://go.Microsoft.com/fwlink/?LinkId=91237
    ... and save it to the root of your C:\ drive. After you register on theroot of the C:\ drive, follow these steps:

    Close all Internet Explorer Windows and other applications.

    AutoScan--> RUN and type:
    %SystemDrive%\windowsupdateagent30-x86.exe /WUFORCE
    --> Click OK.

    (If asked, select 'Run'). --> Click on NEXT--> select 'I agree' and click NEXT--> where he completed the installation, click "Finish"...

    Reset.

    Now reset your Windows with this FixIt components update (you * NOT * use the aggressive version if requested):
    How to reset the Windows Update components?

    Reset.

Maybe you are looking for