Error in update statement

Hello

I wrote an update statement as below:

Update (select a.col1, a.col2 from table1, table2 b
where a.pk1 = b.pk1 and
a.PK2 = b.pk2 and
a.PK3 = b.pk3 and
a.PK4 in)
Select a.pk4 from table1, table2 b
where a.pk1 = b.pk1 and
a.PK2 = b.pk2 and
a.PK3 = b.pk3
less
Select pk4 from table2
)
) s
Set s.col1 = 'I ',.
s.col2 = null;

Table1 is a base table and the primary key for this table is made of CP1, CP2, pk3, pk4.
Table 2 is a temporary table with no primary key column.
My goal is to update the columns of table 1.
I'm using the code above in a procedure and this error:
ORA-01779: cannot modify a column that is mapped to a table not preserved key
I'm sure that the error has to with the foregoing update statement.

I have read a few articles and realize that Oracle can understand what table to update in this scenario. But I am at a loss to rewrite this query.
Please advice, how I can rewrite this query.

Thank you!

Hello

Instead of updating a view online, update your actual table, like this:

UPDATE   table1
SET      col1     = 'I'
,      col2     = NULL
WHERE      (col1, col2, col3, col4) IN
      (
          SELECT  ...
          FROM    table1
          JOIN    table2  ...
      )
;

I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
If you ask on a DML statement, such as UPDATE, the sample data will be the content of the or the tables before the DML, and the results will be the State of the or the tables changed when it's all over.
Explain, using specific examples, how you get these results from these data.
Always tell what version of Oracle you are using.
See the FAQ forum {message identifier: = 9360002}

Tags: Database

