Optimization of an update that uses multiple selects on the same table

Oracle version : 10g
Hello,
I have created an UPDATE statement which uses two selects on a single table to do an update according to date criteria.
Due to the fact that the update has different criteria for updating according to whether the date falls within one of two ranges
(future or past) two selects were used together with a union between them to unite the results.
The end result is of course two full table scans and a poorly performing execution.
The goal is to update a field XDEL (type number) based on a date column value (column XDATE) where the dates of interest
fall both in the past (less than sysdate minus 45 days) and in the future (greater than sysdate +90 days). For records with XDATE
values within these ranges, I wish to set field XDEL=1
For records in the future (>=sysdate+90):
for a unique combination of XNAME+XCODE, where XDATE is within the date range for update, set XDEL=1
but for a non-unique combination of XNAME+XCODE+XDATE, update XDEL=1 only for the 'oldest' future record, ie update XDEL for MIN(XDATE) only
For records in the future (< sysdate+45):
for a unique combination of XNAME+XCODE, where XDATE is within the date range for update, set XDEL=1
for a non-unique combination of XNAME+XCODE, update XDEL=1 only for the 'newest' past record, ie update XDEL for MAX(XDATE) only
The combination of XNAME+XCODE XDATE is unique. As an example of the 'in the past' scenario:
XNAME | XCODE | XDATE
================
1. AAAA ~ 002 ~ 01/01/2006
2. AAAA ~ 002 ~ 02/01/2006
3. AAAA ~ 002 ~ 03/01/2006
4. XXXX ~ 123 ~ 02/01/2006
Here, we would update XDEL in record 3. as it corresponds to MAX(XDATE) for the GROUP AAA002 (and we would also update record 4. as a unique record that meets the criteria)
As an example of the 'in the future' scenario:
XNAME | XCODE | XDATE
================
1. HHHH ~ 002 ~ 01/01/2011
2. HHHH ~ 002 ~ 02/01/2011
3. HHHH ~ 002 ~ 03/01/2011
4. XXXX ~ 123 ~ 02/01/2011
Here, we would update XDEL in record 1. as it corresponds to MIN(XDATE) for the GROUP HHHH002 (and of course 4. as a unique record that meets the criteria)
Here is a query that works, but is slow:
UPDATE TAB1 SET XDEL=1 WHERE (XNAME,XCODE,XDATE) IN ((SELECT XNAME,XCODE,max(XDATE) FROM TAB1 WHERE XDATE < sysdate-45 GROUP BY XNAME,XCODE) UNION (SELECT XNAME,XCODE,min(XDATE) from TAB1 WHERE XDATE >= sysdate+90 GROUP BY XNAME,XADDR));
XDATE is a DATE type
XCODE and XADDR are VARCHAR2
XDEL is number type
Any ideas would be greatly appreciated.

Here is a suggestion. The code is not tested.
update tab1 t1
   set xdel = 1
where exists (select null
                 from (
                        select xname,
                               xcode,
                               max(case when xdate < sysdate-45 then xdate else null end) xdate1,
                               min(case when xdate >= sysdate+90 then xdate else null end) xdate2
                          from tab1
                         group by xname, xcode
                      ) t
                where t1.xname = t.xname
                  and t1.xcode = t.xcode
                  and (t1.xdate = t.xdate1 or t1.xdate = t.xdate2))

