Advanced update query

I am trying to perform an update query on one field that uses multiple foreign key parameters from one table to update the other table. The data in all three foreign key parameter fields are not constant. Accuracy is absolutely critical. I tied this as well as other various scenarios with no success. Can anyone help?
Update A_table a
set a.rate = (
select b.rate
from B_table b
where b.id = a.id
and b.transdate = a.transdate
and b.orgnum = a.orgnum
and b.transdate = to_date('31/12/2007', 'dd/mm/yyyy')
)

I think most of the new guys post product related questions here because, they might have heard that there is something called forums, they go to google and type oracle forums. When the forums home page opens they directly post in the first link available, which is unfortunately this forum. Probably moving Database forum up, and moving technology network community forums below would solve this problem compared to the number of people who don't even read the forum name before posting.

Similar Messages

  • About update query

    Hello :),
    I am a MS SQL Server expert [;)]. trying to learn ORACLE.
    I tried to assign some value to a variable in an update query. I got error message that virtual columns are not allowed. This is very important to get rolling effect.
    Can some one please guide me about how to get rolling effect if we can not assign a value to a variable in an update query.
    Thanx in advance.
    Nishu

    hello sgalaxy and gintsp, thanx for ur reply.
    My reply is so late because for some reason I was not able to log on to this site.
    There is some good reason why I need this. I am giving code and error messages below, please guide me.
    ==============================
    I am trying this thing in procedure. I am using ORACLE DATABASE EXPRESS EDITION
    Here is the code.
    create or replace procedure "PROC1"
    is
    TYPE Bal_Collect IS TABLE OF NUMBER;
    Collt Bal_Collect := Bal_Collect(100);
    begin
    Update empAccount Set Bal = Collt(Collt.Last) Returning Bal BULK COLLECT INTO Collt;
    end;
    Error message
    Compilation failed,line 6 (02:20:45)
    PLS-00425: in SQL, function argument and return types must be SQL type
    Compilation failed,line 6 (02:20:45)
    PL/SQL: ORA-00904: : invalid identifier
    Compilation failed,line 6 (02:20:45)
    PL/SQL: SQL Statement ignored
    BUT FOLLOWING UPDATE STATEMENT WORKS
    Update empAccount Set Bal = Collt(1) Returning Bal BULK COLLECT INTO Collt;

  • Doubt in Update query

    I have a problem using update query, for updating one column in a table with another column in another table. For eg say i have two tables, collector and survey
    Fields in Collector:
    col_n_account_num
    col_v_email
    col_n_phone_number
    Fields in survey
    sur_v_question_id
    sur_n_account_num
    sur_v_response
    update collector
    case when sur_v_question_id=collector_email then col_v_email=sur_v_response end,
    case when sur_v_question_id=collector_phone then col_n_phone_number=sur_v_response end
    Thanks in advance
    Regards,
    ss

    write two simple update statements
    update collector set col_v_email =
    (select sur_v_response from survey
    where sur_v_question_id=collector_email )
    and
    update collector set col_n_phone_number =
    (select sur_v_response from survey
    where sur_v_question_id=collector_phone)

  • I want single update query without use the function.

    I want to update sells_table selling_code field with max date product_code from product table.
    In product table there is multiple product_code date wise.
    I have been done it with below quey with the use of function but can we do it in only one update query
    without use the function.
    UPDATE sells_table
    SET selling_code = MAXDATEPRODUCT(ctd_vpk_product_code)
    WHERE NVL(update_product_flag,0) = 0 ;
    CREATE OR REPLACE FUNCTION HVL.maxdateproduct (p_product IN VARCHAR2) RETURN NUMBER
    IS
    max_date_product VARCHAR2 (100);
    BEGIN
    BEGIN
    SELECT NVL (TRIM (product_code), 0)
    INTO max_date_product
    FROM (SELECT product_code, xref_end_dt
    FROM product
    WHERE TO_NUMBER (p_product) = pr.item_id
    ORDER BY xref_end_dt DESC)
    WHERE ROWNUM = 1; -- It will return only one row - max date product code
    EXCEPTION
    WHEN OTHERS
    THEN
    RETURN 0;
    END;
    RETURN max_date_product;
    END maxdateproduct;
    Thanks in Advance.

    Hi,
    Something like this.
    update setlls_table st
            set selling_code =(select nvl(trim(product_code)) from 
                                  (select product_code
                                          , rank() over (partition by item_id order by xref_end_dt DESC) rn
                                       from product
                                   ) pr
                                   where rn =1
                                         and pr.item_id = st.ctd_vpk_product_code
                               ) where NVL(update_product_flag,0) = 0 ;As such not tested due to lack of input sample.
    Regards
    Anurag Tibrewal.

  • Dynamic Update Query

    HI All,
    Please find below DML script.
    CREATE TABLE UP_A(ID INT , VAL VARCHAR(50))
    GO
    INSERT INTO UP_A VALUES(100,'Hundred')
    INSERT INTO UP_A VALUES(1001,'Hundred and one')
    INSERT INTO UP_A VALUES(1000,'Thousand')
    INSERT INTO UP_A VALUES(1005,'Thousand and five')
    go
    CREATE TABLE UP_B(ID1 INT,ID2 INT,VAL1 VARCHAR(50),VAL2 VARCHAR(50))
    GO
    INSERT INTO UP_B(ID1,ID2) VALUES(100,1000)
    INSERT INTO UP_B(ID1,ID2) VALUES(1001,1005)
    GO
    SELECT * FROM UP_A
    SELECT * FROM UP_B
    i wants to update Table UP_B Val1 and Val2 columns Based on Table UP_A ID Values.
    Example : in Table UP_A for ID=100 the VAL='Hundred' So, this has to be updated in Table UP_B Val1 column. In the same way i wants to update all respective Val1 and Val2 from the respective Val from Table UP_A. 
    Is there way to update with single UPDATE Query.
    Thanks in advance.
    bala krishna

    Thank you for tryign, but you got it wrong. You ha be no idea what a tahel is, how to naem data element or SQL syntax:
    CREATE TABLE UP_A
    (ID INT , VAL VARCHAR(50))
    GO
    INSERT INTO UP_A VALUES(100,'Hundred')
    INSERT INTO UP_A VALUES(1001,'Hundred and one')
    INSERT INTO UP_A VALUES(1000,'Thousand')
    INSERT INTO UP_A VALUES(1005,'Thousand and five')
    go
    CREATE TABLE UP_B(ID1 INT,ID2 INT,VAL1 VARCHAR(50),VAL2 VARCHAR(50))
    GO
    INSERT INTO UP_B(ID1,ID2) VALUES(100,1000)
    INSERT INTO UP_B(ID1,ID2) VALUES(1001,1005)
    GO
    SELECT * FROM UP_A
    SELECT * FROM UP_B
    i wants to update Table UP_B Val1 and Val2 columns Based on Table UP_A ID 
    Thank you for trying to post DDL,  but you got it wrong. You have no idea what a table is, how to name data element or SQL syntax. 
    CREATE TABLE Numeric_Somethings
    (numeric_value INTEGER NOT NULL PRIMARY KEY, 
     display_txt VARCHAR(20) NOT NULL);
    INSERT INTO Numeric_Somethings
     VALUES(100, 'Hundred'), 
         (1001, 'Hundred and one'), 
         (1000, 'Thousand'), 
         (1005, 'Thousand and five');
    A table is not a file. Try this design:
    CREATE TABLE Redundant_Somethings
    (numeric_value_1 INTEGER NOT NULL
      REFERENCES Numeric_Somethings(numeric_value),
     numeric_value_2 INTEGER NOT NULL
      REFERENCES Numeric_Somethings(numeric_value),
    PRIMARY KEY (numeric_value_1, numeric_value_2)); -- guess! 
    INSERT INTO Redundant_Somethings(numeric_value1, numeric_value2) VALUES(100, 1000), (1001, 1005)
    >> I wants to update Table Redundant_Somethings ..<<
    You might, but an SQL Programmer will use a VIEW that is always correct
    CREATE VIEW Double_Stuff
    AS 
    SELECT R.numeric_value_1, R.numeric_value_2
           N1.display_txt, N2.display_txt
      FROM Redundant_Somethings AS R,
           Numeric_Somethings AS N1, Numeric_Somethings AS N2
     WHERE R.numeric_value_1 = N1.numeric_value
       AND R.numeric_value_2 = N2.numeric_value;
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Update query issue to update middle (n records) of the rows in a table

    Hi
    I have a below requirement for that I gone thru one below appoch to fulfill my requirement.
    Requirement:
    I need to pull 3 crore data thru ODI, source table does not have a primary key and it have 200 columns with 3 crores records (it has a 25 columns as composite key).
    I need to populate those 3 crores records into target oracle DB but when I tried to load 3 crores at time I got an error so I approch incremental load, since for that I need to update for each 1 crore records with flg1,flg2 anf flg3 (flag values), for this update I have added one more column in source table using those flag values I can populate 1 crore records in target machine.
    Approch
    For aove requirement I writem below query to update flg1 for first crores records update tbl_name set rownum_id='flg1' where rownum<=10000000; and it updated successfully without any error, for second, to update flg2 for 2nd crore records I wrote below update query and it execute 20min and given *0 rows updated* Please help if below query is wrong
    Query: update tbl_name set rownum_id='flg2' where rownum<=20000000 and rownum_id is NULL;
    Thanks in advance
    Regards,
    Phanikanth

    A couple of thoughts.
    1. This forum is in English and accessed by people in more than 100 countries. Use metric counts not crore. Translate to million, billions, trillions, etc.
    2. No database version ... makes helping you very hard.
    3. 200 columns with 25 in a composite key is a nightmare by almost any definition ... fix your design before going any further.
    4. What error message? Post the complete message not just your impression of it.
    5. Oracle tables are heap tables .. there is no such concept as the top, the bottom, or the middle.
    6. If you are trying to perform sampling ... use the SAMPLE clause (http://www.morganslibrary.org/reference/select.html#sssc).
    7. What is ODI? Do not expect your international audience to know what the acronym means.

  • Update query is waiting for async descriptor resize

    Hi All,
    One of the update query which was completing in 1-2 mins. Suddenly today it started taking more than 3-4 hours and still it is running.
    Below is the query, I can see the explain plain. I can see the query is waiting for async descriptor resize wait event
    UPDATE AP_INVOICE_DISTRIBUTIONS SET POSTED_FLAG = 'N' WHERE POST
    ED_FLAG = 'S' AND (ACCOUNTING_DATE >= :B2 OR :B2 IS NULL) AND (A
    CCOUNTING_DATE <= :B1 OR :B1 IS NULL)
    when i checked the P1text, P2text columns of v$session, it is showing outstanding #aio,current ai0 limit respectively.
    Explan plan
    CODEPLAN_TABLE_OUTPUT
    | Id  | Operation                      | Name                         | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | UPDATE STATEMENT               |                              |       |       |   250 (100)|          |
    |   1 |  UPDATE                        | AP_INVOICE_DISTRIBUTIONS_ALL |       |       |            |          |
    |   2 |   NESTED LOOPS                 |                              |       |       |            |          |
    |   3 |    NESTED LOOPS                |                              |    39 | 12480 |   250   (0)| 05:14:02 |
    |*  4 |     TABLE ACCESS BY INDEX ROWID| AP_ACCOUNTING_EVENTS_ALL     |    39 |   624 |   145   (0)| 03:02:09 |
    |*  5 |      INDEX RANGE SCAN          | AP_ACCOUNTING_EVENTS_N2      |  3954 |       |    14   (0)| 00:17:36 |
    |*  6 |     INDEX RANGE SCAN           | AP_INVOICE_DISTRIBUTIONS_N18 |     4 |       |     2   (0)| 00:02:31 |
    PLAN_TABLE_OUTPUT
    |*  7 |    TABLE ACCESS BY INDEX ROWID | AP_INVOICE_DISTRIBUTIONS_ALL |     1 |   304 |     4   (0)| 00:05:02 |
    CODE
    Please help me on this.
    Env Details --
    DB version -- 11.2.0.1
    OS - IBM AIX.
    Thanks in advance...

    This could be this bug
    Bug 9829397 - Excessive CPU and many "asynch descriptor resize" waits for SQL using Async IO (Doc ID 9829397.8)

  • Update query for a table

    Hi
    Can any body send valid update query like this:
    <sql:update var="XX">
    Update emp set name='yy', phone='1234' where id='abc'
    </sql:update>
    Thanks in Advance
    SP

    Hi
    Can any body send valid update query like this:
    <sql:update var="XX">
    Update emp set name='yy', phone='1234' where id='abc'
    </sql:update>
    Thanks in Advance
    SP

  • Update query with CL_SQL_STATEMENT class

    Hi all,
    I'm trying to execute an update query with ADBC classes in order to modify two parameters (n_doc and processed) from a row with the following instructions:
          l_con_ref = cl_sql_connection=>get_connection( 'DB_7879' ).
          l_stmt_ref = l_con_ref->create_statement( ).
         CONCATENATE 'update' gv_table ' set n_doc= ? processed = ''X'' where id_ordn = ? '  INTO l_stmt SEPARATED BY space.
          GET REFERENCE OF materialdocument INTO l_dref.
          l_stmt_ref->set_param( l_dref ).
          GET REFERENCE OF ps_zmm_mov-id_ordn INTO l_dref.
          l_stmt_ref->set_param( l_dref ).
          l_stmt_ref->execute_update( l_stmt ).
    However, I got the error ORA-0933: SQL command not properly ended. I guess this error occurs because I am trying to update two parameters with a single query since using the following CONCATENATE instruction
         CONCATENATE 'update' gv_table ' set n_doc= ? where id_ordn = ? '  INTO l_stmt SEPARATED BY space.
    results ok.
    Does anybody know if it is possible to modify two parameters with only one update query with ADBC classes?
    Thank you in advance!

    Hi Suhas,
    Based on Oracle, I see it conforms almost completely ISO/IEC 9075 ([Oracle and Standard SQL|http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/ap_standard_sql.htm#10293])
    UPDATE seems to conform completely [UPDATE SET clause|http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_108a.htm#2087215]
    So using a comma to separate columns is true for every SQL language that conforms ISO/IEC 9075
    Sandra
    PS: of course SAP's "Open SQL" language does not conform at all

  • Update query in HQL.

    Hi,
    Can you suggest me the format of the update query for HQL
    Thanks in advance.

    Read the documentation, google for tutorials and examples.

  • Update query problem

    Hello
    I'm trying to write an update query either in a single statement or stored procedure that updates a numeric column based on a date column. I do this using:
    UPDATE DATE SMSCLOSED_CTYWOA SET 'date_action_start' = to_number(to_char('action_date' ,'MMDDYY')); No big deal. The problem is both column names have apostrophe's in their name (i.e. '). When I run this query the 'action_date' segment returns an error:
    ERROR at line 1:
    ORA-01747: invalid user.table.column, table.column, or column specification
    Any advice would be appreciated.
    Thanks in advance.

    If you had a normal table, like:
    Name Null? Type
    DATE_ACTION_START NUMBER(6)
    ACTION_DATE DATE
    the command would be:
    UPDATE smsclosed_ctywoa
    SET date_action_start = TO_NUMBER(TO_CHAR(action_date,'MMDDYY'));
    However, if you have a table like:
    Name Null? Type
    'date_action_start' NUMBER(6)
    'action_date' DATE
    which is a really poor table design, then the command would be:
    UPDATE smsclosed_ctywoa
    SET "'date_action_start'" = TO_NUMBER(TO_CHAR("'action_date'",'MMDDYY'));
    Note that, in both cases, there is no DATE after the word UPDATE.
    In the second case, if your column names have apostrophes and are in lower case, which is a really bad design, then you need to enclosed them in double quotes.
    Another thing you should be aware of is that, because date_action_start is a number field, you will be losing the leading zeroes, so July 9, 2001 will be 70901, not 070901.
    It looks like you need to seriously reconsider your table design.
    null

  • Help with a update query from a subquery

    Hello All,
    I wanted to see if someone can help me with an update query.
    I need to grab a latitude & longitude from a the same user that is in two accounts. therefore i am trying to update lat/long in a users table for one account based off of the same user in another account. I am matching the users up by phone number and last name. I tried a subquery but am having difficulty.
    I was thinking of something like the following:
    update users
    set lat = getlat, long = getlong
    inner join (select lat as getlat, long as get long from users where account_id = '1')
    on phone = phone and last name = lastname
    where account_id = '2' and lat IS NULL and long IS NULL
    Am I going in the right direction???
    Thanks in advance for any assistance!!!!

    What difficulty are you having? Have you tried what you posted and get an error?
    Although someone may be able to give you sql advice here, I would try posting this over at Stack Overflow as its not really related to Coldfusion.

  • Cannot convert msaccess update query to view

    Hello,
    I am trying to migrate an msaccess database to oracle using oracle sql developer. The problem is that I get error messages when I convert the captured access model to an oracle model.
    I only get error messages on the converted views. These are originally update queries in access like the following example:
    UPDATE [Tbl Zuguebersicht CMA] INNER JOIN 1_PrioTab ON [Tbl Zuguebersicht CMA].Zugnummer = [1_PrioTab].ZugNr SET [Tbl Zuguebersicht CMA].Prioritaet = [1_PrioTab]![InternePrio];
    In the captured model this query is already listed under the node for views. When I convert the model, I get the error message that it cannot be converted.
    If I got it right, an update query cannot be converted to a view, is that correct? So it should rather be a function. I couldn't find a possibility to change this!
    Or am I on the wrong track and there is just a special problem with exactly this update query? But then again, all the update queries could not be converted!
    Help would greatly be appreciated! Thanks in advance...
    Edited by: user8772417 on Sep 17, 2009 8:54 AM

    Thanks for your answers!
    Well I guess then I I have to create the stored procedures myself after the conversion and delete the useless views. That shouldn't be a big deal! I only wanted to avoid searching for the code lines where the stored procedure has to be called - therefore, the automatic way would have been much more comfortable :-)
    I will request this feature on the sql developer page. I can't imagine I am the only one facing this particular MS Access conversion problem.
    Thanks again,
    Max

  • Unanle to run update query

    Hi Experts,
    I got the solution from SAP to run update query on table E071 by using SQLPLUS prompt.
    But when I run this query I am getting message as below:
    ERROR at line 1:
    ORA-00942: table or view does not exist
    I am also unable to execute simple query like
    - select * from E071;
    - desc E071;
    For all above queries I am getting the same message as shown.
    But I am able to open view the table in SE11.
    I am also able to execute the following query in sqlplus -
    - select owner, table_name from all_tab_cols where table_name like 'E071';
    - select * from all_tables where table_name like 'E071';
    Please provide me the solution / alternative to run this update query on table E071.
    Thanks in Advance
    Best RG//
    Ramesh.

    Hi,
    if you use
    sqlplus / as sysdba
    you are SYS to the DB. You need to specify the schemauser.
    desc sapr3.E071
    desc sapsr3.E071
    desc sapsid.E071
    depending on how you schemauser is named.
    check your sidadm environment:
    env | grep -i schema
    Hope this helps
    Volker

  • If statement in update query

    I was wondering if you could have a cfif statement inside of a update query.  See example below.  Is there a better way of doing it? thanks.
    <cfquery DATASOURCE="xxx" name="update">
      UPDATE plant_gen_info
            SET levels_complete = #URL.var0#
                <cfif IsDefined("URLvar13">
                ,Q1_answer = #URL.var13#
                </cfif>
            WHERE ID = #session.member_id#
      </cfquery>

    TheScarecrow,
    Yes, dynamic query statements can be assembled using <cfif>.  I would suggest you switch your IsDefined() to a StructKeyExists() and strongly suggest you make good use of <cfqueryparam>:
    <cfquery DATASOURCE="xxx" name="update">
      UPDATE plant_gen_info
            SET levels_complete = <cfqueryparam value="#URL.var0#" cfsqltype="****">
                <cfif StructKeyExists(URL, "var13")>
                ,Q1_answer = <cfqueryparam value="#URL.var13#" cfsqltype="****">
                </cfif>
            WHERE ID = <cfqueryparam value="#session.member_id#" cfsqltype="****">
      </cfquery>
    I put a "****" placeholder for cfsqltype attributes because I'm not sure which would be appropriate for your variables.  See the help docs for more on the cfqueryparam and cfsqltype.
    -Carl V.

Maybe you are looking for