Similar Questions

  • Syntax error in update statement

    Oracle 10 g database version

    Hi all

    I'm number one update command but I get the error message. I appreciate if someone help out me. Thank you

    Examples of data

    UPDATE of res rest, vic vict

    SET rest.paid_amt = 0,

    Rest.accumulated_amt = 0

    RES WHERE. V_ID = vic. V_ID

    AND vic.case_id = 111;

    Error

    SQL error: ORA-00971: lack of SET keyword

    00971 00000 - "lack the SET keyword.

    * Cause:

    * Action:

    You can also use join update, if the join is key to keeping on the table whose columns are updated, which in your case, remains. V_ID must be a foreign key pointing to vict. V_ID, because the rest columns is updated.

    UPDATE (select res.paid_amt, res.accumulated_amt, res.V_ID, vic.V_ID, vic.case_id
              from rest res, vict vic
             where res.V_ID=vic.V_ID
           )
       SET paid_amt = 0,
           accumulated_amt = 0
     WHERE case_id = 111;
    
  • Logging of DML errors for Update statement

    Hello

    I am facing a problem regarding recording with instructions to update DML errors.

    Oracle: 10.2

    I am running after update DML:
    BEGIN 
    
    UPDATE 
    table_1  a
    SET a.Exp_DATE =a.EFF_DATE 
    WHERE  a.col_a1 != (SELECT b.colb1
                         FROM table_2  b
                         WHERE  a.msisdn =b.msisdn )
    LOG ERRORS INTO table_1_ERR REJECT LIMIT UNLIMITED;                         
                             
                             
                             
    END ;    
    I expect that "ORA-01427: einreihig subquery returns several lines" would be entered in the table of error LOG "table_1_err".
    but instead, I got error lance and entire dml has been restored.

    Please let me know if this exception is not captured by the logging of DML errors.

    Thank you
    Abhishek

    Abhi.k wrote:
    I expect that "ORA-01427: einreihig subquery returns several lines" would be entered in the table of error LOG "table_1_err".
    but instead, I got error lance and entire dml has been restored.

    Logging error tables are there to capture violations of constraints. What you have is a coding error. So no, he will not be captured.

  • ERRORS in the LOG of the capture of 2291 on UPDATE statement errors

    We are running Oracle Database 10 g Enterprise Edition Release 10.2.0.4.0 - Production 64 - bit with the options of partitioning, OLAP, Data Mining and Real Application Testing

    We used often successfully the clause of the logging of errors during the execution of the batch to the database inserts. However, we now have a situation where an UPDATE statement is default and make back up when it encounters a referential constraint foreign key [ORA-02291]. It registers with success of coercion errors [ORA-02290] Check. Foreign keys are not carried over, and they have nothing to do with unique constraints or indexes on the table that is the target of the UPDATE statement. The logging of errors table was created using the DBMS_ERRLOG package. We have created to make sure that we introduced column format errors. The same problem occurs. The UPDATE statement tries to update about 12000 lines. Any help in understanding this problem would be appreciated.

    Here's the error statement
    ORA-02291: integrity constraint (OIFS. FRAME_FK07) violated - key parent not found

    Here is the statement of the problem and its PLSQL block surrounding:

    BEGIN < < update_records > >
    UPDATE image f
    SET (company_name,
    address1_line,
    address2_line,
    address1_city,
    address1_state,
    address1_zip,
    contact1_name,
    contact1_phone_number,
    update_date,
    update_user,
    -Comments,
    facility_name,
    facility_type,
    doing_business_as,
    contact1_phone_ext,
    contact1_fax,
    contact1_email,
    contact2_name,
    contact2_phone_number,
    contact2_phone_ext,
    contact2_fax,
    contact2_email,
    source_survey,
    source_status,
    address2_city,
    address2_state,
    address2_zip,
    facility_location_number,
    attention_line,
    company_official,
    facility_irs_code
    ) =
    (SELECT company_name,
    address1_line,
    address2_line,
    address1_city,
    address1_state,
    address1_zip,
    contact1_name,
    contact1_phone_number,
    SYSDATE,
    user_in,
    facility_name,
    facility_type,
    doing_business_as,
    contact1_phone_ext,
    contact1_fax,
    contact1_email,
    contact2_name,
    contact2_phone_number,
    contact2_phone_ext,
    contact2_fax,
    contact2_email,
    source_survey,
    source_status,
    address2_city,
    address2_state,
    address2_zip,
    facility_location_number,
    attention_line,
    company_official,
    facility_irs_code
    Oifs.respondent r
    WHERE r.cin = f.cin
    )
    WHERE f.cin IN
    (SELECT cin
    Of
    (SELECT cin,
    company_name,
    address1_line,
    address2_line,
    address1_city,
    address1_state,
    address1_zip,
    contact1_name,
    contact1_phone_number,
    facility_name,
    facility_type,
    doing_business_as,
    contact1_phone_ext,
    contact1_fax,
    contact1_email,
    contact2_name,
    contact2_phone_number,
    contact2_phone_ext,
    contact2_fax,
    contact2_email,
    source_survey,
    source_status,
    address2_city,
    address2_state,
    address2_zip,
    facility_location_number,
    attention_line,
    company_official,
    facility_irs_code
    OF oifs.respondent
    LESS
    SELECT cin,
    company_name,
    address1_line,
    address2_line,
    address1_city,
    address1_state,
    address1_zip,
    contact1_name,
    contact1_phone_number,
    facility_name,
    facility_type,
    doing_business_as,
    contact1_phone_ext,
    contact1_fax,
    contact1_email,
    contact2_name,
    contact2_phone_number,
    contact2_phone_ext,
    contact2_fax,
    contact2_email,
    source_survey,
    source_status,
    address2_city,
    address2_state,
    address2_zip,
    facility_location_number,
    attention_line,
    company_official,
    facility_irs_code
    OF oifs.frame
    )
    )
    ERROR IN oifs.frame_load_errors LOG
    (job_num |) ' ' || TO_CHAR (SYSDATE, 'YYYYMMDD HH24:MI:SS'). 'update')
    REJECT LIMIT UNLIMITED;
    EXCEPTION
    WHILE OTHERS THEN
    ohub.err_pkg.record_and_continue (' msg_in = > ' problem to update the lines of FIELD ');
    LIFT;
    END update_records;

    I think and that's just a wild guess, is that your table has a trigger... or an associated view has a relaxing place.

  • Handful of division by zero error in the update statement

    My dear welcom

    How and I overcame this problem in my update statement
    for exwmple, it comes to the table
    CREATE TABLE TEST4
    (
    A1 NUMBER,
    A2 NUMBER OF,
    A3 NUMBER
    )

    Insert into TEST4 a1, a2, values (15.3);
    Insert into TEST4 a1, a2, values (9.3);
    Insert into TEST4 a1, a2, values (12.0);

    commit;


    now, I'm trying to update the column a3 in Division a1/12

    Start
    update set of test4
    A3 = a1/a2;
    exception
    WHEN ZERO_DIVIDE THEN
    update set of test4
    A3 = 0;
    end;
    After you validate THE VALUE of A3 = 0;

    Can any onle help me


    I use oracle 10g R2
    Thanks in advance
    SQL> select  *
      2    from  test4
      3  /
    
            A1         A2         A3
    ---------- ---------- ----------
            15          3
             9          3
            12          0
    
    SQL> update  test4
      2     set  a3 = case a2 when 0 then 0 else a1 / a2 end
      3  /
    
    3 rows updated.
    
    SQL> select  *
      2    from  test4
      3  /
    
            A1         A2         A3
    ---------- ---------- ----------
            15          3          5
             9          3          3
            12          0          0
    
    SQL> 
    

    SY.

  • I install 4 cod error 80244022 updates

    I install 4 cod error 80244022 updates

    0 x 80244022 WU_E_PT_HTTP_STATUS_SERVICE_UNAVAIL even State HTTP 503 - service is temporarily overloaded.

    Try tomorrow

  • When I turn on the computer of mymy and it gives me request error indicating that "the required data was not put into memory due to an error of e state / of"0xc000009c".»

    Original title: IO error

    OK so I turn on my computer and it gives me request error indicating that "the required data was not put into memory due to an error of e state / of"0xc000009c".»

    I run an xp windows 2003-04. My computer does not start completely and if I click on debug or put end to the program there just restarts the computer. How can I solve this problem? and is it possible that I can update my software?

    You say that you can not even start in Safe Mode, so method 1 will not help you, method 2 will not help you and 3 method will not help you.

    I start in the XP Recovery Console and first run a chkdsk/r on the afflicted system, but since we don't know anything about your system, we will need more information.

    It is a shame that in the forums MS Answers, the first response to a new question is (or should be) a request for more information...  You are 5 days in your problem, and so for him it seems that you are not getting anywhere.  If the thread goes inactive for more than a few days, the response of the Microsoft Support Engineer will become the 'response' automatically because it has links to the KB articles.

    Since the Microsoft Answers forum does not have any kind of information system request when a new question is asked, we know absolutely nothing about your system.  Not knowing the basic information a problem prolongs the frustration and the agony of these issues.

    Thank you MS Answers, allowing the resolution of simple problems as frustrating and a lot of time as possible.

    Provide information on your system, the better you can:

    What is your system brand and model?

    What is your Version of XP and the Service Pack?

    Your system have IDE or SATA disks?

    Describe your current antivirus and software anti malware situation: McAfee, Symantec, Norton, Spybot, AVG, Avira!, MSE, Panda, Trend Micro, CA, Defender, ZoneAlarm, PC Tools, Comodo, etc..

    The question was preceded by a loss of power, aborted reboot or abnormal termination?  (this includes the plug pulling, buttons power, remove the battery, etc.)

    The afflicted system has a working CD/DVD (internal or external) drive?

    You have a genuine XP installation CD bootable, which is the same Service as your installed Service Pack (this is not the same as any recovery CD provided with your system)?

    If the system works, what do you think might have changed since the last time it did not work properly?

  • SQLite Update statement

    I have a database in my application, and part of it (obviously) will require the user to update the database with the current information.

    There are 24 columns of the table, and I have my update function works almost 100%, except that there are two drop downs, and when the user updates the record individual everything that is selected in the fall of two downs, is applied to all records.

    My update statement is like this:

    var statement:SQLStatement = new SQLStatement();statement.sqlConnection = connection;statement.text = "UPDATE TABLE SET " +      "OneFish=?, " +       "TwoFish=?, " +       "RedFish=?, " +       "BlueFish=?, " +          // CONTINUES AS TEXT INPUTS DOWN TO       "DropDown1=?, " +     "DropDown2=?, " +          // FEW MORE TEXT INPUTS THEN                "WHERE RECORD_ID=?";       statement.parameters[0] = OneFish.text;       statement.parameters[1] = TwoFish.text;       statement.parameters[2] = RedFish.text;       statement.parameters[3] = BlueFish.text;          // CONTINUES AS TEXT INPUTS DOWN TO       statement.parameters[17] = DropDown1.selectedItem;        statement.parameters[18] = DropDown2.selectedItem;          // FEW MORE TEXT INPUTS THEN        statement.parameters[23] =                FishOption.selectedItem.RECORD_ID;                statement.addEventListener(SQLEvent.RESULT, updateWorked);                statement.addEventListener(SQLErrorEvent.ERROR, updateFailed);                statement.execute();
    

    ALL updates day very well and shown to the a specific RECORD_ID. However, the decline in the bottom change overall.

    This does not happen on my service of "addFish". Someone out there have any ideas why this is?

    Update: It isn't my SQL. If I close the application and then go back, the changes show correctly. The drop down menus are simply not refreshing properly after the update of the database.

    J.Rab!

    I literally JUST thought out and sat next to the woman to rejoice with the laptop on my lap! Then the BlackBerry made his small notification and I said out loud, "oh look, it's probably somebody tell me what I did wrong before that I could update!

    Had dinner and a record label with a look at it to understand.

    To display the resulting data & update fields, I was setting the command prompt from the drop down menus! I went my output and changed function use the selectedItem and success!

    I also forgot to include a refreshTheDatabase(); at the end of my updateFunction() function call;

    I hit a brick wall with this for several hours this afternoon and I can't believe it was that simple! I should have got up and walked away earlier!

  • Error Windows Update Database that can be 0 x 80070490

    Original title:

    Update of Windows, Java and some problems

    Hello

    My Java and Windows 8 will not get automatically updated.  When I go to all the work this symbol [[[comes in. I have updated Java, nevertheless a message shows to update when I put a cursor over any word of an open page of the internet. I have troubleshooted illustrated message"

    Error Windows Update Database that can be 0 x 80070490

    Miniport Wan (Network Monitor) # 2 has a driver problem

    Windows Update configured to never install drivers '  

    Some keys on the keyboard do not work.  How can I fix these problems?

    Hello Arif,

    Thanks for posting your query on Microsoft Community forum.

    If you receive Windows Update error 80070490, it means that a file (CBS Manifest) that is needed to install updates is corrupt.

    Try it out below mentioned methods and see if it helps.

    Method 1

    Try to follow the steps mentioned in the article below.

    Windows Update, error 0 x 80070490

    Method 2

    Try to run the Troubleshooting Windows Update tool.

    This utility is used to and check if the network card and Windows Update services are running properly.

    Problems with installing updates

    Try other steps mentioned in this article if the issue that you are facing is mentioned in one of the mentioned option it.

    Method 3

    If the problem persists I suggest to reset the Windows Update components and for this, try to run the fixit described in the following article. If you already tried the fixit even before that I ask of you rerun the fixit.

     

    How to reset the Windows Update components?

    http://support.Microsoft.com/kb/971058/en-us#LetMeFixItMyselfAlways

    Hope it would help. If problem persists always post back with the current state of your computer and the result of the proposed suggestion, we will be happy to help you.

    Thank you.

  • Update statement

    Hi friends,

    Need your help with an update statement.

    Update t set t.icode int_tab =.

    (select ac.icode in the ac_tab ac, ed edition

    where ac.current_code = ed.unit)

    where ed.process_no = t.action_no);

    where ed.process_no = t.action_no

    *

    ERROR on line 4:

    ORA-00904: "ED". "" PROCESS_NO ": invalid identifier

    Basically, we need to update int_tab.icode with ac_tab.icode where ac_tab.current_code = edition.unit

    Thank you very much

    I suggest you MERGE. Inside () I call "source" can be controlled carefully. And then you can easily do the UPDATE

    No funny Executive plans and if he SELECT jobs, UPDATE works as well.

    MERGE into the target int_tab

    USING (SELECT t.rowid, rid, ac.icode,

    Of ac_tab ac

    Join IN-HOUSE ed Edition

    ON ac.current_code = ed.unit

    Join IN-HOUSE int_tab t

    ON ed.process_no = t.action_no

    WHERE t.icode! = ac.icode

    and t.icode is not null) source

    on (target.rowid = source.id)

    WHEN MATCHED

    THEN UPDATE set target.icode = source.icode;

  • Update statement with multiple joints

    Hello

    I use Oracle 12 c and here my Question:

    /*

    ledgerstb is an Oracle the ITO (TransNo column is the primary key)

    vledgerstb_gtt is a global temporary Table

    vledgervc_gtt is a global temporary Table

    */

    UPDATE

    (, SELECT ledgerstb. TransNoVC AS TransNoVC_Old,

    vledgervc_gtt.transnovc AS TransNoVC_New

    OF ledgerstb

    INNER JOIN vledgerstb_gtt ON ledgerstb. TransNo = vledgerstb_gtt.transnostb

    INNER JOIN vledgervc_gtt ON ledgerstb. STBNo = vledgervc_gtt. STBNo

    ) T

    SET T.TransNoVC_OLD = T.TransNoVC_NEW;

    This update statement gives the following error message:

    Error report-

    ORA-01779: cannot modify a column that is mapped to a table not preserved key

    ORA-06512: at "RELYC. STBPKG', line 597

    ORA-06512: at line 201 level

    01779 00000 - 'impossible to change a column that is mapped to a non-preserved table at key'

    * Cause: An attempt was made to insert or update columns in a join finds out who

    map to a table not kept the key.

    * Action: Change the directly underlying base tables.

    For your reference, the following result internal instruction select (in blue color police) give;

    TransNo: 1 STBNo: VAAAABM315711131

    TransNo: STBNo 2: VAAAABM315711214

    TransNo: STBNo 3: VAAAABM315711262

    TransNo: STBNo 4: VAAAABM316410986

    Please suggest if I'm doing something wrong or it is not possible to update the table like that.

    (I know that I can use ForAll Update statement, but I do not want to use Collections here.)

    Thank you carine, finally I found my answer,

    the update query requires that each record that will be updated should be updated only once. so if I do join 1<->1 it updates successfully.

    Thanks to all who contributed, or at least tried. Thanks again.

  • GoldenGate reproducing not UPDATE statement

    Hi all

    I have this problem with my process of goldengate. I created processes extract and replicat process, I was loading initial thru expdp and impdp. All right (insert, delete) until execution of the update statement. He added my replicat process.

    Here is the error:

    2013-07-22 17:05:16 WARNING OGG-01431 abandoned grouped transaction on "OWNER. Table_name', mapping error.

    2013-07-22 17:05:16 WARNING OGG-01003 repositioning of rba in seqno 162688 0.

    2013-07-22 17:05:16 WARNING mapping OGG-01151 error to the OWNER. Table_name to the OWNER. TABLE_NAME.

    2013-07-22 17:05:16 WARNING OGG-01003 repositioning of rba in seqno 162688 0.

    The table does not have the keys to the identifier.

    How should I solve my problem?

    Thank you very much in advance for gurus.

    When you get a mapping error, there will be more details on the issue in the discard file. Take a look here for the error.

    But in general, updates, you must make sure that you did a TRANDATA ADD on the side of the source in order to have the columns, you must apply the operation target and on target, if you do not have a PK or the user interface, you must specify KEYCOLS in the card then Replicat knows which columns to use to format the WHERE clause.

    Let us know what error is in your file throw, and we can go from there.

    Best regards

    Mary

  • problem by making an update statement

    Hi all
    I should write an update statement
    These tables: country: name, code, population, nextyearr_population...
    nextyear_population is empty, first, I should get population_growth of the picture of the population, then compute the year population next according to population and population_growth corrent

    population: country (in fact no code name of the country), population_growth,...

    So I wrote and I got this error
    Error starting at line 1 in command:
    
    update country c
    set c.nextyear_population=(c.population+ ((c.population*(select pop.population_growth from population pop join country co on co.code=pop.code))/100)
    )
    where country.code=population.country
    Error at Command Line:4 Column:20
    Error report:
    SQL Error: ORA-00904: "POPULATION"."COUNTRY": invalid identifier
    00904. 00000 -  "%s: invalid identifier"
    *Cause:    
    *Action:
    --------------------------------------------------------
    --  File created - Wednesday-May-15-2013   
    --------------------------------------------------------
    --------------------------------------------------------
    --  DDL for Table COUNTRY
    --------------------------------------------------------
    
      CREATE TABLE "intern"."COUNTRY" ("NAME" VARCHAR2(40), "CODE" CHAR(2), "CAPITAL" VARCHAR2(40), "PROVINCE" VARCHAR2(40), "POPULATION" NUMBER, "AREA" NUMBER, "NEXTYEAR_POPULATION" NUMBER) 
     
    
       COMMENT ON COLUMN "intern"."COUNTRY"."NAME" IS 'the country name'
     
       COMMENT ON COLUMN "intern"."COUNTRY"."CODE" IS 'the internet country code (two letters)'
     
       COMMENT ON COLUMN "intern"."COUNTRY"."CAPITAL" IS 'the name of the capital'
     
       COMMENT ON COLUMN "intern"."COUNTRY"."PROVINCE" IS 'the province where the capital belongs to'
     
       COMMENT ON COLUMN "intern"."COUNTRY"."POPULATION" IS 'the population number'
     
       COMMENT ON COLUMN "intern"."COUNTRY"."AREA" IS 'the total area'
     
       COMMENT ON TABLE "intern"."COUNTRY"  IS 'the countries of the world with some data'
    REM INSERTING into intern.COUNTRY
    SET DEFINE OFF;
    Insert into intern.COUNTRY (NAME,CODE,CAPITAL,PROVINCE,POPULATION,AREA,NEXTYEAR_POPULATION) values ('Andorra','ad','Andorra la Vella','Andorra la Vella',69865,468,null);
    Insert into intern.COUNTRY (NAME,CODE,CAPITAL,PROVINCE,POPULATION,AREA,NEXTYEAR_POPULATION) values ('United Arab Emirates','ae','Abu Dhabi','Abu Dhabi',2523915,82880,null);
    Insert into intern.COUNTRY (NAME,CODE,CAPITAL,PROVINCE,POPULATION,AREA,NEXTYEAR_POPULATION) values ('Afghanistan','af','Kabul','Kabul',28513677,647500,null);
    
    
    
    
    --------------------------------------------------------
    --  File created - Wednesday-May-15-2013   
    --------------------------------------------------------
    --------------------------------------------------------
    --  DDL for Table POPULATION
    --------------------------------------------------------
    
      CREATE TABLE "intern"."POPULATION" ("COUNTRY" CHAR(2), "POPULATION_GROWTH" NUMBER, "INFANT_MORTALITY" NUMBER) 
     
    
       COMMENT ON COLUMN "intern"."POPULATION"."COUNTRY" IS 'the country code'
     
       COMMENT ON COLUMN "intern"."POPULATION"."POPULATION_GROWTH" IS 'population growth rate (percentage, per annum)'
     
       COMMENT ON COLUMN "intern"."POPULATION"."INFANT_MORTALITY" IS 'infant mortality (per thousand)'
     
       COMMENT ON TABLE "intern"."POPULATION"  IS 'information about the population of the countries'
    REM INSERTING into intern.POPULATION
    SET DEFINE OFF;
    Insert into intern.POPULATION (COUNTRY,POPULATION_GROWTH,INFANT_MORTALITY) values ('ad',0.95,4.05);
    Insert into intern.POPULATION (COUNTRY,POPULATION_GROWTH,INFANT_MORTALITY) values ('ae',1.54,14.51);
    Insert into intern.POPULATION (COUNTRY,POPULATION_GROWTH,INFANT_MORTALITY) values ('af',4.77,163.07);
    Thanks in advance

    I'm using oracle11g and ubuntu 12


    best, david
    update  country c
       set  nextyear_population = population + population * (select pop.population_growth from population pop where c.code = pop.country) / 100
     where  code in (
                     select  country
                       from  population
                    )
    /
    

    SY.

  • Merger of statement: with several Update statement.

    Hello

    I'm trying under the merge statement. However to get the error "not correctly completed 0ra-00933 sql command.

    In fact, my join conditions are the same, but I wanted to update the different columns based on the different places where clause in the update statement.

    for example.

    FUSION
    IN abc3 tgt
    With the HELP of abc CBC
    WE (src.cust = tgt.cust)
    WHEN MATCHED
    THEN
    UPDATE
    SET tgt.sales = src.sales
    where tgt.cust = 'Cust3'
    UPDATE
    SET tgt.sales1 = src.sales
    where tgt.cust = 'Cust2';

    Please let me know if there is no work around for this.

    Hi, pm

    You can try this please.

    MERGE
     INTO ABC3 TGT
     USING ABC SRC
      ON (src.cust = tgt.cust)
    WHEN MATCHED THEN
    UPDATE SET TGT.SALES = DECODE(TGT.CUST,'Cust3',SRC.SALES,TGT.SALES),
               TGT.SALES1 = DECODE(TGT.CUST,'Cust2',SRC.SALES,TGT.SALES1)
    WHERE TGT.CUST='Cust3' OR tgt.cust='Cust2';
    
  • Decode function in the Update statement

    Hi all

    I'm writing a query where I can update a pastdue_fees column in a table of book_trans based on a difference between the return_dte and due_dte columns.

    I use Oracle SQL. That's what I have so far for my decoding function:

    SQL > SELECT
    2 DECODE (SIGN ((return_dte-due_dte) * 2),)
    3 '-1 ', ' 0',
    4 '1', '12', 'Null')
    5 FROM book_trans;

    DECO
    ----
    Null value
    12
    Null value
    0

    If the logic is that, if the sign is - 1, the value in the return_dte column must be 0; If it is + 1, then it has 12 and everything else is Null.

    So now, I have to conclude my function of decoding of the update statement to update the columns. However, I get the error messages.

    The logic should be:
    UPDATE book_trans SET PastDue_fees = decode (expression)

    I gave him a few different tests with the following results:

    SQL > UPDATE book_trans
    2 SET pastdue_fees = SELECT
    3 DECODE (SIGN ((return_dte-due_dte) * 2),)
    4 '-1 ', ' 0',
    5 '1', '12', 'Null')
    6 FROM book_trans.
    SET pastdue_fees = SELECT
    *
    ERROR on line 2:
    ORA-00936: lack of expression


    SQL > UPDATE book_trans
    2 SET pastdue_fees =
    3 DECODE (SIGN ((return_dte-due_dte) * 2),)
    4 '-1 ', ' 0',
    5 '1', '12', 'Null')
    6 FROM book_trans.
    OF book_trans
    *
    ERROR on line 6:
    ORA-00933: SQL not correctly completed command.

    Any help or advice would be greatly appreciated I got SQL for about six weeks and not very competent!

    Thank you!

    882300 wrote:
    Hi all

    I'm writing a query where I can update a pastdue_fees column in a table of book_trans based on a difference between the return_dte and due_dte columns.

    I use Oracle SQL. That's what I have so far for my decoding function:

    SQL > SELECT
    2 DECODE (SIGN ((return_dte-due_dte) * 2),)
    3 '-1 ', ' 0',
    4 '1', '12', 'Null')
    5 FROM book_trans;

    DECO
    ----
    Null value
    12
    Null value
    0

    If the logic is that, if the sign is - 1, the value in the return_dte column must be 0; If it is + 1, then it has 12 and everything else is Null.

    So now, I have to conclude my function of decoding of the update statement to update the columns. However, I get the error messages.

    The logic should be:
    UPDATE book_trans SET PastDue_fees = decode (expression)

    I gave him a few different tests with the following results:

    SQL > UPDATE book_trans
    2 SET pastdue_fees = SELECT
    3 DECODE (SIGN ((return_dte-due_dte) * 2),)
    4 '-1 ', ' 0',
    5 '1', '12', 'Null')
    6 FROM book_trans.
    SET pastdue_fees = SELECT
    *
    ERROR on line 2:
    ORA-00936: lack of expression

    SQL > UPDATE book_trans
    2 SET pastdue_fees =
    3 DECODE (SIGN ((return_dte-due_dte) * 2),)
    4 '-1 ', ' 0',
    5 '1', '12', 'Null')
    6 FROM book_trans.
    OF book_trans
    *
    ERROR on line 6:
    ORA-00933: SQL not correctly completed command.

    Any help or advice would be greatly appreciated I got SQL for about six weeks and not very competent!

    Thank you!

    If you really really really want to update the entire table, the syntax would be...

    UPDATE book_trans
       SET
          pastdue_fees  = DECODE(SIGN((return_dte - due_dte)*2), -1, 0, 1, 12, Null);
    

    I took out all the single quotes. If you actually have a string column and store all numbers in there so it must be reported as a NUMBER column and not a column of type character (varchar2).

    ALWAYS use the appropriate data type, it will save you a ton of headaches in the future.

    Also, since you are new to the forum, please read the FAQ to learn etiquette and what not.

    http://wikis.Sun.com/display/Forums/Forums+FAQ

Maybe you are looking for