UPDATED MULTI-COLUMN ORA-00001

When I try to update the 3 columns to s_cust with s_upd_fault data I get ORA-00001: unique constraint (DaveyB.FLT_REF) violated.

I'm not sure why this is and how to fix it.

I hope you can help.

CREATE TABLE s_upd_fault AS
SELECT  11111 AS s_fault_number,
            'David Bryan' AS s_full_name,
            'Closed' AS s_fault_status
            --'' AS t_adv_notes,
            --'' AS t_adv_fault_status
FROM DUAL UNION ALL
SELECT 11112, 'James Smith', 'Open' FROM DUAL UNION ALL
SELECT 11113, 'Claire Smith', 'Closed' FROM DUAL UNION ALL
SELECT 11114, 'Jenny Row', 'Closed' FROM DUAL UNION ALL
SELECT 11115, 'Stan Lee', 'Closed' FROM DUAL UNION ALL
SELECT 11116, 'John Steves', 'Closed' FROM DUAL UNION ALL
SELECT 11117, 'James James', 'Open' FROM DUAL UNION ALL
SELECT 11118, 'David David', 'Open' FROM DUAL UNION ALL
SELECT 11119, 'Peter Peter', 'Open' FROM DUAL
;

/* TEST DATA*/
--INSERTS TODAYS DATA INTO THE TABLE
INSERT INTO s_cust (s_fault_number, s_full_name, s_fault_status) ( 
SELECT      s_fault_number, s_full_name, s_fault_status
FROM        s_fault
)
; 

/*CREATES A TABLE TEMPLATE TO STORE THE DATA*/ 
CREATE TABLE s_cust (
s_fault_number  VARCHAR(20) CONSTRAINT flt_ref PRIMARY KEY,
s_full_name     VARCHAR2(15),
s_fault_status  VARCHAR2(10),
t_adv_notes     VARCHAR2(20),
t_adv_fault_status VARCHAR2(30),
    CHECK (s_fault_status IN ('Open', 'Closed'))  --VALIDATION
);


--UPDATE THE COLUMNS WITH NEW DATA
UPDATE  
    s_cust 
SET 
(   s_fault_number,
    s_full_name,
    s_fault_status
) = 
(   
    SELECT  s_fault_number,
            s_full_name,
            s_fault_status
    FROM    s_upd_fault
    WHERE   s_fault_number = '11111'
)
Edited by: DaveyB October 8, 2009 12:38

Hello

UPDATE
    s_cust
SET
(   s_fault_number,
    s_full_name,
    s_fault_status
) =
(
    SELECT  s_fault_number,
            s_full_name,
            s_fault_status
    FROM    s_upd_fault
    WHERE   s_fault_number = '11111'
)

Because the above query is updated all the lines with s_fault_number as '11111', and since it is a primary key, you cannot update this value to more than one line.

I guess you could want to do that

UPDATE
    s_cust  s_cust
SET
(   s_fault_number,
    s_full_name,
    s_fault_status
) =
(
    SELECT  s_fault_number,
            s_full_name,
            s_fault_status
    FROM    s_upd_fault suf
    WHERE   s_cust. s_fault_number = suf.s_fault_number
)
where s_fault_number = '11111'

If you want to update the entire column and then withdraw where s_fault_number = '11111'

Concerning
Anurag Tibrewal.

Tags: Database

