Subselect in update

Hello,
i want to write an sql-update statement where a field through a part of another field will be supplemented.
example:
update tabelle set targetDirectiory = ' export/home/VALUE_FROM_FIELD x' where blablabla
This should work as a subselect ?but I do not know how i can merge the strings
Thanks a lot.
Lutz

It could have been better if you would have provided some supporting data. Anyway
You can do it like
UPDATE emp       e
   SET dept_name = 'DEPT-'||(SELECT d.dept_name
                               FROM dept          d
                              WHERE d.dept_id     = e.dept_id
WHERE blahblahblah;Regards
Arun

Similar Messages

  • Nested Subselect in UPDATE statement

    Hi everybody,
    I have the following problem: There are two tables FOO and BAR that both have columns X and Y and a primary key. I want to fill the values X and Y of FOO with the values X and Y from BAR where FOO.key = BAR.key . There may be multiple rows from BAR with the same key so I simply select the first one. The query would look like
    UPDATE foo f
       SET ( x, y ) = ( SELECT *
                          FROM ( SELECT b.x, b.y
                                   FROM bar b
                                  WHERE f.key = b.key )                    
                         WHERE ROWNUM = 1 );However, this doesn't work because the alias F is not known inside the nested subquery. If I remove the outer subquery ( the one with ROWNUM=1 ) it works fine. But I need to limit the result to a single row ( in the real application I sort the innermost query by date ). Why does Oracle forget the meaning of alias F within the nested subquery?
    Pat

    Hi, Pat,
    A subquery can be correlated only to its immediate parent query, not its grandparent.
    You can get the results you want using MERGE instead of UPDATE.
    You can also get the same results with only one sub-query, something like this:
    UPDATE foo f
       SET ( x, y ) = ( SELECT MAX (x) KEEP (DENSE_RANK LAST ORDER BY a_date)
                               ,        MAX (y) KEEP (DENSE_RANK LAST ORDER BY a_date)
                  FROM   bar
                  WHERE  key     = f.key
                );I suspect MERGE will be more efficient.
    Edited by: Frank Kulash on Mar 9, 2010 11:02 AM

  • For r in (select) loop: execution plan question

    Hi there,
    I have a procedure which does the following (on Oracle 11.1.0.7):
    begin
      for r in (select col1,max(col2) as col2 from tab@remote_db group by col1 ) loop
        update tab2
           set col_a = r.co1
           where col_b = r.col2;
        commit;
      end loop;
    end;The subselect from the remote table delivers about 4000 rows.
    When executing fast, the procedure runs about 20 seconds, the trace shows that the select is executed 1 time, fetches 49 times. The update executes 4000 times.
    When executing slow, the procedure runs about 20 minutes (!), the trace shows that the select is executed 1 times, fetches 4000 times. The update executes 4000 times.
    This happens without changing the code, from the same client (sqlplus on the server, same version as database).
    Can anyone probably give me a clue how I could track down the plsql execution steps like the optimizer trace that let you see why a certain sqlplan was not taken or what might cause that change in behavior?
    I cannot produce that behavior at will - most times the procedure runs fast.
    thanks,
    Heimo

    Hi again,
    regarding the "faulty test" and what is fastest: user tested both versions and came up with the for-loop to satisfy him best. I would, of course, utilize event 10046 and tkprof and a repeatable dataset to have solid data. Sorry for not setting enough emphasis on my real question, which is described in the following.
    But, and that is what is really causing awkward feelings for me: when doing plain sql, I can use events 10046, 10053 and learn from the tracefiles why a decision was taken (now that is making me feel good, actually). But when it comes to plsql, I have not yet such a handy toolset that helps me understand what influences the plsql-engine to go this or that way.
    Thus, I valued the posts pointing to dbms_trace and plsql_optimization_level as helpful answers.
    Because of that I learned about the views %_PLSQL_OBJECT_SETTINGS and remembered to check for other plsql-initora settings.
    I also verified that neither the 10046 nor the 10053 trace files contain any reference to plsql-parameters/settings, and that the 10053 trace only shows the subselect and update, but no info if it would "bulkify" or not.
    Meanwhile I did start to utilize dbms_trace (which causes the statement to go the unbulkifyed by the way) and maybe I can learn from that output or from following posts?
    best regards
    Heimo

  • UPDATE with subselect

    I'm trying to write an update statement using a subselect. I'm comfortable doing this in MS SQL, but am new to Oracle.
    Can someone please show me why my DDL is not liked? I'm getting an error "SQL command not properly ended".
    Any help would be appreciated.
    Thank you.
    Robert
    DDL:
    update lai
    set registrationEndDate=firstMeeting-2
    from
    (select laim.learningActivityInstanceID,
         min(meetingStart) as firstMeeting
         from DRlearningActivityInstance lai
         inner join drLAInstanceMeeting laim
         on lai.id=laim.learningActivityInstanceID
         group by laim.learningActivityInstanceID) A,
         drLearningActivityInstance lai
         where a.learningActivityInstanceID= lai.id

    Not sure to understand what your update should do, but the correct syntax could be something like :
    update drLearningActivityInstance lai
    set registrationEndDate=
    (select min(meetingStart) -2
    from drLAInstanceMeeting laim
    where lai.id=laim.learningActivityInstanceID
    group by laim.learningActivityInstanceID)
    where lai.id = <value>;
    Without the where condition with an external value, all drLearningActivityInstance rows would be updated.
    See [url http://download-west.oracle.com/docs/cd/B14117_01/server.101/b10759/statements_10007.htm#sthref7335]UPDATE documentation
    By the way, UPDATE is a DML, not a DDL.

  • Using NVL function in subselect of an update

    Hi,
    nvl is not working in my situation
    Here is my select
    SELECT nvl(a.id, 'WAS NULL') FROM table_1 a, table_2 b
    WHERE a.id=b.id;
    Now here I get NULL instead of 'WAS NULL' as I accepted.
    Table a and table b do not have any identical ids, still I need to be a value returned.
    Is there a way?
    Thanks

    Well this works for me:
    SQL> CREATE TABLE table_1 (id INT NOT NULL, val VARCHAR2(10) NOT NULL);
    Table created.
    SQL> CREATE TABLE table_2 (id INT NOT NULL, val VARCHAR2(10) NOT NULL);
    Table created.
    SQL> INSERT INTO table_1 VALUES (1, 'A');
    1 row created.
    SQL> INSERT INTO table_2 VALUES (2, 'B');
    1 row created.
    SQL> UPDATE table_1 t1
      2  SET    val =
      3         ( SELECT NVL(t2.val,'Was NULL') FROM table_2 t2
      4           WHERE  t2.id = t1.id );
    SET    val =
    ERROR at line 2:
    ORA-01407: cannot update ("WILLIAM"."TABLE_1"."VAL") to NULL
    SQL> UPDATE table_1 t1
      2  SET    val =
      3         NVL
      4         ( ( SELECT t2.val
      5             FROM   table_2 t2
      6             WHERE  t2.id = t1.id )
      7         , 'Was NULL');
    1 row updated.
    SQL> SELECT * FROM table_1;
            ID VAL
             1 Was NULL
    1 row selected.

  • Help in update instruction, please

    hi,
    i can't make progress in my update instruction and need some help. Oracle makes an ora-00907 message and says that a bracket is missing but in this case it doesn't make sense.
    update DM_MESSDATEN
    set DM_MESSDATEN.FAUNA_ID=1 where MISSION_ID in (select DM_MESSDATEN.MISSION_ID from
    DM_MISSION, DM_MESSDATEN where DM_MISSION.MISSION_ID=DM_MISSION.MISSION_ID AND
    measure_name='Transit CT-WB' AND DM_MESSDATEN.FAUNA_ID=999999 AND rownum <2 order by mission_id);
    i used this as standalone and it works fine but within update i need a subselect and can't use this join,
    select DM_MESSDATEN.MISSION_ID from
    DM_MISSION, DM_MESSDATEN where DM_MISSION.MISSION_ID=DM_MISSION.MISSION_ID AND
    measure_name='Transit CT-WB' AND DM_MESSDATEN.FAUNA_ID=999999 AND rownum <2 order by mission_id;

    Furthrmore, I don't understand your query :
    You wrote :
    update DM_MESSDATEN
    set DM_MESSDATEN.FAUNA_ID=1
    where MISSION_ID in (select DM_MESSDATEN.MISSION_ID
                         from   DM_MISSION, DM_MESSDATEN
                         where  DM_MISSION.MISSION_ID=DM_MISSION.MISSION_ID
                         AND    measure_name='Transit CT-WB'
                         AND    DM_MESSDATEN.FAUNA_ID=999999
                         AND rownum <2But where DM_MISSION.MISSION_ID=DM_MISSION.MISSION_ID seems always true, so why add this one ? Or is it a mistake ?
    That's not very clear in my head...
    Nicolas.

  • Subselect in EJB 2.1

    Hi,
    what's the best way to do a query like this
    UPDATE
       table
    WHERE id = (
       SELECT
          id
       FROM
          table
       WHERE
          <condition>
       ORDER BY id
       LIMIT 1
    )in EJB 2.1 while taking into consideration that subselects are not transaction safe? If you have any idea, please tell me :-)
    Thanks
    -Danny

    Hm... looks, better, right! :)
    But I guess this can't be done using EJBQL. Is is race condition safe to
    write a finder with the join part like this:
    SELECT OBJECT(a) FROM tableA AS a, tableB as B
    WHERE a.id = b.id AND a.reservedForID = 0 AND b.<col> = <condition>and then do a
    TableAValue aVal= aLocal.findBy...();
    aVal.setReservedForID(id);
    aLocal.update(aVal);without havind a second thread finding the exact same entry? Is it correct,
    that the container has to lock the entry that is returned?

  • Update with join

    Hello Everybody
    I have 3 tables in a maxdb 7.6 database
    rbarbeitsplanpos key=rbarbeitsplanposid column gewichtung,...
    rbaplposausf key=rbaplposausfid columns rbarbeitsplanposid,...
    rbqspruefpos key=rbqspruefposid columns rbaplposausfid,gewichtung,...
    Now i want to update gewichtung in rbqspruefpos with the value of gewichtung in the corresponding record in rbarbeitsplanpos.
    The way to find the correct value is:
    From rbqspruefpos with rbaplposausfid into rbaplposausf  
    From rbaplposausf with rbarbeitsplanposid to rbarbeitsplanpos
    I found this hit:
    A simple example of the power of including joins in an Update Statement:
    Update Tbl1 set tbl1.field1=tbl2.field2*.10,
    from Tbl1 join tbl2 on tbl1.PKfield=tbl2.tbl1FK
    This will update all the joined rows in tbl1 to 10% of the values in tbl2.
    I code:
    update rbqspruefpos set gewichtung =  rbarbeitsplanpos.gewichtung,
    from rbqspruefpos
    join  rbaplposausf on rbqspruefpos.rbaplposausfid = rbaplposausf.rbaplposausfid
    join rbarbeitsplanpos on rbarbeitsplanpos.rbarbeitsplanposid = rbaplposausf.rbarbeitsplanposid
    General error;-5016 POS(73) Missing delimiter: =
    This one works without errors:
    update rbqspruefpos set gewichtung = (select rbarbeitsplanpos.gewichtung  from rbarbeitsplanpos
    join  rbaplposausf on rbarbeitsplanpos.rbarbeitsplanposid = rbaplposausf.rbarbeitsplanposid
    join rbqspruefpos on rbqspruefpos.rbaplposausfid = rbaplposausf.rbaplposausfid)
    but all rbqspruefpos.gewichtung are filled with the same value?
    The first value found in rbarbeitsplanpos.
    Any help welcomed
    Best regards
    Albert

    > I code:
    > update rbqspruefpos set gewichtung =  rbarbeitsplanpos.gewichtung,
    > from rbqspruefpos
    > join  rbaplposausf on rbqspruefpos.rbaplposausfid = rbaplposausf.rbaplposausfid
    > join rbarbeitsplanpos on rbarbeitsplanpos.rbarbeitsplanposid = rbaplposausf.rbarbeitsplanposid
    >
    >  General error;-5016 POS(73) Missing delimiter: =
    >
    >
    > This one works without errors:
    > update rbqspruefpos set gewichtung = (select rbarbeitsplanpos.gewichtung  from rbarbeitsplanpos
    > join  rbaplposausf on rbarbeitsplanpos.rbarbeitsplanposid = rbaplposausf.rbarbeitsplanposid
    > join rbqspruefpos on rbqspruefpos.rbaplposausfid = rbaplposausf.rbaplposausfid)
    >
    > but all rbqspruefpos.gewichtung are filled with the same value?
    > The first value found in rbarbeitsplanpos.
    Looks like you're doing it wrong.
    Subselects need to be enclosed in brackets.
    See [Subquery (subquery)|http://maxdb.sap.com/doc/7_6/60/515f3eca2a11d2a97100a0c9449261/content.htm]
    Only scalar subselects (these are the ones that by their very structure can only produce zero or one rows in the result set) can omit the brackets.
    The database cannot know that there is only one value in this column - you may try and put a aggregation function round it.
    regards,
    Lars

  • Update a subst() with other substr() value from same row

    Oracle 10.2.4.0
    Given table MYTEST:
    Name                                      Null?    Type
    NAME_IND                                           VARCHAR2(15)
    LOCAL_DATA                                         VARCHAR2(30)need to update every row, effectivley doing something like this:
    update mytest
    set substr(local_data,1,4) = substr(local_data,27,30)Obviously that code doesn't actually work, but at least implies what I need to do, and am having a hard time getting my head wrapped around exactly how to make it happen.
    Expected input would be like:
    NAME_IND        LOCAL_DATA                    
    bert            12345678901234567890123456AAAA
    bigbird         12345678901234567890123456BBBB
    ernie           12345678901234567890123456CCCC and expected result would be
    NAME_IND        LOCAL_DATA                    
    bert            AAAA5678901234567890123456AAAA
    bigbird         BBBB5678901234567890123456BBBB
    ernie           CCCC5678901234567890123456CCCC

    Frank Kulash wrote:
    Hi,
    In the SET clause of an UPDATE statement, the items to the left of the = signs must be columns in your table.
    If you want to change local_data, in whole, or in part, then you say
    SET  local_data = ...Now, what is the value to which you want to set it? If I understand correctly, it's the concatenation of two things
    (1) The 4 characters starting a position 27 of the original local_data, and
    (2) the part of the original local_data starting at position 5
    The way to code that is
    UPDATE  mytest
    SET     local_data = SUBSTR (local_data, 27, 4)
                || SUBSTR (local_data, 5)Remember, the 3rd argument to SUBSTR is the length of the substring you want to extract, not the ending position.Right. Actually I had thought of that, but for some reason was thinking there would need to be a subselect, or even possibly an anonymous block of PL/SQL to get the value of the substr()'s for the 'current' row. After posting, shutting down, and heading home, my head cleared a bit and so was all set to give it a try, and it was exactly what I needed. Thanks for the lead.

  • Automatically Update a UDF in the Item Master

    Hi Experts,
    I am new to SAP Business One. I need to update automatically the value of a UDF. The value will be calculated using data from related tables. Calculation includes -summation, divide and minus etc. Could you provide guide.
    For example a new UDF should contain the suggested quantity to order in the Item Master Data. This is calculated considering the running average sales quantity as of current time for this month and deduct the available quantity on hand and also deduct the quantity already ordered (arriving soon to be delivered to warehouse).
    Formula:      =  ( S / N ) * D - ( OnHand ) - ( Ordered )
    where   S = Quantity sold so far within this month
                  N = days count ( if today is March 18, N = 18 )
                  D = number of  days for this month.  (can be 28, 30 or 31 days)
    This means that the data in the database must also be updated. I appreciate your input.
    If possible, the OITW, MinOrder will be updated instead of a UDF.

    Haven't tested it properly, but something like this....
    select
    (s0.qty / datepart(day,getdate())) * datepart(day,(DateAdd(day, -1, DateAdd(month, DateDiff(month, 0, getdate())+1, 0)))) - t0.onhand - t0.onorder
    from
    oitm t0
    left join
    (select     t0.itemcode,
              sum(t0.quantity) as qty
              from inv1 t0
              inner join
              oinv t1
              on t0.docentry = t1.docentry
              where datepart(month,t1.docdate) = datepart(month,getdate())
              and datepart(year,t1.docdate) = datepart(year,getdate())
              group by t0.itemcode) s0
    on t0.itemcode = s0.itemcode
    where t0.itemcode = $[OITM.ITEMCODE]
    Currently this adds up the qty from all invoices, if you want to subtract credit notes you just have to build in a second subselect from ORIN and RIN1 and subtract them off.
    Hope this helps.

  • Update  returned more then one row

    Hi ,
    Can you help me with this?
    I have the following:
    update admuser.udfvalue
    set udf_number=
    (select sum(nvl(uv.udf_number,0))
    from admuser.projwbs pw, admuser.udfvalue uv
    where pw.proj_id=uv.proj_id
    group by pw.proj_id, pw.parent_wbs_id, pw.phase_id,
    uv.proj_id,pw.wbs_name, pw.wbs_name)
    where proj_id = any
    (select pw.proj_id
    from admuser.projwbs pw, admuser.udfvalue uv
    where pw.proj_id=uv.proj_id
    group by pw.proj_id, pw.parent_wbs_id, pw.phase_id,
    uv.proj_id,pw.wbs_name, pw.wbs_name)
    and the error: ERROR at line 3:
    ORA-01427: single-row subquery returns more than one row
    thank you

    Hi,
    You subselect isn't linked to your target table,
    update admuser.udfvalue target
       set udf_number =
              (  select sum(nvl(uv.udf_number, 0))
                   from admuser.projwbs pw
                  where pw.proj_id = target.proj_id
               group by pw.proj_id
                       ,pw.parent_wbs_id
                       ,pw.phase_id
                       ,pw.proj_id
                       ,pw.wbs_name
                       ,pw.wbs_name)
    where proj_id = any (  select pw.proj_id
                              from admuser.projwbs pw, admuser.udfvalue uv
                             where pw.proj_id = uv.proj_id
                          group by pw.proj_id
                                  ,pw.parent_wbs_id
                                  ,pw.phase_id
                                  ,uv.proj_id
                                  ,pw.wbs_name
                                  ,pw.wbs_name);Regards
    Peter

  • What is a easy way to update colors in a FW design?

    Hello is it possible to use Fireworks swatch to update colors at once?
    In this example if I want to update the color #9A6600 I must update the menu buttons submenu and the text (the origal contains more items)
    For recurring items I am using the style option but every style has one of the basic colors of the thema.

    Interesting question!
    Styles are like symbols. If you change a style definition, you can update all instances of that style on the canvas. So one way to change color quickly across multiple objects would be to select an object with a style attached to it, change its fill color, and then click the Redefine Style button in the Properties panel. All the instances of that style will be changed to reflect the new fill color.
    But there are other ways to change the fill or stroke colors of multiple objects. Simply selecting multiple objects on the canvas or in the Layers panel and then choosing the desired fill or stroke color will work. On the canvas, Shift-click or click-and-drag to select multiple objects using the Pointer tool (or the Subselection tool if an item belongs to a group). In the Layers panel, selecting a layer/folder will select all the objects in that layer; Shift-click or Command-click can also be used to select multiple objects or layers.
    The one caveat to the above suggestions are Symbols. Symbol instances are easy to update in and of themselves by editing the Symbol, but they're somewhat separated from other items on the canvas. For example, you cannot directly change their fill or stroke color on the canvas, and styles contained within Symbols won't automatically update themselves the way they will for other objects.

  • Tecra M9-136 - BSOD during Vista SP2 update

    Tecra M9-136 asked this morning to update to Vista SP2 and during the process the BSOD 0x0000007E arrived. Restarted in Safe Mode and the installer continued and then finally reported that the update had failed - and reverted to SP1. This took most of the morning.
    It will start in Safe Mode but on a normal boot-up, Vista SP1 gets through the fingerprint recognition and then fails with the same BSOD (it doesn't get as far as displaying the desktop).
    The laptop has BIOS level 1.80. I've tried in Safe mode to install 1.90 but it tells me that the battery has insufficient charge and the power adapter isn't attached. Both untrue.
    Stuck - need advice. Could this be a hard fault? Can't see how I can update anything if it's a soft fault.
    thanks

    The message with the BSOD mentioned checking BIOS and driver versions. Anyway, no change made to that.,
    I tried System Restore but the only available restore point was the SP2 installation. I thought Vista was supposed to save a restore point every 24 hours even if nothing new had been installed.
    I've now found in System Information / Windows Error Reporting several messages like this:
    28/09/2009 12:08 Windows Error Reporting Fault bucket 0x7E_NULL_IP_DRVNDDM+57bd, type 0&#x000d;&#x000a;Event Name: BlueScreen&#x000d;&#x000a;Response: None&#x000d;&#x000a;Cab Id: 0&#x000d;&#x000a;&#x000d;&#x000a;Problem signature:&#x000d;&#x000a;P1: &#x000d;&#x000a;P2: &#x000d;&#x000a;P3: &#x000d;&#x000a;P4: &#x000d;&#x000a;P5: &#x000d;&#x000a;P6: &#x000d;&#x000a;P7: &#x000d;&#x000a;P8: &#x000d;&#x000a;P9: &#x000d;&#x000a;P10: &#x000d;&#x000a;&#x000d;&#x000a;Attached files:&#x000d;&#x000a;C:\Windows\Minidump\Mini0928 09-04.dmp&#x000d;&#x000a;C:\Users\me\AppData\Local\Te mp\WER-75660-0.sysdata.xml&#x000d;&#x000a;C:\Users\me\AppData\L ocal\Temp\WER7D78.tmp.version.txt&#x000d;&#x000a;& #x000d;&#x000a;These files may be available here:&#x000d;&#x000a;C:\Users\me\AppData\Local\Mic rosoft\Windows\WER\ReportArchive\Report06d1c4b5

  • Cannot open and update IPhoto after upgrading to OXYosemite

    From the App store, I downloaded and installed OXYosemite. There are 2 more updates available: iPhoto and iMovie. When I try to upload them, the notice I get is "Update Unavailable with This Apple ID  This update is not available for this Apple ID either because it was bought by a different user or the item was refunded or cancelled."
    I have 2 apple IDs when I inquire about my ids. Signing in App Store with either of them, doesn't resolve the problem. I get the same notice. iTunes, Mac, mobile downloads, all use the same apple IP, only for the computer downloads from App Store isn't working.
    What should I do?
    Thanks, Sev

    I have the same problem and can't find out how to correct it.  Unable to update iPhoto or iMovie .. I get the same message as above user.  Help!

  • Error message: "playlists selected for updating no longer exist"

    I tried to update my ipod nano and I guess I had deleted a playlist, but since then, I have not been able to update. Every time I try, I get the following message:
    "Cannot be updated because all of the playlists selected for updating no longer exist."
    I haven't been able to highlight which playlists are selected to begin with.
    I read through the manual and thought that maybe rebooting the whole system might work. So I deleted Itunes from my computer and re-installed.
    Then I tried re-setting my ipod. So now I have nothing on my ipod.
    I also deleted everything from my library, thinking it might help to start from scratch. Nothing has worked.
    How do I "select" and "unselect" playlists so I can get up and running again?

    Here you go.
    http://discussions.apple.com/thread.jspa?messageID=607312&#607312

Maybe you are looking for

  • Table required for billing and RG1 output

    Dear all, pls give me the list of tables required for billing output and RG1 output

  • Process for tds receivable posting

    hi all what is the process for tds receivable configuration in sap and how do we post tds receivable in sap. please let me know the process of customer tds receivable configuration in sap and posting through fb70 Kind regards sap fico arman

  • Moving iWeb data from one computer to another

    I have an iWeb site on my old mac lap top. I can not get the data to transfer to the new laptop. How do I move all iweb entries from one computer to another?

  • After like 10 minutes internet stops working

    okay so this all started when i updated to dp 3 or something, then the internet started acting up.....no matter if i update or not (this has been going on for like a month, and i'm on the actual release of yosemite) it keeps on doing this stuff where

  • Tabbed Panels Bug

    I've created a three tab panel using the widget, and put text in each of the three panels. It displays correctly in Design Mode, but when I switch to Preview or export the html to view in browser, the panels only display the center panel's text, no m