Update a column with value of column of other table

Hi,
I am looking for an update statement for the following scenario
With following 2 tables
TABLE1 (Primary A, B)
TABLE2 (Secondary C , D).
C Column is not unique.
Please provide me an update statement to update TABLE1.B with TABLE2.D where TABLE1. A = TABLE2.C
Please note that TABLE2.C is not unique.
Please let me know whether this satement is correct.
UPDATE TABLE1
SET B = (SELECT DISTINCT D FROM TABLE 2 WHERE A=C )
Thanks
Alla Kishore

UPDATE TABLE1 T1
SET T1.B = (SELECT DISTINCT D FROM TABLE2 T2 WHERE T2.C=T1.A )

Similar Messages

  • Updating a column from other table

    Hi all,
    I have a simple update query problem. I have four tables
    activist(activist_id,first_name,last_name,c_state),
    membership(activist_id,g_n_id),
    group_network(g_n_id,g_n_type_id),
    school_grop_det(g_n_id,state). For some records in activist table the c_state column is null, i want to update that column with state column of school_group_det table.
    Here is the query for the states which are null
    select distinct a.activist_id,a.first_name,a.last_name,
    a.c_state,sd.state from activist a,membership m,
    group_network g,school_group_det sd where
    a.activist_id=m.activist_id and g.g_n_id=m.g_n_id and
    g.g_n_id=sd.g_N_id and a.c_state is null and g.g_n_type_id='1001'
    order by a.activist_id
    I got the activist_id,first_name,last_name,c_state from activist and state from school_group_det. now i as i told you want to update the c_state with state column of school_group_Det table.
    Pleae any one help me
    Thanks
    Srinivas

    For ur query the reply whay u have got is correct one. For further quries similar to one u had u can download a tool named TOAD (Tools for Oracle Application Developer) from quest site (www.quest.com). Install it a proceed.
    Do let me know how and what u feek about TOAD.

  • How to update two columns in two tables?

    hi friends
    I have two tables linked to each other through SaleNo and SaleDT. their structure as below
    Sales Table============
    SaleNo int PK auto increment
    SaleDT Datetime PK
    Qnty decimal
    Units decimal
    Invoices table
    =================InvoiceNo int PK Auto incremented
    InvoiceDT Datetime
    SaleNo int FK
    SaleDT Datetime FK
    Note that SaleDT column is NOT assigned with getDate() expression.
    1. what I need to do is update the SaleDT column of Sales table and Invoices table with the value '2013-01-31 10:31:55.813', how do I do this without manually breaking the link between the tables?
    2. Assume SaleNos 15 to 27 needs update the SaleDT to '2013-06-12 10:31:55.813', how do I do this complex operation where I I have update SaleDt column of two table of SaleNo range from 15 to 27?
    thanks
    I use Visual studio 2012 Ultimate and SQL server 2008 developer edition!

    Why not below? May be you will not be able to change your design now, but just want to share.
    Sales Table============
    SALEID int PK autoincrement
    SaleNo int
    SaleDT Datetime
    Qnty decimal
    Units decimalUNIQUE (Saleno,SaleDT)
    Invoices table
    =================InvoiceNo int PK Auto incremented
    InvoiceDT Datetime
    SALEID int FK

  • How to update multiple columns from different tables using cursor.

    Hi,
    i have two tables test1 and test2. i want to udpate the column(DEPT_DSCR) of both the tables TEST1 and TEST2 using select for update and current of...using cursor.
    I have a code written as follows :
    DECLARE
    v_mydept1 TEST1.DEPT_CD%TYPE;
    v_mydept2 TEST2.DEPT_CD%TYPE;
    CURSOR C1 IS SELECT TEST1.DEPT_CD,TEST2.DEPT_CD FROM TEST1,TEST2 WHERE TEST1.DEPT_CD = TEST2.DEPT_CD AND TEST1.DEPT_CD = 'AA' FOR UPDATE OF TEST1.DEPT_DSCR,TEST2.DEPT_DSCR;
    BEGIN
    OPEN C1;
         LOOP
              FETCH C1 INTO v_mydept1,v_mydept2;
              EXIT WHEN C1%NOTFOUND;
              UPDATE TEST2 SET DEPT_DSCR = 'PLSQL1' WHERE CURRENT OF C1;
              UPDATE TEST2 SET DEPT_DSCR = 'PLSQL2' WHERE CURRENT OF C1;
         END LOOP;
         COMMIT;
    END;
    The above code when run says that it runs successfully. But it does not updates the desired columns[DEPT_DSCR].
    It only works when we want to update single or multiple columns of same table...i.e. by providing these columns after "FOR UPDATE OF"
    I am not sure what is the exact problem when we want to update multiple columns of different tables.
    Can anyone help me on this ?

    oops my mistake.....typo mistake...it should have been as follows --
    UPDATE TEST1 SET DEPT_DSCR = 'PLSQL1' WHERE CURRENT OF C1;
    UPDATE TEST2 SET DEPT_DSCR = 'PLSQL2' WHERE CURRENT OF C1;
    Now here is the upated PL/SQL code where we are trying to update columns of different tables --
    DECLARE
    v_mydept1 TEST1.DEPT_CD%TYPE;
    v_mydept2 TEST2.DEPT_CD%TYPE;
    CURSOR C1 IS SELECT TEST1.DEPT_CD,TEST2.DEPT_CD FROM TEST1,TEST2 WHERE TEST1.DEPT_CD = TEST2.DEPT_CD AND TEST1.DEPT_CD = 'AA' FOR UPDATE OF TEST1.DEPT_DSCR,TEST2.DEPT_DSCR;
    BEGIN
    OPEN C1;
    LOOP
    FETCH C1 INTO v_mydept1,v_mydept2;
    EXIT WHEN C1%NOTFOUND;
    UPDATE TEST1 SET DEPT_DSCR = 'PLSQL1' WHERE CURRENT OF C1;
    UPDATE TEST2 SET DEPT_DSCR = 'PLSQL2' WHERE CURRENT OF C1;
    END LOOP;
    COMMIT;
    END;
    Please let us know why it is not updating by using using CURRENT OF

  • Update trigger fails with value too large for column error on timestamp

    Hello there,
    I've got a problem with several update triggers. I've several triggers monitoring a set of tables.
    Upon each update the updated data is compared with the current values in the table columns.
    If different values are detected the update timestamp is set with the current_timestamp. That
    way we have a timestamp that reflects real changes in relevant data. I attached an example for
    that kind of trigger below. The triggers on each monitored table only differ in the columns that
    are compared.
    CREATE OR REPLACE TRIGGER T_ava01_obj_cont
    BEFORE UPDATE on ava01_obj_cont
    FOR EACH ROW
    DECLARE
      v_changed  boolean := false;
    BEGIN
      IF NOT v_changed THEN
        v_changed := (:old.cr_adv_id IS NULL AND :new.cr_adv_id IS NOT NULL) OR
                     (:old.cr_adv_id IS NOT NULL AND :new.cr_adv_id IS NULL)OR
                     (:old.cr_adv_id IS NOT NULL AND :new.cr_adv_id IS NOT NULL AND :old.cr_adv_id != :new.cr_adv_id);
      END IF;
      IF NOT v_changed THEN
        v_changed := (:old.is_euzins_relevant IS NULL AND :new.is_euzins_relevant IS NOT NULL) OR
                     (:old.is_euzins_relevant IS NOT NULL AND :new.is_euzins_relevant IS NULL)OR
                     (:old.is_euzins_relevant IS NOT NULL AND :new.is_euzins_relevant IS NOT NULL AND :old.is_euzins_relevant != :new.is_euzins_relevant);
      END IF;
    [.. more values being compared ..]
        IF v_changed THEN
        :new.update_ts := current_timestamp;
      END IF;
    END T_ava01_obj_cont;Really relevant is the statement
    :new.update_ts := current_timestamp;So far so good. The problem is, it works the most of time. Only sometimes it fails with the following error:
    SQL state [72000]; error code [12899]; ORA-12899: value too large for column "LGT_CLASS_AVALOQ"."AVA01_OBJ_CONT"."UPDATE_TS"
    (actual: 28, maximum: 11)
    I can't see how the value systimestamp or current_timestamp (I tried both) should be too large for
    a column defined as TIMESTAMP(6). We've got tables where more updates occur then elsewhere.
    Thats where the most of the errors pop up. Other tables with fewer updates show errors only
    sporadicly or even never. I can't see a kind of error pattern. It's like that every 10.000th update
    or less failes.
    I was desperate enough to try some language dependend transformation like
    IF v_changed THEN
        l_update_date := systimestamp || '';
        select value into l_timestamp_format from nls_database_parameters where parameter = 'NLS_TIMESTAMP_TZ_FORMAT';
        :new.update_ts := to_timestamp_tz(l_update_date, l_timestamp_format);
    END IF;to be sure the format is right. It didn't change a thing.
    We are using Oracle Version 10.2.0.4.0 Production.
    Did anyone encounter that kind of behaviour and solve it? I'm now pretty certain that it has to
    be an oracle bug. What is the forum's opinion on that? Would you suggest to file a bug report?
    Thanks in advance for your help.
    Kind regards
    Jan

    Could you please edit your post and use formatting and tags.  This is pretty much unreadable and the forum boogered up some of your code.
    Instructions are here: http://forums.oracle.com/forums/help.jspa                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Getting errors when updating a column on a table having a primary key

    Hi,
    I have an application on Oracle APEX that raises the following error after an attempt (through the application) to update a column with no specific constraint on it:
    ORA-06550: line 1, column 17: PL/SQL: ORA-00936: missing expression ORA-06550: line 1, column 9: PL/SQL: SQL Statement ignoredUnable to fetch row.
    The involved table has a primary key conatraint and the corresponding column can be populated by a sequence (but there is no trigger to manipulate the sequence).
    The sequence is mentioned in the involved page definition for populating the primary key.
    If I disable the primry key and set to null the corresponding value for the primary of the record to be updated, then it is possible to update that record (thus the above column) through the application.
    Did someone encountered this situation before?
    If yes, what was then your workaround/solution?
    Kind Regards.

    Dear user8058501 ,
    Firstly) Did you check
    Auto Row Fetch (After upgrade to 4.0.1)
    Automated Row Fetch on Table with Synonym causes ORA-00936: missing expr.
    Secondly) If the problem is not resolved, Would you provide a sample on apex.oracle.com with workspace/developer account to be able to help you
    Please, if this solves your question, mark it as Correct. Otherwise as helpful.
    Best Regards
    Mahmoud

  • Question about creating and updating new columns in a table

    Hi, I have a couple of questions that would love some answers to
    Please bear in min that questions relate to datawarehouse / Just large tables with say about 50 million records
    1) How do you create new columns in a big table
    2) how do you update the new columns
    3) would you create an index on a column in a table with 200m rows when the only two possible values are stored in the column (e.g.Y, N) - give your resason
    my aswers to these would be
    1) simple alter table ...
    2) simple update statements
    3) No need to create an index
    I might be wrong on these in the context of datawarehouse
    cheers
    css_jay99

    If the number of Y vs. N is about 50/50, you only have to parse through 50% of the
    overall amount of columns.Fnord. If the ratio of Y to N was 1:20 then the index would be useful for searching for values of Y only. Or if the column is nullable and the bulk of the entries were null then it might be useful. But a 50/50 split? FTS is much more effective.
    So, it does depend on the data distribution, but in most cases such an index would never be used (or should never be used).
    Cheers, APC

  • Need logic to update Varchar column in a table

    Hi,
    Could you give me logic for below.
    I have a table xx_dbc where one of the column Attribute1 is varchar2(240).
    Attribute1 has values like 
    ==================
    (AIN,PUP,GRI,NINE)
    (AIN,PUP)
    (AIN)
    (GRI,NINE)
    I have to update this column for every record with values AIN=10 , PUP=20 , GRI=30 , NINE=40
    Columns should be updated like below
    (10,20,30,40)
    (10,20)
    (10)
    (30,40)
    Thanks.

    Hi,
    Here's one way:
    WITH  replacements  AS
        SELECT  'AIN' AS old_str, '10' AS new_str  FROM dual  UNION ALL
        SELECT  'PUP',            '20'             FROM dual  UNION ALL
        SELECT  'GRI',            '30'             FROM dual  UNION ALL
        SELECT  'NINE',           '40'             FROM dual
    ,    normalized_data  AS
        SELECT  p_key
        ,       LEVEL               AS sort_key
        ,       REGEXP_SUBSTR ( attribute1
                              , '[^(,)]+'
                              , 1
                              , LEVEL
                              )     AS str
        FROM    xx_dbc
    --  WHERE   ...     -- If you need any filtering, put it here
        CONNECT BY   LEVEL              <= 1 + REGEXP_COUNT (attribute1, ',')
                AND  PRIOR p_key        = p_key
                AND  PRIOR SYS_GUID ()  IS NOT NULL
    SELECT    '(' || LISTAGG ( NVL (r.new_str, n.str)
                             ) WITHIN GROUP (ORDER BY sort_key)
                  || ')'  AS  new_attribute1
    ,         n.p_key                         -- If wanted
    FROM             normalized_data  n
    LEFT OUTER JOIN  replacements     r  ON  r.old_str  = n.str
    GROUP BY  n.p_key
    ORDER BY  n.p_key
    Like everything else, it depends on your Oracle version.
    In the query above, p_key can be any unique key from xx_dbc, including attribute1 or ROWID.
    Relational databases, like Oracle, work best when each column of each row contains only 1 piece of information, not a delimited list of any number of pieces.  This is so fundamental to table design that it's called First Normal Form.  Most of the work in this problem involves converting your denormalized data into First Normal Form, and then converting it back again.  This problem, like many others, would be much simpler and more efficient if your table was in First Normal Form.
    The query above assumes the replacement strings (such as 'AIN' and '10') are not already in a table.  If they are, or if they can be derived from a table, then you don't need the replacements sub-query; use your real table instead.

  • Update 1 column,1 single table based on where results of multiple tables

    I would like the my_id column in 1 table updated to the static value of 247 for my_id stored in the 1 single table based on the where clause, which uses the my_id column in it.
    The update statement updates all rows in table1, instead of just the rows where
    the condition ( (b.my_id=a.my_id)
    and ( b.my_name like 'OIS SrClerk%')
    and (a.f_id=m.f_id)
    and (trunc(m.cr_time) < '02-Apr-2008')) is true
    What needs to be changed?
    update table1 a
    set a.my_id=247
    from table1 a, table2 b, table3 m
    where
    (b.my_id=a.my_id)
    and ( b.my_name like 'OIS SrClerk%')
    and (a.f_id=m.f_id)
    and (trunc(m.cr_time) < '02-Apr-2008')

    Are you looking for this?
    UPDATE table1 A
       SET A.my_id = 247
    WHERE EXISTS (SELECT 'x'
                     FROM table2 b,
                          table3 M
                    WHERE b.my_id = A.my_id
                     AND b.my_name LIKE 'OIS SrClerk%'
                     AND A.f_id = M.f_id
                     AND TRUNC (M.cr_time) < to_date('02-apr-2008 00:00:00','dd-mon-yyyy HH:MI:SS') )changed date string to to_date
    Message was edited by:
    devmiral

  • Updating a column of a table

    Hi all
    I have a problem in updating one column in the target table(say table A) from a column in the source table (say table B).
    All the columns in table A has been populated. Just one column should be populated. My source is a SQL object that contains a complex sql query that returns three columns date_from, date_to and ID.
    In the table A, I have the same date_from and date_to and need to get the ID from the SQL object and set it to the corresponding ID in the table A.
    I tried many ways to update the table, but it I couldn't ;(
    I should read from a table and update it based on a look-up function mapped to the column I need to update.
    I want to map the ID colmn from table A to a look-up ext function that can get the column from the table B. However I don't know how to use the Data Services objects to just update 1 column. If you could give me a consequence of the DS objects to be update a table based on a look-up , I would be so grateful.
    Thanks.

    Your dataflow should look like this :
    1) Source = the SQL transform with date_from, date_to and ID as columns.
    2) Next add a query (copy all columns from schema in to schema out) and set date_from and date_to as keys. Also make sure column names exactly match the column names in your target table, if not rename them in this query.
    3) Add a Map_Operation transform that maps all "normal" operation codes to "update"
    4) Finally add your target table and in the properties/options set "use input keys" to yes (or checked).
    This will generate UPDATE statements for all columns used in the query with a WHERE clause based on the keys defined in the query (date_from, date_to).
    Ben.

  • Updating the column of a table

    Hello Gurur,
    I have two tables they are
    Test & emp_op
    Desc  empop
    - empid
    -id_num
    -node_num
    _Desc Test
    -id_num
    -node_num
    -name
    -addr
    -empid
    Now i m trying to update the column empid in test table, copying as it is from empid column of emp_op table . Below is the query i have wriiten to update
    update test e
    set e.empid = (select t.empid from emp_op t
    where t.id_num = e.id_num and
    t.node_num = e.node_num );
    But it gives me an error ORA-01427: single-row subquery returns more than one row. any idea why ??
    if not, is there is any way i can accomplish this task in a different way ??
    Thank you so much. I appriciate it!!

    Hi,
    That means some row (maybe more than one) in test matches two or more rows in emp_op.
    What do you want to do in that case? Post some sample data (from both tables, relevant columns only) and the results you want to see in test after the UPDATE.
    If you know that all the matching rows in emp_op will have the same empid, you can just change SELECT in the sub-query to SELECT DISTINCT .

  • Navigation to update a column in the table jtf.jtf_rs_resource_extns

    Hi All,
    I'm using oracle 11.5.10
    Can somebody tell me the frontend form which is related to the table jtf.jtf_rs_resource_extns
    I need to update a column in the above table from the frontend.
    Please explain me the navigation for doing the same
    Regards,
    Mohan

    I can't tell you the answer to your query but what I can tell you is that you have logged the thread in a wrong forum. As far as my knowledge goes, this table does not delong to HRMS.
    Just check the product in which you are working and then log the thread in the right forum.
    Thanks,

  • How to update old instances with values

    Hi,
    i am using albpm 5.7 version.
    i have a requirement i need to update the oldinstances with updated data.
    suppose i have added new external variable to process how it will update the old instances.
    plz suggest how to solve this problem.
    Regards,
    Srinivas.

    Hi,
    The standard behaviour is that new instances of the process will use the most recent version of the process that has been deployed to the database. This allows you to deploy new versions of the processes without impacting on processes which are already in progress.
    When the workflow engine determines what activity to run next in the process, the engine checks what the start date of the process instance was, so that it can check what version of the process was active at that time. If you update the start date for each running process, so that it reflects the date that you saved the most recent version of the flow, then the workflow engine will use the latest version instead of the version that it was running.
    This is not supported. I would never suggest that you do this in a production environment - it does not make sense to be making frequent changes to the process in a production environment, since there is no supported mechanism for forcing existing flows to use the new definition. The engine is designed specifically to run the same version of the process for the duration of the process instance - what you want to do is to blow this out of the water completely. If you do change this, then all timing that is recorded against the activities becomes useless, and the other impact on the workflow process us something that you would need to consider incredibly carefully before deciding whether you want to take the risk.
    HTH,
    Matt
    WorkflowFAQ.com - the ONLY independent resource for Oracle Workflow development
    Alpha review chapters from my book "Developing With Oracle Workflow" are available via my website http://www.workflowfaq.com
    Have you read the blog at http://thoughts.workflowfaq.com ?
    WorkflowFAQ support forum: http://forum.workflowfaq.com

  • Update a column of a table to a value fast. table size is 16gb

    hi guys,
    set indexes to unusable will make processing faster.
    What other ways to make it faster? Am currently using the below but taking very long.
    version: 10.2.0.4
    UPDATE PDF.TAB_REF SET CODE='F';
    thanks

    set indexes to unusable will make processing fasterOnly for indexes on "CODE". Indexes on other columns are not updated by this UPDATE statement so they do not need to be set to UNUSABLE.
    Now you've unnecessarily added the overhead of having to REBUILD each of those indexes !
    (And if you do have a single-column index on "CODE", you don't need it anymore so you should drop the index !)
    This would be a FullTableScan.
    How large is the table ? Most DBAs/Developers answer a question with "x million rows". But "x million rows of 100bytes each" is very different from "x million rows of 492bytes each" which is very different from "x million rows of 1304bytes each". The FullTableScan has to read all the blocks -- so the effort is relative to the number of blocks, not the number of rows.
    Have you monitored the update by querying V$SESSTAT, V$SESS_IO and V$TRANSACTION ?
    (I guess you are using OEM's display of "Long Running SQL operations" which is based on V$SESSION_LONGOPS).
    Hemant K Chitale

  • Stored Procedure for updating dynamic columns in a table

    I have a table with a lot of columns around 30ish
    Now I want to create a stored procedure that will update a specific column to a new value.
    I the @columname and @newvalue to be the parameters, and an addition @itemId for the WHERE clause so it will update that specific row/data only.
    here's my Stored Procedure
    USE [db]
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[usp_UpdateData]
    @itemID int,
    @ColumnName varchar(50),
    @newValue nvarchar(50)
    AS
    BEGIN
    Update dbo.ProjectAllocation
    Set @ColumnName = @newValue
    Where itemID = @itemID END
    When I pass the following
    @ColumnName: UserName
    @newValue: NewUserName
    @itemID: 1
    it doesnt update row with itemID = 1.
    How can I do this?
    ----------------------- Sharepoint Newbie

    Did you try my last post method. Its better to use parameterized approach.
    Anyway, if you want to change your code,you may need to change as below.....
    SET @sql = 'UPDATE dbo.table SET ' + @ColumnName + '=''' + @newValue + ''' WHERE [itemID] = ' + cast(@itemID as varchar(50));

Maybe you are looking for

  • No longer connects to my network automatically

    I've always been automatically connected to my AE network when logging on to my account or waking up from sleep while logged on but that's no longer true anymore. I now have to select the network from the airport icon in the menu bar. I'm not prompte

  • How do I stop Ical from stealing focus?

    Is anyone aware of a way to stop ical from stealing focus when events are created or modified?  I do not want to lose the ability to fast switch to the app when it is in another space. I have some individuals on my team at work who tend to edit multi

  • How to call WD ABAP screens in CE 7.3  Java webdynpro

    Hi, I have few developed applications in WD ABAP and I want use the same screen in Java WD using CE7.3 as a part of one  iview in a page. Which means I have one page which has 5 views and I would like to use one view - WD ABAP screen. How it is possi

  • 7.0.2. /  Copy and Paste Broken In Large .mp4

    I have a large .mp4 movie file. I should be able to select a small portion of it, copy, and then paste into a new QT player. When I do, instead of that happening, it oddly pastes in text from the last webpage I was at. I know... ***?!? Anyone have a

  • Is there any Security Feature available in any of ...

    Dear Everyone, very good day to you all Just checking for a security feature: 1. Is there a way to hide my Messages or can I set up a Personal password to prevent access from strangers? 2. Is there a way to hide my contacts list or can I set a passwo