Similar Messages

  • Using multiple ipods on the same cpu

    my little brother & older sister just got new ipod videos and while i have an ipod photo i need to know if any1 can tell me how to set it up so i can use multiple ipods on the same (windows) computer without creating multiple user accounts if its even possible

    Hello,
    We have three ipods in our home - new g5 (mine) and 2 minis. We all use the same computers. Basically our library contains around 15gb of music (everyones).
    We have individual play lists - mine: good music; daughters rap or thumping stuff - lol.
    When you first plug your new pods on you get a screen up which asks you what you want to do (its in preferences usually). Chose the option to automatically update the following playlists and select which one you want to match with that particular pod. My youngest daughter has a few playlists i.e on the go, chill etc. so she selects around 4. I have one, and my elder daughter has a couple.
    Its easy to do (especially if I could work it out). Good luck.

  • Use multiple themes in the same project?

    I'm making a slideshow in iMovie 09. It consists of approx. 200 pictures. Those 200 pics are then broken down into 5 distinct groups. I've applied the Scrapbook theme to the first 40 pictures. I tried to apply a different theme (Filmstrip) to the next 30 pictures. When I did that, however, it changed the theme for the original 40 pictures to Filmstrip as well.
    Am I able to use multiple themes within the same project? I don't think its possible.
    Is my solution to make the 5 sections of the slideshow in iMovie 09 using a different theme for each section? I'd export as a movie file and then create the final slideshow that would consist of the 5 movies previously made (each with a different theme).
    Thanks in advance. This project is due in 3 weeks.
    Martin

    This is not possible in iMovie (to use multiple themes).
    However, you can do this using your idea of joining multiple movies into one. You can do this with QuickTime Pro, or with MPEG Streamclip. [Here is a video Tutorial by venerable forum member Jon Walker|http://web.me.com/jrwalker4/QuickNotes/MPEGStreamclip/Entries/2008/5/25_Tutorial015.html] which shows the MPEG Streamclip option.

  • Using multiple timer in the same SessionBean

    Hello,
    Is it possible to use multiple timer in the same Stateless Session Bean. In my application a user can schedule some task to execute. To do so I was thinking of creating a Session Bean which would create calendar timer on user request and, when one of the timer expires, retrieve the task to execute thanks to the information stored in the timer.
    When I tried the solution explained above, it seems that the @timeout method is synchronized on 1 timer. For example if I create a timer that will be executed every 10 seconds and another one executed every 30 seconds, the timeout callback is called every 30 seconds but 4 times.
    My code looks like that :
    @Stateless
    @LocalBean
    public class TimeManager {
        public void onUserRequest(ScheduleExpression expression) {
            Timer timer = timerService.createCalendarTimer(expression, timerCfg);
        @Timeout
        void timeout(Timer timer) {
            logger.log(Level.INFO, (String) timer.getInfo());
    }Is there a way to do what I want?
    Thank you

    This doesn't make any sense to me. If i were to write a bunch of schemas for a particular applicaion, would
    I have them all in the same namespace? You would normally have one schema that describes the information model associated with the one namespace that the different documents in your application use.
    If so, why can't I load more than one in the same name space?The parser chooses the schema based on the namespace alone. There is no other information used to decide which schema to use, so you can only have one schema for the namespace.
    They all have different root elements.You can have different root elements in the one schema.
    I don't even need the namespaces, but I can't
    figure out how to get rid of them (the schema isn't valid with out them according to XML Spy). You can set the schema explicitily before parsing, but not (AFAIK) set after parsing has begun, except by using the mapping of namespace to schema location.
    I have also tried to use the external-noNameSpaceSchemaLocationproperty, but it doesn't seem like you can pass in an array of schemas to that one. It only expects a
    String as the Object you pass in to setProperty. Yes, you can only validate a document against the one schema.
    So, how can I load all my schemas so I don't have to reference them in the XML documents? Either combine your schemas so you have one schema for your namespace that validates elements which are defined in that namespace (the formal/correct way of doing it), or construct a filter that inserts a PI to point to the schema once the root element is opened (the pragmatic/bit of a hack way of doing it).
    Pete

  • Can I use multiple iPhones on the same iTunes account? e.g. my wife and I each have iPhones

    can I use multiple iPhones on the same iTunes account? e.g. my wife and I each have iPhones

    Yes, you can have as many devices - iPhones, iPods, iPads - as you like using the same iTunes account.

  • How to use multiple proxies at the same time?

    im planning to use multiple proxies at the same time on mac but i have no idea how to do it?!. i need help!thanks!

  • How to use multiple Interfaces for the same BS?

    Hi @ ,
    Is it possible to have a scenarion where i am using multiple interfaces in the same BS based upon some conditional field in the message.
    I amnot able to get the solution I know with condition editor I can have multiple receivers but in my scenarion based upon message fiels i have to decide which BAPI to be used and wht mapping and then post it to the same System
    Any help will be highly rewarded
    Regards

    Hi-
    Yes it is possible you can use multimapping for mapping the interfaces.
    To know more about multimapping see
    http://help.sap.com/saphelp_nw04/helpdata/en/21/6faf35c2d74295a3cb97f6f3ccf43c/content.htm
    Some more helpful links
    /people/jin.shin/blog/2006/02/07/multi-mapping-without-bpm--yes-it146s-possible

  • I want to use multiple colors in the same box - Pantone plus process. I am trying to create a support plate of cyan under a PMS.

    I want to use multiple colors in the same box - Pantone plus process. I am trying to create a support plate of cyan under a PMS.

    How is the external drive formatted?
    Allan

  • Can I use multiple SSIDs on the same intranet in close proximity?

    Can Multiple APs running the same or different channels be used with different SSIDs to create seperate wireless networks on the same intranet?
    Example: 4 APs running on the same floor of a small building, 2 APs using SSID named ABC using channels 1 &6. The other 2 APs using SSID named XYZ using channels 1 & 6 or even 6 & 11.
    Will this scenario work to create two seperate wireless networks on the same intranet or will this cause problems with all wireless traffic?

    For you to understand, the channel is a subdivision of the "physical" medium. The SSID is a logical subdivision that is stacked on the physical medium/frequency/channel.
    You can run several "logical" networks (based on different SSID) on one single (physical) channel/frequency. Clients of each "logical" network won't see and won't be able to talk (radio level) with the clients of the other "logical network" /SSID. However, if they operate on the same channel/frequency, they will interfere and your throughput will be affected since they nevertheless share the same (physical) frequency.
    It's very similar to the difference between IP addresses and MAC addresses. You may have 2 stations in the same "collision domain" (MAC level; Physical network; subject to collision with each other packets) while they can't speak together without a router because on an IP standpoint they are not in the same subnet (logical network).
    So, your solution will work, both networks will be independent at a logical level, but when both 'logical networks" share the same frequency ("collision domain(!)") the throughput will be affected subsequently (all stations of both "logical networks" are operating on the same frequency/channel).
    Guy

  • Can Numbers Display Multiple Views of the Same Table

    Hi,
    Excel and Appleworks both have a pull down tab on the vertical bar allowing multiple views into the same spreadsheet (table). Can Numbers do this?
    I have a set of calculations at the top of a spreadsheet that are based on years and years worth of data under the calculations (same column). I add data for each new event (the rows) and watch the calculations at the top of the data. Easy to do in Excel or Appleworks, but, I can't figure out how to do this in Numbers.
    Example:
    Spot1 Spot2
    Total 15 36
    Avg 5 12
    Jan 09 5 10
    Feb 09 6 20
    Mar 09 4 6
    Apr 09
    So... does Numbers allow the view "split" or multiple views that Excel and Appleworks allow?
    Thanks!
    Tom

    Question asked and responded several times:
    feature unavailable.
    For multiple views of a table there is an easy workaround as we may build a table whose every cells grab their contents from the 'master' one.
    _Go to "Provide Numbers Feedback" in the "Numbers" menu_, describe what you wish.
    Then, cross your fingers, and wait _at least_ for iWork'10
    Yvan KOENIG (VALLAURIS, France) mardi 1 septembre 2009 21:56:42

  • Using multiple ipods on the same computer

    I have three ipods in the family. Is it possible to have three different libraries that can sync when each different ipod is connected? At the moment. my libray syncs with al three.

    There are basically three ways of using multiple iPods on a computer and these involve:
    a) Sharing a single iTunes library
    b) Creating Multiple Libraries in a single user account
    c) Creating multiple user accounts.
    Note: When you are sharing an iTunes library, you don't have to set each iPod to update in the same manner, you can mix and match from the options below as each iPod has it's own update settings
    Sharing a Library and/or User Account
    If you want to share the one library, you can set either or all of the iPods so that they only get updated with only certain playlists (you can update from more than one if you wish): Loading songs onto iPod automatically - Windows
    Choosing the update option "Sync Music - Selected playlists" allows you to create a playlist specifically for the iPod and drag the tracks you want into it. If you tire of the list and want to change it, you just add or remove the songs you don't want. The ones you take out out remain in the library to be used some other time if you choose. You can read more about playlists at these links:
    iTunes: Creating playlists of your favorite songs
    How to create a Smart Playlist with iTunes
    Or you can choose to update any or all of the iPods manually and just drag whatever content you want to them: Managing content manually on iPod
    Loading the iPod shuffle differs slightly but it can still be used with the others, for details have a look at this page:
    Loading songs onto iPod shuffle - Windows
    Loading songs onto iPod shuffle - Mac
    Multiple Libraries
    It's also possible to have multiple libraries in a single account. To create or access a second (or more) library, hold down the Option key (or Shift key in Windows) when launching iTunes 7. In the resulting dialogue you will get the option to create a new library or navigate to the other Library.
    Note: You can only have one Library open at a time and iTunes will default to the last library opened if you don't use the keyboard command to choose one. This can prove tricky when using multiple iPods, if you don't use the keyboard command you can risk syncing to the wrong library:Using multiple iTunes libraries -Windows
    Separate User Accounts
    Another option is to create a separate User account for each person on your PC or Mac. Different accounts by definition would give you completely separate libraries. Each account has it's own iTunes folder, Library and iTunes Music folder and you load it with CDs etc just as you did with your original one. The iPod can be set to update however the owner chooses, sync all, manual or sync specific playlists
    I don't use Windows so I can't give you a step by step on that one, however I can point you to another web page which should help you out. You can read about Windows user accounts here: Create A New User Account In Vista

  • How to use multiple languages at the same time for spell checking?

    I use two different languages all the time and words are mostly so different (English and Finnish) that I could have spell checking on for both languages at the same time.
    Now it seem to allow to select only one language at the time and I have to switch back and fort zillion of times per day.

    Thanks for the quick answer.
    The Dictionary Switcher doesn't seem to work with Finnish language, it doesn't detect it at all to be one of the choices although in the Firefox context menu Languages -> Finnish/Finland is shown.
    Also, if it would work, I would need to get rid of multiple EN_* langauges. I just need EN_UK or EN_US, not all 22 different EN_*.
    One option would be to create a custom dictionary, which would have words from both languages. The next task is then to find out how to make this kind of custom ENFI-dictionary, which would have words from both English and Finnish languages.
    Finnish may be a some kind of special case for spell checking anyway, because the support is in its separate plugin:
    http://voikko.sourceforge.net/

  • How do I use multiple accounts on the same Mac with Apple TV2?

    I have home sharing turned on in two separate accounts on a single MacPro.  When I am logged into both accounts, I can see both accounts' iTunes Libraries available in the AppleTV2.  However, when I try to open each account iTunes Library in the AppleTV2, only one account will open (whichever one I logged into first).  (In other words, I log into Account1 then open iTunes with Home Sharing On, then log into Account2 (while Account1 is still logged on), open iTunes with Home Sharing On. AppleTV2 shows Account1 Library and Account2 Library under Computers, but will only load Account1 Library.  Account2 Library will just cause AppleTV2 to search for the Library then give an error.)  How come AppleTV2 can see both Libraries but will only open one Library?  How can I fix this?
    Thanks,
    zpockets

    Thank you for replying.  Both of the accounts are Admin accounts.  The Libraries are kept in the user/music/itunes/itunes media folder on each account.  However, I do use multiple iTunes Libraries on my Account1.  One of the Libraries I use in Account1 is on a separate internal HD.  However, the other Libraries I use in Account1 are stored in user/music/itunes/itunes media folder on the main HD (which hosts both Account1 and Account2).  It doesn't seem to matter whether I am using an iTunes Library on an external drive or the main drive in Account1, I still get the same problem: only account1 library will load.  AppleTV sees that the Account2 Library is there, but it won't load it.

  • How to use multiple instances of the same dll ?

    Hi,
    I'd like to use multiple instances of a jni dll . I have created
    different threads, in each thread, I have called System.loadLibrary(..),
    and I would like each thread to access a different instance of this
    library.
    Unfortunately, the loadLibrary function is effective only once so I
    can not find the way to do this.
    Can anyone help me on this ?
    Thanks.
    Francois.

    Hi, :)
    and I would like each thread to access a different
    instance of this library.In Win32, this is outright impossible. A DLL will only exist once in a process space.
    In Unix, or at least in Solaris, I think this is also not possible, as libraries are loaded by the dynamic linker, and it keeps tabs of which modules have already been loaded into the process space.
    I'm assuming your problem is that your native library has non-reentrant code.
    If so, there are two approaches you can take to this:
    1) If you have access to the source code for the native library, change it so that it is reentrant.
    2) If you do not, change your Java code so that access to the native code is made from whithin synchronize blocks.
    If your problem is of a different nature, I'll second the words of the previous poster and ask you what it is...
    Cheers,
    J.

  • Question about using multiple iPods on the same PC

    I've read the FAQs on this subject but I still have a couple of questions about multiple users with separate iPods using the same PC.
    I want to use my family's desktop (A new Gateway with Vista, if it matters) for my new iPod Classic, but my father already has an iTunes account on there for his iPod. I know I can create a new user account on the PC and move iTunes to a shared folder so that we can share music, but will this second account be able to purchase music from the iTunes store or am I going to have to switch between Windows User accounts to make purchases and then move new songs into my separate iTunes account via the shared folder? Will it be its own separate iTunes account (separate user name, separate credit card used, etc.) or will it just be a second library that's dependant on the first?
    I want to be able to have my own iTunes account, make my own purchases in it, and maybe occasionally share tv shows or something with my father.
    If this can't be done, would I be better off just creating new playlists for our two iPods from the same library, or creating a second library on my Father's account?
    Also, if I want to access things I've purchased from iTunes on this desktop in iTunes on my notebook, will I be able to?
    I hope that made sense.
    Sorry if these seem like silly questions. This will be my first iPod as I'm really excited about the 160gig and want to know if these things are possible.
    Thanks in advance for any help

    Hi, Wes.
    Congratulations on your new iPod Classic and Welcome to the Apple Discussions.
    For no particular reason, let's answer your last question first ...
    ... if I want to access things I've purchased from iTunes on this desktop in iTunes on my notebook, will I be able to?
    The iTunes Store operates on a one download per purchase policy so you will have to copy the purchases from one computer to the other and make sure that you authorize the laptop to play the songs.
    As to your first question ...
    ... will this second account be able to purchase music from the iTunes store or am I going to have to switch between Windows User accounts to make purchases ...
    Whatever XP User Account you are logged in to doesn't really matter. What's important is which Apple Account you sign in to ... yours or your Dad's or - if you had my Apple ID and password - The Mimico Kid's for that matter. You can sign in to any Apple Account on any XP User Account. Or any computer for that matter.
    Where the XP User Account comes into play is that it will determine where on your computer the purchases are downloaded. Files will be sent to the iTunes Music folder as specified in the iTunes Edit menu > Preferences > Advanced tab > General sub-tab. Default settings will have a different location for each User Account - C:\Documents and Settings\ user name \My Documents\My Music\iTunes - but if you've read this article in the Apple Knowledge Base, you will know you can change the location of the iTunes Music folder in each XP Account to a common location such as C:\Documents and Settings\All Users\Documents\My Music\iTunes.
    Post back if all this hasn't been as clear as mud and you need anything clarified.