Similar Questions

  • updated multi-column seq

    Hi all

    Can someone help me to update my emp table.

    It's my orginal table
    SQL> select * from emp_addr order by 1, 2;

    EMP_NAME        EMP_ADD              CO_NAME
    --------------- -------------------- --------------------
    ADAM            803, Coton Gren rd   hl bank
    ADAM            803, Coton Gren rd   hl bank
    ADAM            Defu Lane 10         can bank
    JACK            Ubi Rd 4             bank ofshore
    JON             78, Sin Ming Dr      bank ofshore
    JON             78, Sin Ming Dr      bank ofshore
    SAM             15, Telok Kurau Rd   bank
    SAM             205,Alexandra Rd     bank

    8 rows selected
    the output should look like
    SQL> select * from emp_addr order by 1, 2;

    EMP_NAME        EMP_ADD              CO_NAME
    --------------- -------------------- --------------------
    ADAM_1          803, Coton Gren rd   hl bank
    ADAM_1          803, Coton Gren rd   hl bank
    ADAM_2          Defu Lane 10         can bank
    JACK_1          Ubi Rd 4             bank ofshore
    JON_1           78, Sin Ming Dr      bank ofshore
    JON_1           78, Sin Ming Dr      bank ofshore
    SAM_1           15, Telok Kurau Rd   bank
    SAM_2           205,Alexandra Rd     bank

    8 rows selected
    Here ADAM_1 is repeated twice because EMP_ADD and CO_NAME twice.
    Its a group of EMP_ADD and CO_NAME

    Thank you

    Rgds
    Saaz
    SQL> select * from t
      2  /
    
    NAME                 ADDRESS            COMP
    -------------------- ------------------ ------------
    ADAM                 803, Coton Gren rd hl bank
    ADAM                 803, Coton Gren rd hl bank
    ADAM                 Defu Lane 10       can bank
    JACK                 Ubi Rd 4           bank ofshore
    JON                  78, Sin Ming Dr    bank ofshore
    JON                  78, Sin Ming Dr    bank ofshore
    SAM                  15, Telok Kurau Rd bank
    SAM                  205,Alexandra Rd   bank
    
    8 rows selected.
    
    SQL> update t
      2     set name = (    select name||rno name
      3               from (select row_number() over(partition by name order by name) rno,
      4                            t.*
      5                       from (select distinct name, address, comp from t) t) t1
      6              where t.name = t1.name
      7                and t.address = t1.address
      8                and t.comp = t1.comp)
      9  /
    
    8 rows updated.
    
    SQL> select * from t
      2  /
    
    NAME                 ADDRESS            COMP
    -------------------- ------------------ ------------
    ADAM1                803, Coton Gren rd hl bank
    ADAM1                803, Coton Gren rd hl bank
    ADAM2                Defu Lane 10       can bank
    JACK1                Ubi Rd 4           bank ofshore
    JON1                 78, Sin Ming Dr    bank ofshore
    JON1                 78, Sin Ming Dr    bank ofshore
    SAM1                 15, Telok Kurau Rd bank
    SAM2                 205,Alexandra Rd   bank
    
    8 rows selected.
    
  • ORA-00001 on form insert, duplicate value

    Hello!
    I have 8 fields in my form. The values of 4 of them go in Table1 and Table2 others 4.
    Table 1 has a composite unique constraint based on 2 columns (which are filled with the first 2 fields in my form which are the first and last name).
    Table2 has no constraints.
    I've manually recreated my form that was originally made with the wizard block/layout of data. So now im integration with applications I've written. I have to mention everything works fine as long as im not looking to insert a record for someone who is already in Table1.

    The problem: ORA-00001 ("you tried to execute an INSERT or UPDATE statement that created a value duplicated in an area limited by a single index.") when im trying to insert a record for someone who is already in the table 1 (i.e. the name and family name combination is most unique in Table1). In Table1, I say everything is all right, because I don't want to not more than once the same person, but because of this exception ORA INSERT into Table2 also fails. How can I avoid this?

    The code is also just that INSERT INTO can get so I won't post.

    THX,
    Iulian

    If I understand the problem correctly from what you say,

    "So now im integration with applications I've written. The code is also just that INSERT INTO can get so I won't post. »

    This means that you have two table insert statements. Wrap the first statement with the Manager of exceptions as noted below. This way nothing will be inserted into table1 when there are duplicate, but you can insert into another table.

    Begin
    Begin
    Insert into table1 values...
    Exception when DUP_VAL_ON_INDEX then
    Null;
    End;
    Insert into table2 values...

    End;

    I hope this works.

  • ORA-00001 violation, always on the 2nd insertion irrespective of the values

    Connected to:

    Database Oracle 12 c Enterprise Edition Release 12.1.0.2.0 - 64 bit Production

    With the options of partitioning, OLAP, advanced analytics and Real Application Testing

    I get a UK violation when I shouldn't be, and I'm stuck.  Where to look to figure out what is causing the problem?  Excerpts below.

    I insert only two records.  The second insertion always fails, regardless of the value of LOT_NO.

    I.E.

    • If the first insert is with LOT_NO 1234, the 2nd insertion with LOT_NO 1235 fails.
    • If the first insert is with LOT_NO 1235, the 2nd insertion with LOT_NO 1234 fails.


    truncate table ppr_lots;


    commit;


    Select * from ppr_lots;  -not return any records


    -alter table ppr_lots change the lot_uk disable constraint;


    insert into PPR_LOTS (lot_no, lot_id, lot_type_id, lot_status_type_id, cadastral_area_id, land_tenure_type_id, land_use_type_id, lot_demarcation_type_id, the plan_id argument, address_id, lot_building_id, pid, legal_issues_yn, lot_size, area_unit_type_id, gis_data_captured_yn, short_legal_dsc, long_legal_dsc, eff_from_dtm) eff_through_dtm remarks_dsc, section_locator_no, lot_guid, logically_deleted_yn, concurrency_check_ts, log_created_by_user_id, log_created_ts, log_updated_by_user_id, log_updated_ts)

    values (1234, 2, 5305, 5201, 23, 4700, 1802, 5000, 1, null, null, 1, 'n', 10, 201, 'Y', 'GAC002001234', null, null, null, null, null, null, 'n', to_timestamp (27 November 2015 09:05:42.517978', 'dd-mm-yyyy hh24:mi:ss.ff'), 1, to_timestamp (27 November 2015 09:05:42.517978', 'dd-mm-yyyy hh24:mi:ss.ff'), null, null);


    insert into PPR_LOTS (lot_no, lot_id, lot_type_id, lot_status_type_id, cadastral_area_id, land_tenure_type_id, land_use_type_id, lot_demarcation_type_id, the plan_id argument, address_id, lot_building_id, pid, legal_issues_yn, lot_size, area_unit_type_id, gis_data_captured_yn, short_legal_dsc, long_legal_dsc, eff_from_dtm) eff_through_dtm remarks_dsc, section_locator_no, lot_guid, logically_deleted_yn, concurrency_check_ts, log_created_by_user_id, log_created_ts, log_updated_by_user_id, log_updated_ts)

    values (1235, 3, 5304, 5201, 24, 4701, 1802, 5000, 2, null, null, 2, 'n', 104.5, 200, 'Y', 'CEC003001235', null, null, null, null, null, null, 'n', to_timestamp (27 November 2015 09:05:42.538275', 'dd-mm-yyyy hh24:mi:ss.ff'), 1, to_timestamp (27 November 2015 09:05:42.538275', 'dd-mm-yyyy hh24:mi:ss.ff'), null, null);


    Error report-

    SQL error: ORA-00001: unique constraint (LIS_PPR. LOT_UK) violated

    00001 00000 - "forced single (s.%s) violated."

    * Cause: An UPDATE or INSERT statement attempted to insert a duplicate key.

    For Trusted Oracle configured in DBMS MAC mode, you can see

    This message if there is an entry double at a different level.

    * Action: Either remove the single restriction or not to insert the key.

    BTW, if I turn off the UK, everything is fine.

    -Ken

    LOT_UK is defined simply as follows.

    ALTER TABLE PPR_LOTS

    ADD CONSTRAINT LOT_UK UNIQUE

    (

    LOT_NO

    )

    USING INDEX

    (

    CREATE A UNIQUE LOT_UK ON PPR_LOTS (LOT_NO CAD) INDEX

    LOGGING

    TABLESPACE USERS

    PCTFREE 10

    INITRANS 2

    STORAGE

    (

    65536 INITIAL

    NEXT 1048576

    MINEXTENTS 1

    MAXEXTENTS UNLIMITED

    DEFAULT USER_TABLES

    )

    NOPARALLEL

    )

    ENABLE;

    Found the problem.

    I thought that I had disabled triggers.  Turns out I didn't, and a defective trigger is overwhelming as LOT_NO.

    It's always the answer is simple.

    -Ken

  • Compare multiple columns and update a column based on the comparison

    Hi all

    I have to update the column STATUS of the slot structure of the table.

    Status should be 'P' if all the columns count are equal on the other should be "F".

    The value of the column can be "NA'. If the value is NA, then avoid this comparison column; compare only other 3 columns.

    My output should look like below.

    State of cnt1, cnt2 cnt3 ID cnt4

    1   4       4       4     4       P

    2   4       5       4     4       F

    3 4 4 NA 4 P

    NA 4 4 3 4

    I tried with the statemnt with BOX WHEN conditions and DECODE UPDATE, but could not succeed, can someone please help

    To do this, if you use my statement in response #11 box (Re: Re: comparison of multi-column and update a column based on the comparison of)

  • ORA-00001

    DEV 6I, db 10g, win 8,

    Hello

    I have a master-details form based on two blocks

    1 - purchase_order (order_id pk).

    2 - purchase_order_detail (fk order_id).

    I want to insert separate 'ITEM_ID' of the secondary table column values in a column in a third table, called 'STOCK. PRODUCT_ID.

    SO, I used this code:

    DECLARE
        CURSOR DIS_ITEMS_C IS
        SELECT DISTINCT ITEM_ID FROM ITEMS ;
       
        V_ITEM NUMBER ;
    BEGIN
        GO_BLOCK('PURCHASE_ORDER_DETAIL') ;
    FIRST_RECORD ;
    GO_ITEM('PURCHASE_ORDER_DETAIL.ITEM_ID') ;
    
    LOOP
        INSERT INTO ITEMS VALUES (:ITEM_ID) ;
        EXIT WHEN :SYSTEM.LAST_RECORD = 'TRUE';
        DOWN ;
    END LOOP  ;
    COMMIT ;
    
    OPEN DIS_ITEMS_C ;
    LOOP
        FETCH DIS_ITEMS_C INTO V_ITEM ;
        INSERT INTO STOCK (PRODUCT_ID) VALUES (V_ITEM) ;
        EXIT WHEN DIS_ITEMS_C%NOTFOUND ;
    END LOOP ;
    
    COMMIT ;
    END ;
    
    

    but I am facing unique ora-00001 "constraint violated", I don't know why?

    the main table inserts normally and retail as well, so the rest are the 'STOCK' AND 'ELEMENTS' TABLES,

    The 'ELEMENTS' has no. the CONSTRAINTS of TABLE and selects the "DISTINCT" from him I then insert them into the "STOCK"?

    I tried to do what the form do this manually with instructions insert and insert it normally, I don't see this error? you have an idea

    causes of this error is displayed?

    Thank you

    The mistake is that your

    WHEN THE OUTPUT DIS_ITEMS_C % NOTFOUND;

    is this bad place atheist. He should be immediately after EXTRACTION. With your code, the last record has been inserted twice.

  • SQL to update two columns in a TABLE2 from TABLE1

    I know it's a simple question for some of you, but I am new to SQLs, so please help...

    I have two tables, TABLE1 and TABLE2 as below, the two tables contains more records 50million then:
    SELECT * FROM TABLE1.
    &&&&&&&&&&&&&&&&&&&&&&&&&&&
    ID                        BUS_FID                WORKID                  STATIONID                  
    ---------------------- ---------------------- ---------------------- ---------------------- 
    28400000117234         245                    13461428.25           16520877.8             
    28400000117513         403                    13461428.25           16520877.8             
    28400000117533         423                    13461428.25           16520877.8             
    28400000117578         468                    13461428.25           16520877.8             
    28400000117582         472                    13461428.25           16520877.8             
    
    
    SELECT * FROM TABLE2.
    &&&&&&&&&&&&&&&&&&&&&&&&&&&
    BUS_FID                    ID                 TRPELID                RELPOS                 WORKID                 STATIONID                
    ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- 
    114                    28400000117658         28400000035396         23.225                                                               
    115                    28400000117659         28400000035396         23.225                                                               
    116                    28400000117660         28400000035396         23.225                                                               
    117                    28400000117661         28400000035396         23.225                                                               
    118                    28400000117662         28400000035396         23.225                                                               
    119                    28400000117663         28400000035396         23.225                                                               
    120                    28400000117664         28400000035396         23.225                                                               
    121                    28400000117665         28400000035396         23.225                                                               
    122                    28400000117666         28400000035396         23.225                                                               
    123                    28400000117667         28400000035396         23.225                                                               
    124                    28400000117668         28400000035396         23.225                                                               
    125                    28400000117669         28400000035396         23.225                                                               
    126                    28400000117670         28400000035396         23.225    
    Now, I tried to use the following SQL to update the columns ID of WORK & STATIONID in TABLE2 but failed. BUS_FID in the two tables have been UNIQUE indexed and they can be used as primary keys to join these two tables.
    UPDATE (
      SELECT  p.WORKID px,
              p.STATIONID py,
              p.BUS_FID pid,
              temp.WORKID tempx,
              temp.STATIONID tempy,
              temp.BUS_FID tempid
        FROM  TABLE1 temp, 
              TABLE2 p
        WHERE pid = tempid
    )
      SET px = tempx,
          py = tempy;
    
    COMMIT;
    with above code, Oracle gave following errors:
    SQL Error: ORA-00904: "TEMPID": invalid identifier
    00904. 00000 -  "%s: invalid identifier"
    Can someone help me fix it? Thank you ~ ~ ~
    BTW, both two tables contains documents more than 50 million. So, if you have a better SQL to perform the same task, please let me know!

    Appreciated your help in advance.

    Alias cannot be used in the query (sub-) where they are defined.

    Concerning

    Etbin

  • Addition of virtual column: ORA-12899: value too large for column

    I am using Oracle 11g, OS Win7, SQL Developer

    I'm trying to add the virtual column to my test table, but get ORA-12899: value too large for column error. Here are the details.
    Can someone help me in this?
    CREATE TABLE test_reg_exp
    (col1 VARCHAR2(100));
    
    INSERT INTO test_reg_exp (col1) VALUES ('ABCD_EFGH');
    INSERT INTO test_reg_exp (col1) VALUES ('ABCDE_ABC');
    INSERT INTO test_reg_exp (col1) VALUES ('WXYZ_ABCD');
    INSERT INTO test_reg_exp (col1) VALUES ('ABCDE_PQRS');
    INSERT INTO test_reg_exp (col1) VALUES ('ABCD_WXYZ');
    ALTER TABLE test_reg_exp
    ADD (col2 VARCHAR2(100) GENERATED ALWAYS AS (REGEXP_REPLACE (col1, '^ABCD[A-Z]*_')));
    
    SQL Error: ORA-12899: value too large for column "COL2" (actual: 100, maximum: 400)
    12899. 00000 -  "value too large for column %s (actual: %s, maximum: %s)"
    *Cause:    An attempt was made to insert or update a column with a value
               which is too wide for the width of the destination column.
               The name of the column is given, along with the actual width
               of the value, and the maximum allowed width of the column.
               Note that widths are reported in characters if character length
               semantics are in effect for the column, otherwise widths are
               reported in bytes.
    *Action:   Examine the SQL statement for correctness.  Check source
               and destination column data types.
               Either make the destination column wider, or use a subset
               of the source column (i.e. use substring).
    When I try to, I get the correct results:
    SELECT col1, (REGEXP_REPLACE (col1, '^ABCD[A-Z]*_'))
    FROM test_reg_exp;
    Thank you.

    Yes, RP, it works if you give col2 size > = 400.

    @Northwest - could you please test the same w/o having a clause of regex in col2?
    I have a doubt about using a REGULAR expression in this case Dynamics col.

    Refer to this (might help) - http://www.oracle-base.com/articles/11g/virtual-columns-11gr1.php
    Below excerpt from above link... see if that helps...
    >
    Notes and restrictions on the virtual columns include:

    The indexes defined on the virtual columns are equivalent to a function-based index.
    Virtual columns can be referenced in the updates and deletions WHERE clause, but they cannot be manipulated by DML.
    The tables containing virtual columns may still be eligible for result caching.
    Functions in expressions must be deterministic when the table is created, but can then be recompiled and non-deterministic without for as much invalidate the virtual column. In such cases, the following steps must be taken after the function is recompiled:
    Constraint on the virtual column must be disabled and re-enabled.
    On the virtual column indexes must be rebuilt.
    Materialized views that access the virtual column must be fully refreshed.
    The result cache must be flushed if the virtual column acceded to the request (s).
    Statistical table must be regathered.
    The virtual columns are not supported for the organized and external object in index, cluster or temporary tables.
    The expression used in the virtual column definition has the following restrictions:
    It cannot refer to another virtual column by name.
    It can refer to the columns defined in the same table.
    If it refers to a deterministic user-defined function, it cannot be used as a partitioning key column.
    The result of the expression must be a scalar value. It cannot return that an Oracle supplied the data type, a type defined by the user, LOB or LONG RAW.
    >

    Published by: Vanessa B on October 16, 2012 23:48

    Published by: Vanessa B on October 16, 2012 23:54

  • update to column values (false) in a copy of the same table with the correct values

    Database is 10gr 2 - had a situation last night where someone changed inadvertently values of column on a couple of hundred thousand records with an incorrect value first thing in the morning and never let me know later in the day. My undo retention was not large enough to create a copy of the table as it was 7 hours comes back with a "insert in table_2 select * from table_1 to timestamp...» "query, so I restored the backup previous nights to another machine and it picked up at 07:00 (just before the hour, he made the change), created a dblink since the production database and created a copy of the table of the restored database.

    My first thought was to simply update the table of production with the correct values of the correct copy, using something like this:


    Update mnt.workorders
    Set approvalstat = (select b.approvalstat
    mnt.workorders a, mnt.workorders_copy b
    where a.workordersoi = b.workordersoi)
    where exists (select *)
    mnt.workorders a, mnt.workorders_copy b
    where a.workordersoi = b.workordersoi)

    It wasn't the exact syntax, but you get the idea, I wanted to put the incorrect values in x columns in the tables of production with the correct values of the copy of the table of the restored backup. Anyway, it was (or seem to) works, but I look at the process through OEM it was estimated 100 + hours with full table scans, so I killed him. I found myself just inserting (copy) the lines added to the production since the table copy by doing a select statement of the production table where < col_with_datestamp > is > = 07:00, truncate the table of production, then re insert the rows from now to correct the copy.

    Do a post-mortem today, I replay the scenario on the copy that I restored, trying to figure out a cleaner, a quicker way to do it, if the need arise again. I went and randomly changed some values in a column number (called "comappstat") in a copy of the table of production, and then thought that I would try the following resets the values of the correct table:

    Update (select a.comappstat, b.comappstat
    mnt.workorders a, mnt.workorders_copy b
    where a.workordersoi = b.workordersoi - this is a PK column
    and a.comappstat! = b.comappstat)
    Set b.comappstat = a.comappstat

    Although I thought that the syntax is correct, I get an "ORA-00904: 'A'. '. ' COMAPPSTAT': invalid identifier ' to run this, I was trying to guess where the syntax was wrong here, then thought that perhaps having the subquery returns a single line would be cleaner and faster anyway, so I gave up on that and instead tried this:

    Update mnt.workorders_copy
    Set comappstat = (select distinct)
    a.comappstat
    mnt.workorders a, mnt.workorders_copy b
    where a.workordersoi = b.workordersoi
    and a.comappstat! = b.comappstat)
    where a.comappstat! = b.comappstat
    and a.workordersoi = b.workordersoi

    The subquery executed on its own returns a single value 9, which is the correct value of the column in the table of the prod, and I want to replace the incorrect a '12' (I've updated the copy to change the value of the column comappstat to 12 everywhere where it was 9) However when I run the query again I get this error :

    ERROR on line 8:
    ORA-00904: "B". "" WORKORDERSOI ": invalid identifier

    First of all, I don't see why the update statement does not work (it's probably obvious, but I'm not)

    Secondly, it is the best approach for updating a column (or columns) that are incorrect, with the columns in the same table which are correct, or is there a better way?

    I would sooner update the table rather than delete or truncate then re insert, as it was a trigger for insert/update I had to disable it on the notice re and truncate the table unusable a demand so I was re insert.

    Thank you

    Hello

    First of all, after post 79, you need to know how to format your code.

    Your last request reads as follows:

    UPDATE
      mnt.workorders_copy
    SET
      comappstat =
      (
        SELECT DISTINCT
          a.comappstat
        FROM
          mnt.workorders a
        , mnt.workorders_copy b
        WHERE
          a.workordersoi    = b.workordersoi
          AND a.comappstat != b.comappstat
      )
    WHERE
      a.comappstat      != b.comappstat
      AND a.workordersoi = b.workordersoi
    

    This will not work for several reasons:
    The sub query allows you to define a and b and outside the breakets you can't refer to a or b.
    There is no link between the mnt.workorders_copy and the the update and the request of void.

    If you do this you should have something like this:

    UPDATE
      mnt.workorders     A      -- THIS IS THE TABLE YOU WANT TO UPDATE
    SET
      A.comappstat =
      (
        SELECT
          B.comappstat
        FROM
          mnt.workorders_copy B   -- THIS IS THE TABLE WITH THE CORRECT (OLD) VALUES
        WHERE
          a.workordersoi    = b.workordersoi      -- THIS MUST BE THE KEY
          AND a.comappstat != b.comappstat
      )
    WHERE
      EXISTS
      (
        SELECT
          B.comappstat
        FROM
          mnt.workorders_copy B
        WHERE
          a.workordersoi    = b.workordersoi      -- THIS MUST BE THE KEY
          AND a.comappstat != b.comappstat
      )
    

    Speed is not so good that you run the query to sub for each row in mnt.workorders
    Note it is condition in where. You need other wise, you will update the unchanged to null values.

    I wouold do it like this:

    UPDATE
      (
        SELECT
          A.workordersoi
          ,A.comappstat
          ,B.comappstat           comappstat_OLD
    
        FROM
          mnt.workorders        A      -- THIS IS THE TABLE YOU WANT TO UPDATE
          ,mnt.workorders_copy  B      -- THIS IS THE TABLE WITH THE CORRECT (OLD) VALUES
    
        WHERE
          a.workordersoi    = b.workordersoi      -- THIS MUST BE THE KEY
          AND a.comappstat != b.comappstat
      ) C
    
    SET
      C.comappstat = comappstat_OLD
    ;
    

    This way you can test the subquery first and know exectly what will be updated.
    This was not a sub query that is executed for each line preformance should be better.

    Kind regards

    Peter

  • Insert first in the results of the empty table in ORA-00001: unique constraint

    Hi all
    We are running Oracle 10 g. I modified an Oracle stored procedure instead of using the cursor for loops or bulk collect for use INSERT with the SELECT statement. When I run this version, I get ORA-00001 on first insertion. ONCE the exception is thrown. I checked that the array is empty. I don't think the ORA-00001 is the real cause of the problem. I have a syntax problem I'm not aware of.

    Here's the script:
     
    CREATE OR REPLACE PROCEDURE SP_LOAD_TEST
     (p_rpt_month    varchar2)
    IS
    
    --===================================================
    -- define exceptions
    --===================================================
    
    DUP_VAL_ON_INDEX              EXCEPTION;
    
    --===================================================
    -- read the USER data
    --===================================================
    CURSOR c_get_USERS_TBL IS
    select DIV_CD,
             WRKR_USER_ID,
             RPT_MONTH 
    
    from  USERS_TBL
     WHERE RPT_MONTH = P_RPT_MONTH
     ORDER BY DIV_CD,
                    WRKR_USER_ID;
       
    --===================================================
    -- get the location name from the TLOC_DMSN table 
    --===================================================
    CURSOR c_wrkr_loc_name ( p_wrkr_user_id varchar2) IS
    select WRKR_LOC
    
    from  .TLOC_DMSN
     WHERE TRIM(wrkr_user_id) = TRIM(p_wrkr_user_id);
    
    --===================================================
    -- define a place holder for each row fetched from each cursor
    --===================================================
    c_get_USERS_TBL_row            c_get_USERS_TBL%ROWTYPE;
    
    --===================================================
    -- define variables
    --===================================================
    
    v_elapsed_time                  VARCHAR2(50);
    v_elapsed_time_hh             FLOAT;
    v_elapsed_time_mi             FLOAT;
    v_elapsed_time_ss             FLOAT;
    v_mod_ss                          FLOAT;
    v_mod_mi                          FLOAT;
    v_elapsed_time_minus_ss   FLOAT;
    
    v_div_cd1                            USERS_TBL.div_cd%TYPE;
    v_wrkr_user_id1                  USERS_TBL.wrkr_user_id%TYPE;
    v_rpt_month1                      USERS_TBL.wrkr_user_id%TYPE;                 
    
    v_div_cd2                           USERS_TBL.div_cd%TYPE;
    v_wrkr_user_id2                 USERS_TBL.wrkr_user_id%TYPE;
    V_rpt_month2                    USERS_TBL.rpt_month%TYPE;
    v_usage_hour                    FACT_TBL.usage_hour%TYPE;
    v_bytes_sent                      FACT_TBL.bytes_sent%TYPE;
    v_bytes_rcvd                      FACT_TBL.bytes_rcvd%TYPE;
    v_total_bytes                      FACT_TBL.total_bytes%TYPE;
    v_div_nm                           FACT_TBL.div_nm%TYPE;
    v_wrkr_loc                         .TLOC_DMSN.WRKR_LOC%TYPE;
    v_wrkr_dspl_nm                 FACT_TBL.wrkr_dspl_nm%TYPE;
    v_wrkr_ph                         FACT_TBL.wrkr_ph%TYPE; 
    v_url                                 FACT_TBL.url%TYPE;
    v_divcd_userid                  VARCHAR2(12);
    v_prev_divcd_userid          VARCHAR2(12);
    v_prev_div_cd                    USERS_TBL.div_cd%TYPE;
    v_prev_wrkr_user_id          FACT_TBL.wrkr_user_id%TYPE;
    v_date_id                            NUMBER(10);
    v_user                                CHAR(8);
    v_seq_id                          NUMBER;
    v_insert_counter               NUMBER;
    v_mmyyyy                        VARCHAR2(6);
    v_mm                              VARCHAR2(2);
    
    
    BEGIN
    
    
    
    --===================================================
    -- initialize variables
    --===================================================
    v_div_cd1 := ' ';
    v_prev_div_cd := ' ';
    v_wrkr_user_id1  := ' ';
    v_wrkr_loc := ' ';
    v_rpt_month1 := ' ';  
    v_divcd_userid := ' ';
    v_prev_divcd_userid := ' ';
    v_prev_wrkr_user_id := ' ';
    v_insert_counter := 0;
    v_seq_id := 0;
    v_mmyyyy := ' ';
    
    --===================================================
    -- build run month in mmyyyy format before writing to TLOAD_LOG table
    --===================================================
    CASE 
            WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'JANUARY'    THEN    v_mm := '01';
            WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'FEBRUARY'  THEN  v_mm := '02';
            WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'MARCH'       THEN    v_mm := '03';
            WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'APRIL'          THEN  v_mm := '04';
            WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'MAY'            THEN    v_mm := '05';
            WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'JUNE'           THEN  v_mm := '06';
            WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'JULY'            THEN    v_mm := '07';
            WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'AUGUST'       THEN  v_mm := '08';
            WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'SEPTEMBER'  THEN    v_mm := '09';
            WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'OCTOBER'      THEN  v_mm := '10';
            WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'NOVEMBER'     THEN    v_mm := '11';
            WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'DECEMBER'     THEN  v_mm := '12';                
     END CASE;
    
    v_mmyyyy := v_mm||substr(p_rpt_month,INSTRB(p_rpt_month,'-',1,1)+1,4);
    
    
    --===================================================
    -- get the name of user running this procedure
    --===================================================
    v_user  := ' ';
    select user into v_user from dual;
    
    
    --===================================================
    -- get date id for the current date
    --===================================================
    v_date_id        := 0;
    select date_id into v_date_id from  .dwtime5 where DWDATE = trunc(sysdate);
    
    
    --===================================================
    -- read each ROW IN the users TABLE
    --===================================================
    -- Open the cursor and intialize the active set
    Open c_get_USERS_TBL;
    
    -- Retrieve the first row, to setup for the WHILE loop
    FETCH c_get_USERS_TBL into c_get_USERS_TBL_row;
    
    -- Continue looping while there are more rows to fetch
    WHILE c_get_USERS_TBL%FOUND LOOP
         v_div_cd1 := c_get_USERS_TBL_row.div_cd;
         v_wrkr_user_id1 := c_get_USERS_TBL_row.wrkr_user_id;
         v_rpt_month1 := c_get_USERS_TBL_row.rpt_month;
           
        CASE
        WHEN v_div_cd1 <> v_prev_div_cd THEN
                  v_prev_divcd_userid := v_divcd_userid;
                  v_divcd_userid := v_div_cd1||v_wrkr_user_id1; 
        WHEN v_wrkr_user_id1 <> v_prev_wrkr_user_id THEN
                 v_prev_divcd_userid := v_prev_div_cd||v_prev_wrkr_user_id;
                 v_divcd_userid := v_div_cd1||v_wrkr_user_id1;
        END CASE;
        
        
        Open c_wrkr_loc_name(v_wrkr_user_id1);
         Fetch c_wrkr_loc_name INTO v_wrkr_loc;
         IF c_wrkr_loc_name%NOTFOUND THEN
             v_wrkr_loc := NULL;
         END IF;
        Close c_wrkr_loc_name ;   
     
      v_seq_id := 0;
       select SEQ_USER_ID.nextval into v_seq_id from dual; 
       
       INSERT INTO  DETAIL_TBL_TEST(DETAIL_PK_ID,  
                                    DIVCD_USERID,
                                    WRKR_USER_ID,
                                    WRKR_DSPL_NM,
                                    RPT_MONTH,
                                    USAGE_HOUR,
                                    DIV_CD,
                                    DIV_NM,
                                    WRKR_LOC,
                                    BYTES_RCVD,
                                    BYTES_SENT,
                                    TOTAL_BYTES,
                                    WRKR_PH,
                                    URL,
                                    CREATE_DT,
                                    CREATE_USER,
                                    CREATE_PGM,
                                    UPDATE_DT,
                                    UPDATE_USER,
                                    UPDATE_PGM )
                             SELECT v_seq_id,
                                    v_divcd_userid,
                                    wrkr_user_id,
                                    wrkr_dspl_nm,
                                    rpt_month,
                                    usage_hour,
                                    div_cd,
                                    div_nm,
                                    v_wrkr_loc,
                                    bytes_rcvd,
                                    bytes_sent,
                                    total_bytes,
                                    wrkr_ph,
                                    url,
                                    SYSDATE,
                                    v_user,
                                   'SP_LOAD_DETAIL_TBL',
                                    SYSDATE,
                                    v_user,
                                   'SP_LOAD_DETAIL_TBL'
                              FROM  FACT_TBL, 
                                    DUAL                                                              
                              WHERE DIV_CD = v_div_cd1
                                AND TRIM(wrkr_user_id) = TRIM(v_wrkr_user_id1)                    
                                AND rpt_month = v_rpt_month1
                              ORDER BY DIV_CD,
                                       WRKR_USER_ID; 
    
         v_insert_counter := v_insert_counter + 1;
         IF v_insert_counter >= 500 THEN
        -- commit changes
            COMMIT;
            v_insert_counter := 0;
         END IF;
         
       FETCH c_get_USERS_TBL into c_get_USERS_TBL_row;
    END LOOP;
    
    Close c_get_USERS_TBL;
    
    
    --===================================================
    -- final commit
    --===================================================
    COMMIT;
    
    
    
    EXCEPTION
    WHEN DUP_VAL_ON_INDEX THEN
             DBMS_OUTPUT.PUT_LINE('Attempting to insert a row that already exists!!!');
    WHEN OTHERS THEN RAISE;
    --END;
     
    
    
    --===================================================
    -- procedure ended.
    --===================================================
    
    END;
    Thank you for your help,


    Seyed

    Hello

    I guess that the error you receive notice when you were in that sequence was ORA-02287: unauthorized by sequence number. This is because you had the ORDER BY clause in there. If you get rid of it, you can just use the sequence number in the insert without the need first to select it...

    With ORDER BY

    
    XXXX> insert
      2  into
      3      dt_t1
      4  SELECT
      5          dt_seq.NEXTVAL,
      6          SYSDATE
      7  FROM
      8      dual
      9  CONNECT BY LEVEL
     10      <=10
     11  ORDER BY
     12          1
     13  /
            dt_seq.NEXTVAL,
                   *
    ERROR at line 5:
    ORA-02287: sequence number not allowed here
    

    No ORDER OF

    XXXX> insert
      2  into
      3      dt_t1
      4  SELECT
      5          dt_seq.NEXTVAL,
      6          SYSDATE
      7  FROM
      8      dual
      9  CONNECT BY LEVEL
     10      <=10
     11  /
    
    10 rows created.
    

    Of course, I guess you want a new id for each row, as seems to be the name of the primary key column.

    HTH

    David

    Published by: Bravid on December 19, 2011 16:07

    Published by: Bravid on December 19, 2011 16:08

  • ORA-00001: unique constraint (GML. PO_ORDR_DTL_U1)

    Hello

    I have this error after I start the synchronization of joint purchase OPM. Help, please.


    Thank you very much

    Kind regards
    peopsquik
    $ oerr ora 00001
    00001, 00000, "unique constraint (%s.%s) violated"
    // *Cause: An UPDATE or INSERT statement attempted to insert a duplicate key.
    //         For Trusted Oracle configured in DBMS MAC mode, you may see
    //         this message if a duplicate entry exists at a different level.
    // *Action: Either remove the unique restriction or do not insert the key.
    $
    
  • InDesign, Import XML, switching to and from possible design multi-column?

    I have a question that may or may not require a script solution. I have a data source external generation text referenced XML file that I will not flow into a book. Normally, the book is a two-column layout, but there are illustrations (and sometimes pieces of explanatory text) which should cover both columns. I've built examples of use of reflow smart text for simple and updated column in multi-column page layout. Using one of these with the active smart text reflow works beautifully.

    Ideally, I would like to a XML tag that says "start spanning two columns now", inserts a large illustration (could also be a piece of text however) and another that says "return to normal 2 columns. I did a number of experiments (all unsuccessful) I can't seem to get a working solution. I really like the XML import, but if this is not possible, I'm willing to look at other approaches.

    Has anyone had a similar problem?

    As a gross illustration...

    Lorem ipsum dolor sit amet, adipiscing elit computer.

    CRAs quis ligula EST. SED dictum erat an EST porta in

    dignissim nisl ultrices. In and convallis elit. Curabitur pretium

    < HYPOTHETICAL_SPAN > magna EU ornare, tellus faucibus total, placerat vitae arcu fringilla

    Nulla non sapien ligula. Vestibule vel mauris and pellentesque erat

    Nunc. Vestibule total ac nulla ornare EU ultricies sapien tincidunt < / HYPOTHETICAL_SPAN >

    so. In metus, id erat auctor gravida dignissim

    eget dignissim erat dictum nisl eleifend porta an EST in

    Harold

    Just to be clear, when you say:

    I have a data source external generation text referenced XML file that I will not flow into a book.

    you mean import XML, not the import of text containing the tag of InDesign, correct?

    Ideally, I would like to a XML tag that says "start spanning two columns now", inserts a large illustration (could also be a piece of text however) and another that says "return to normal 2 columns. I did a number of experiments (all unsuccessful) I can't seem to get a working solution. I really like the XML import, but if this is not possible, I'm willing to look at other approaches.

    Can't you just a tag that maps to a paragraph style that allows to span columns?

  • When Fire Fox support (again!) for display of multi column (and navagable) Favorites (bookmarks)?

    I always use rev 31. This is the last version that is compatible with the add-in on, "Multicolumn Bookmarks 1.5', I have several brands of books collected over the years and the single column format is frustrating and not helpful."

    Asked to provide a current version, which is compatible with "MultiColumn Bookmarks 1.5' Fire Fox, or provide a favorite navigable multi-column as option display in a near future program revision Fire Fox.»

    Sincerely,

    Pierre Arnold

    Sorry, to complete the thought:

    (1) install Stylish from the Mozilla Add-ons site

    https://addons.Mozilla.org/firefox/addon/stylish/

    (2) then back to the user page of style to get the style (the button should be green instead of blue right here)

    https://userstyles.org/styles/119797/bookmarks-menu-in-multiple-columns

  • How to customize the scroll and symbols bars in a multi column list box

    Hello

    I have recently been design FP and have gotten to a scroll bar in a multi column list box.

    How can I change the decals and colors of the scroll bar as I can't seem to change or select all components of it within the control editor.

    I would change the arrow buttons and arrow the cursor with a custom sticker and have a solid track. In adition to that, I would like to change some of the symbols or add my own custom in the existing list.

    Is this possible to do?

    carbon32 wrote:

    Hello

    I have recently been design FP and have gotten to a scroll bar in a multi column list box.

    How can I change the decals and colors of the scroll bar as I can't seem to change or select all components of it within the control editor.

    I would change the arrow buttons and arrow the cursor with a custom sticker and have a solid track. In adition to that, I would like to change some of the symbols or add my own custom in the existing list.

    Is this possible to do?

    I don't think that you can customize parts of the scollbars.

    Here how to add symbols to a listbox control. The new index of symbols must last for 41 as the indices of standard symbols are included between 1 and 40. The size of your custom symbol must be 16 x 16.

    Ben64

  • By programming the auto scroll value multi-column list boxes?

    I have a Multi column list box control that I put off (for indication only) which is used to show the progress.

    When a profile is loaded in the list box if this profile causes the scroll bar to become active it's obviously disabled and if the user cannot scroll

    That the control is disabled, the scroll bar is also disabled is there anyway that I can programmatically on the AutoScroll scroll bar?

    Hello

    You can use the property of the listbox multicoum ' cell upper left Visible.

    If your listbox multicoloum is disabled you can put vertical cursors or something on the front and give the value of the cursor to the line/Coloum (vertical scrollbar) and Coloum for the horizontal scroll bar to the "cell upper left Visible.

    Hope this helps

    Concerning

    David

Maybe you are looking for