Please help, this code is trashing the database

I have the 'pleasure' of fixing a view that as you can see in poorly written, and it is in production.
This thing is dying in production is giving me ORA-03113: end-of-file on communication channel error, I did my research and it is a patch that the DBA needs to apply, but he is telling that he does not have time, anyway, if someone out there kindly look at this code and give me some hints of how I can fix this thing, If you look at the end of the code where I put the message 'here is the problem; it is with this thing is dying, It does not like that subquery, I put alias on the tables but still not working.
SELECT y.gtvsdax_internal_code, y.gtvsdax_internal_code_group,
spraddr_pidm, spriden_id, spriden_last_name, spriden_first_name,
spriden_mi, spraddr_atyp_code, stvatyp_desc, spraddr_street_line1,
spraddr_street_line2, spraddr_street_line3, spraddr_city,
spraddr_stat_code, stvstat_desc, spraddr_zip, spraddr_cnty_code,
stvcnty_desc, spraddr_natn_code, stvnatn_nation, spraddr_seqno,
spraddr_delivery_point, spraddr_correction_digit
FROM saturn.stvatyp, saturn.stvnatn, saturn.stvstat, saturn.stvcnty, saturn.spriden, saturn.spraddr x, general.gtvsdax y
WHERE y.gtvsdax_internal_code_group = 'CC_ADDRESS_SYVADDS'
AND x.spraddr_seqno =
(SELECT MAX (spraddr_seqno)
FROM spraddr a
WHERE a.spraddr_pidm = x.spraddr_pidm
AND a.spraddr_atyp_code = x.spraddr_atyp_code
AND a.spraddr_status_ind IS NULL
AND ( (a.spraddr_to_date IS NULL
AND a.spraddr_from_date IS NULL
OR ( a.spraddr_to_date IS NOT NULL
AND a.spraddr_from_date IS NOT NULL
AND TRUNC (SYSDATE) BETWEEN TRUNC (a.spraddr_from_date)
AND TRUNC (a.spraddr_to_date)
OR ( a.spraddr_from_date IS NOT NULL
AND a.spraddr_to_date IS NULL
AND TRUNC (SYSDATE) >= TRUNC (a.spraddr_from_date)
OR ( a.spraddr_from_date IS NULL
AND a.spraddr_to_date IS NOT NULL
AND TRUNC (SYSDATE) <= TRUNC (a.spraddr_to_date)
AND stvatyp_code(+) = x.spraddr_atyp_code
AND stvnatn_code(+) = x.spraddr_natn_code
AND stvstat_code(+) = x.spraddr_stat_code
AND stvcnty_code(+) = x.spraddr_cnty_code
AND spriden_pidm = x.spraddr_pidm
AND spriden_change_ind IS NULL
AND x.spraddr_status_ind IS NULL
AND ( (x.spraddr_to_date IS NULL AND x.spraddr_from_date IS NULL)
OR ( x.spraddr_to_date IS NOT NULL
AND x.spraddr_from_date IS NOT NULL
AND TRUNC (SYSDATE) BETWEEN TRUNC (x.spraddr_from_date)
AND TRUNC (x.spraddr_to_date)
OR ( x.spraddr_from_date IS NOT NULL
AND x.spraddr_to_date IS NULL
AND TRUNC (SYSDATE) >= TRUNC (x.spraddr_from_date)
OR ( x.spraddr_from_date IS NULL
AND x.spraddr_to_date IS NOT NULL
AND TRUNC (SYSDATE) <= TRUNC (x.spraddr_to_date)
here is the problem
AND ((y.gtvsdax_internal_code_seqno||y.gtvsdax_external_code,
x.spraddr_atyp_code
) =
(SELECT MIN (c.gtvsdax_internal_code_seqno
||c.gtvsdax_external_code
MIN (c.gtvsdax_external_code)
FROM saturn.spraddr m, general.gtvsdax c
WHERE c.gtvsdax_internal_code = y.gtvsdax_internal_code
AND c.gtvsdax_internal_code_group = y.gtvsdax_internal_code_group
AND m.spraddr_pidm = x.spraddr_pidm
AND m.spraddr_atyp_code = c.gtvsdax_external_code
AND m.spraddr_status_ind IS NULL)
AND ( (x.spraddr_to_date IS NULL
AND x.spraddr_from_date IS NULL
OR ( x.spraddr_to_date IS NOT NULL
AND x.spraddr_from_date IS NOT NULL
AND TRUNC (SYSDATE) BETWEEN TRUNC (x.spraddr_from_date)
AND TRUNC (x.spraddr_to_date)
OR ( x.spraddr_from_date IS NOT NULL
AND x.spraddr_to_date IS NULL
AND TRUNC (SYSDATE) >= TRUNC (x.spraddr_from_date)
OR ( x.spraddr_from_date IS NULL
AND x.spraddr_to_date IS NOT NULL
AND TRUNC (SYSDATE) <= TRUNC (x.spraddr_to_date)
))

Agreed on formatting the query nicely.
The bit that jumped out to my problem-spotting eye was
AND ( (a.spraddr_to_date IS NULL
   AND a.spraddr_from_date IS NULL
OR ( a.spraddr_to_date IS NOT NULL
   AND a.spraddr_from_date IS NOT NULL
   AND TRUNC (SYSDATE) BETWEEN TRUNC (a.spraddr_from_date)
   AND TRUNC (a.spraddr_to_date)
OR ( a.spraddr_from_date IS NOT NULL
AND a.spraddr_to_date IS NULL
AND TRUNC (SYSDATE) >= TRUNC (a.spraddr_from_date)
OR ( a.spraddr_from_date IS NULL
AND a.spraddr_to_date IS NOT NULL
AND TRUNC (SYSDATE) <= TRUNC (a.spraddr_to_date)
))which could be written as
AND trunc(sysdate) BETWEEN trunc(nvl(a.spraddr_from_date, sysdate))
                       AND trunc(nvl(a.spraddr_to_date, sysdate))Similarly with x.spraddr_from_date/to_date.

Similar Messages

  • Please help to load image in the database

    Hi to all. ....
    I need to save image file in the database thru forms ...
    I have some image file in the application server and I need to load it in the database in a Blob col..
    Any help ... ??
    Thank's in advance

    Hi!
    Your forms version is very important.
    If you use forms 10g and you want to load the image on the client, you need webutil.
    If you use forms 6 or you want to load the image from the application server to
    a image item in your form, you can use the read_image_file forms build-in:
    read_image_file ( 'x:\path\image.jpg.', 'JPG', 'block.image_item' );On forms 10g this will be executed on the server and the filename and path has to be
    a physical place on your servers harddisk.
    The image item has to be an item of type image and must be assinged to a blob colum in your table.
    Regards

  • My youtube does not work on safari only when i try to play a video it says "This video is not available on mobile add to playlist" But i am using a mac air 11 inch it is not a mobile. Please Help. i have to use the youtube on firefox or chrome

    my youtube does not work on safari only when i try to play a video it says "This video is not available on mobile add to playlist" But i am using a mac air 11 inch it is not a mobile. Please Help. i have to use the youtube on firefox or chrome. At times it also say QuickTime Player can't open "video.3gp". and
    The file may be damaged or may not be a movie file that is compatible with QuickTime Player. when i try to open a video on youtube on safari

    I too am having the same issue as the OP.
    Your USER AGENT information is Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/600.3.18 (KHTML, like Gecko) Version/8.0.3 Safari/600.3.18
    Every webserver that receives a request from your browser is able to determine the HTTP USER AGENT information unless it has been removed by some software (e.g. firewall) before the request was trasmitted.

  • Whenever I connect my 4th generation iPod thouch, all of the playlists on my iPod get deleted. This is very frustrating. Someone please help me? I searched the settings on iTunes and couldn't find anything.

    Whenever I connect my 4th generation iPod thouch, all of the playlists on my iPod get deleted. This is very frustrating. Someone please help me? I searched the settings on iTunes and couldn't find anything.

    Also, when I go on to safari, another alert pops up that safari cannot verify the identity of the website, anything that I type in to as common as google.com. It gives me 3 options to either cancel, look at details, and continue. I've looked at the details of the website of Google and it is legitimate the site. Any help?

  • TS3694 Hi, i'm trying to update my iphone but this is the msg i'm getting, can you please help me. thank you. "the iphone ''C & M '' could not be restored. An unknown error occurred (3194)"

    Hi, i'm trying to update my iphone but this is the msg i'm getting, can you please help me. thank you. "the iphone ''C & M '' could not be restored. An unknown error occurred (3194)"

    http://support.apple.com/kb/TS3694#error3194
    This means that either your firewall/antivirus is blocking access to Apple's servers, or you have used your computer to jailbreak an iDevice in the past. The link above tells you how to resolve this issue.

  • Please help me how to improve the performance of this query further.

    Hi All,
    Please help me how to improve the performance of this query further.
    Thanks.

    Hi,
    this is not your first SQL tuning request in this community -- you really should learn how to obtain performance diagnostics.
    The information you posted is not nearly enough to even start troubleshooting the query -- you haven't specified elapsed time, I/O, or the actual number of rows the query returns.
    The only piece of information we have is saying that your query executes within a second. If we believe this, then your query doesn't need tuning. If we don't, then we throw it away
    and we're left with nothing.
    Start by reading this blog post: Kyle Hailey &amp;raquo; Power of DISPLAY_CURSOR
    and applying this knowledge to your case.
    Best regards,
      Nikolay

  • HT201441 please help me try to contact the owner of this phone IMEI ****  ICCID **** i got his phone now with me but i dont know how to contact them first time

    please help me try to contact the owner of this phone IMEI ****  ICCID **** i got his phone now with me but i dont know how to contact them first time i got it low battery contact me
    I will explan more how i got this phone
    Call me +**** Micky Thai
    <Personal Information Edited By Host>

    A long shot but you might try using the phone to send an email to the phone asking the owner to call their mobile phone.  If the owner has a computer they may get the email and get in contact with you.
    But Roger's suggerstion of turning it over to the police is the best bet.
    OT

  • HT1339 my ipod nano 7th generation....works fine as long as it's on the docking station. when off the station, the display goes dark after a few seconds. it's fully charged. please help. this is the heartbeat of my business. thanks

    my ipod nano 7th generation....works fine as long as it's on the docking station. when off the station, the display goes dark after a few seconds. it's fully charged. please help. this is the heartbeat of my business. thanks

    In the worst case, it's still under warranty (all 7th gen nanos are still under one year from purchase).
    So, you disconnect it from power, and it almost immediately goes dead?  You can try a Restore... but it doesn't sound like the type of problem a Restore will fix.
    You should probably have it looked by Apple Tech Support.  If there's an Apple Store nearby, you can take it to the store's Genius Bar.  To avoid waiting, you can make a reservation at the store's web page
    http://www.apple.com/retail/

  • My Iphone 4s Will not delete the songs I want it to. I've tried Turning off "Show All Music" and then swiping left on the song to delete it, but it wont give me the option to delete the songs. Please help. (this is iOS.7 btw)

    I've tried Turning off "Show All Music" and then swiping left on the song to delete it, but it wont give me the option to delete the songs. Please help. (this is iOS.7 btw) It only does this for some of the songs, but the rest of them I can delete. This is really annoying, please help me ASAP. Thank yall for your time

    I've tried Turning off "Show All Music" and then swiping left on the song to delete it, but it wont give me the option to delete the songs. Please help. (this is iOS.7 btw) It only does this for some of the songs, but the rest of them I can delete. This is really annoying, please help me ASAP. Thank yall for your time

  • Can anyone please explain this code to me?

    I am a new (junior)programmer?Can anyone please explain this code to me in lame terms? I am working at a client location and found this code in a project.
    _file name is AtccJndiTemplate.java_
    Why do we use the Context class?
    Why do we use the properties class?
    package org.atcc.common.utils;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Properties;
    import java.util.logging.Logger;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import org.springframework.jndi.JndiTemplate;
    public class AtccJndiTemplate extends JndiTemplate
      private static Logger logger = Logger.getLogger(AtccJndiTemplate.class.getName());
      private String jndiProperties;
      protected Context createInitialContext()
        throws NamingException
        Context context = null;
        InputStream in = null;
        Properties env = new Properties();
        logger.info("Load JNDI properties from classpath file " + this.jndiProperties);
        try
          in = AtccJndiTemplate.class.getResourceAsStream(this.jndiProperties);
          env.load(in);
          in.close();
        catch (NullPointerException e) {
          logger.warning("Did not read JNDI properties file, using existing properties");
          env = System.getProperties();
        } catch (IOException e) {
          logger.warning("Caught IOException for file [" + this.jndiProperties + "]");
          throw new NamingException(e.getMessage());
        logger.config("ENV: java.naming.factory.initial = " + env.getProperty
    ("java.naming.factory.initial"));
        logger.config("ENV: java.naming.factory.url.pkgs = " + env.getProperty
    ("java.naming.factory.url.pkgs"));
        logger.info("ENV: java.naming.provider.url = " + env.getProperty
    ("java.naming.provider.url") + " timeout=" + env.getProperty("jnp.timeout"));
        context = new InitialContext(env);
        return context;
      public String getJndiProperties()
        return this.jndiProperties;
      public void setJndiProperties(String jndiProperties)
        this.jndiProperties = jndiProperties;
    }

    Hi,
    JNDI needs some property such as the
    java.naming.factory.initial
    java.naming.provider.url
    which are needed by the
    InitialContext(env);
    where env is a properties object
    Now if you can not find the physical property file on the class path
    by AtccJndiTemplate.class.getResourceAsStream(this.jndiProperties);
    where the String "jndiProperties" get injected by certain IOC ( inverse of control container ) such as Spring framework
    if not found then it will take the property from the system which will come from the evniromental variables which are set during the application start up i.e through the command line
    java -Djava.naming.factory.initial=com.sun.jndi.ldap.LdapCtxFactory -Danother=value etc..
    I hope this could help
    Regards,
    Alan Mehio
    London,UK

  • Please help this is driving me nuts!!

    I have the 8320 with os 4.5 and have only had it for a few days,I am trying to download app world but I can't. It wont let me download to desktop,it says;downloads via USB are not enabled for this product and when I try and download it through my blackberry browser it says my device does not meet the system requirements that are needed to support blackberry app world.??? I don't no what to do,please help.

    Hi and Welcome to the Forums!
    The second symptom you describe is the most telling -- see this page:
    http://na.blackberry.com/eng/services/appworld/download.jsp#tab_tab_system_requirements
    Make sure you fully meet all requirements -- you might have to contact your carrier to be sure since one of the requirements involves them. I suggest contacting them and asking them very specifically if your current service plan allows you access to AppWorld.
    Good luck and let us know!
    Occam's Razor nearly always applies when troubleshooting technology issues!
    If anyone has been helpful to you, please show your appreciation by clicking the button inside of their post. Please click here and read, along with the threads to which it links, for helpful information to guide you as you proceed. I always recommend that you treat your BlackBerry like any other computing device, including using a regular backup schedule...click here for an article with instructions.
    Join our BBM Channels
    BSCF General Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • I can't forcequit firefox and shutdown my computer, nor can I open up any other programs or applications. Does anyone know how to fix this? please help this poor soul.

    I can't forcequit firefox and shutdown my computer, nor can I open up any other programs or applications. Does anyone know how to fix this? please help this poor soul.

    You can force quit applications
    >Force quit
    if that does not work you can force quit a computer shut down by hold the power button for an extended period.

  • HT1688 Can you please help me. I purchased the new Apple I 4s phone from AT&T. I bought it out right. NO CONTRACT!! I paid almost $1000.00 for it. I then, had it enrolled it in my company's  ATT service plan. They paid the bill for my service. Since, I ha

    Can you please help me. I purchased the new Apple I 4s phone from AT&amp;T. I bought it out right. NO CONTRACT!! I paid almost $1000.00 for it. I then, had it enrolled it in my company's  ATT service plan. They paid the bill for my service. Since, I have left the company. I have retained, and assumed financial responsibility for the phone, and the phone number with AT&amp;T. The same day I assumed ifinancial responsibility, I had the phone number ported to a new service provider. ( Straight Talk ) After doing so, my phone worked fine. (as far as cellular service) NO DATA Service !!!! I have been on the phone with AT&amp;T, Straight Talk, and Apple, FOR HOURS over TWO days!!! Trying  to get this problem resolved. All I need to do, is change my APN settings (access point name ) settings. Its  my phone!!! Why does any body have this APN menu locked from me??? I've been on the phone for two days between, AT&amp;T, Straight Talk, and Apple products technical support teams. Everybody points the finger at the next guy!! What can I do to get the phone, that I paid for, work  for more than just a phone, and a paper weigh?
    PLEASE HELP ME!!!!!
    Jason
    Sent from my iPhone
    <Email Edited by Host>

    Wow... you seriously over paid for an iPhone.
    That probably explains why you have/had no clue you were purchasing a locked device and think it's an Apple problem to get it unlocked.

  • I upgraded to mountain lion a week ago and now on startup of my macbook pro, microsoft excel and word start up automatically and then crash? very strange can anyone please help? I have checked the login items under users and groups and there is nothing.

    I upgraded to mountain lion a week ago and now on startup of my macbook pro, microsoft excel and word start up automatically and then crash? very strange can anyone please help? I have checked the login items under users and groups and there is nothing.

    Are you using the Office for Mac 2011 version, as you need to do?  The Office for Mac 2004 is Not at all compatible with Mountain Lion, and the 2008 version has been noted to have some problems running with ML.
    Hope this helps

  • I have windows 7 and every time I try to play or add a song. It says itunes has stopped working. Please help this is frustrating.

    I have windows 7 and every time I try to play or add a song. It says itunes has stopped working. Please help this is frustrating.

    a further message  box states that Data Execution Prevention has closed the program.
    Try updating your QuickTime to the most recent version. Does that clear up the DEP errors in iTunes?

Maybe you are looking for

  • Software instruments wont play in arrange window

    Hi, I have recently purchased Logic Pro 9 from app store but when I select a new track as a software instrument there is no sound when playing samples in the arrange window. The samples will play fine in the browser window and will also show up on th

  • Is there a way to install the AE software if my harddrive is broken?

    I have a laptop and a desktop and would like them to both work on the wireless network, but the harddrive on my desktop is broken... is there any way to obtain a digital copy of the software?

  • Bridge CS3 Manage Color Help menu wrong

    The Help menu says- Preferences (Mac OS), and click Advanced. Select Enable Color Management In Bridge. HOWEVER, the options I get when I go to Preferences and Click advanced DO NOT have Select Enable Color Management in Bridge as an option, see encl

  • Rownum Problem

    I have a situation where i have to create a table based on another table and data will be inserted in a phase by phase manner. Suppose I have a table A which holds 10,000 rows. I have to create a table B that will hold the first 2000 rows from A. Aft

  • Adobe Updater doesn't find updates, wrong version, hangs

    I have the full CS5. When I first installed, updater found a number of updates, and recently, it notified me of the update to Photoshop, so it was working. I just ran Updater after installing Acrobat, and it did not find any updates, even though ther