Maybe you are looking for

  • ERROR WHILE UPLOADING FUNCTIONAL LOCATION MASTER DATA THROUGH LSMW?????

    Dear Experts, I am uploading the master data of functional location through LSMW .I had completed all the steps except "Run Batch Input Session". In that step it is showing as functional location already exists, after this error the remaining functio

  • Problem with migo, miro

    Hi All, I am having a message when i do MIGO, MIRO as follow. Purchase order 4500017222 does not exist" But the above number is my purchase order i got  it when i created with PO wiht ME21N. I think tables r not updating . can any one give me the sol

  • JSF 1.2 and Tomcat 6.0.16, error parsing 'jsf-ri-runtime.xml'

    I am working on an application that used jsf 1.1 but would like to move to jsf 1.2. I've added the 1.2 jars (jsf-api.jar and jsf-impl.jar) and jstl-1.2.jar to the app. When I deploy to tomcat 6, i get the following error: 15-Feb-2008 11:30:36 org.apa

  • Deleting document from general documentation tab in implementation project

    Hello, We tried to delete a document from gen. documentation tab in an implementation project, since the gen. documenation tab is greyed out, we couldn't do so. The document is a link from a template project, we tried to delete it (by using the trash

  • Free transform help

    am using cs3....am trying to free transform but for some reason on the menu i am unable to use either the didstort or perspective function....what do i need to do to make them active?? THANKS!!