Slow SQL Function, can it be made to run faster?

Hi there,
I am using Oracle 11.1
I have a simple OWB map that uses the transformation object calling the below function to return a value. The source table for the map contains ~17,000 records, The look-up table used below (BCGDHSC) contains ~180,000 records. My problem is the job takes 17 minutes to run with this function being called, if I comment out the look-up portion it takes about 3 seconds? Any ideas on how I can speed this up or ideas as to what I am doing wrong?
CREATE OR REPLACE FUNCTION "F_GET_PLAN"("EMPLOYEE_ID_IN" IN VARCHAR2, "REGION_CD_IN" IN VARCHAR2) RETURN VARCHAR2 PARALLEL_ENABLE IS
--init variable
control_plan_out varchar2(2);
rec_count int;
BEGIN
--Get the record count to see if it exists
select count(*) into rec_count from BCGDHSC WHERE HSC_REGION_CD = REGION_CD_IN and HSC_EMPLOYEE_ID = EMPLOYEE_ID_IN and rownum=1;
if rec_count <1 then
return '00';
else
select distinct NVL(control_plan,'00') into control_plan_out from BCGDHSC WHERE HSC_REGION_CD = REGION_CD_IN and HSC_EMPLOYEE_ID = EMPLOYEE_ID_IN and rownum=1;
end if;
return control_plan_out;
EXCEPTION
WHEN NO_DATA_FOUND THEN
control_plan_out := '00'; -- exception code here
RETURN control_plan_out;
WHEN OTHERS THEN
NULL;
RETURN NULL;
END;
Thanks,

This is not the fastest way, but it should be better then your current version.
Fast would be to use plain SQL instead of PL/SQL. The select that is inside the function can be written as a subquery inside the other SELECT. if you avoid the function then you avoid many pl/sql context swichts. My version of the functions avoids only half of them since I removed one select.
CREATE OR REPLACE FUNCTION "F_GET_PLAN"("EMPLOYEE_ID_IN" IN VARCHAR2, "REGION_CD_IN" IN VARCHAR2)
  RETURN VARCHAR2 PARALLEL_ENABLE IS
--init variable
  control_plan_out varchar2(2);
  rec_count int;
BEGIN
select NVL(control_plan,'00')
into control_plan_out
from BCGDHSC
WHERE HSC_REGION_CD = REGION_CD_IN  /*  number or string comparsion here ? */
and HSC_EMPLOYEE_ID = EMPLOYEE_ID_IN /*  number or string comparsion here ? */
and rownum=1;
return control_plan_out;
EXCEPTION
WHEN NO_DATA_FOUND THEN
  -- this already takes care of the count = 0 logic
  control_plan_out := '00'; -- exception code here
  RETURN control_plan_out;
END;Also I note that all your "IDs" are strings. Is this intended ? if not you might want to change them into proper number data types.

Similar Messages

  • Underclocked cpu can it be made to run faster

    hi
    i read somewhere n8 has 772 mhz cpu underclocked
    is it possible to utilize the full  power of cpu
    most importantly will it  improveteh n8 xperience???
    how will it effect battery life?
    except for n8 requiring charging everyday post anaa   i have no issues with my n8  its an awesome phone

    You won't get much help with Over Clocking on this site mate, it's not something Nokia approve of.
    You can try Google but I don't think anyone has Over Clocked an N8 yet.
    For me processor speed isn't the problem, I think Ram may become an issue with Belle, all those Home Screens have to be stored somewhere.
    Hopefully they have some slick paging going on.
    N95 (RM159) V31.0.017, N8 (RM596) Belle 111.040.1511

  • My macbook freezes and runs slow..how can i get it to run faster?

    I use my macbook and it freezes and that annoying wheel keeps spinning PLS HELP TY!

    OS X Mavericks: If your Mac runs slowly?
    Spotlight indexing make computer run slowly after a fresh installation of OS X.
    http://support.apple.com/kb/PH13895
    Startup in Safe Mode
    http://support.apple.com/kb/PH14204
    Repair Disk
    Steps 1 through 7
    http://support.apple.com/kb/PH5836
    Reset SMC.     http://support.apple.com/kb/HT3964
    Choose the method for:
    "Resetting SMC on portables with a battery you should not remove on your own".
    Increase disk space.
    http://support.apple.com/kb/PH13806
    Run Etrecheck and post report here or look for any third party apps that may cause the slowdown.
    https://discussions.apple.com/docs/DOC-6173

  • How can I make my phone run faster?

    anytime I have to download or upload or search the web it is very very slow .

    ray miranda wrote:
    I have my iMac purchased in 2008 and it is running very slow.  I have a time capsule.  I believe it only has 1 GB of SD Ram.  Will it run faster/better if I increase the Ram?
    YUP!
    How large is you HD and how much space do you have left?
    Care to share which OS you are using?
    How can I make my iMac run faster?

  • How can i make my iphone run faster

    How can I make my iphone 4 run faster?

    ray miranda wrote:
    I have my iMac purchased in 2008 and it is running very slow.  I have a time capsule.  I believe it only has 1 GB of SD Ram.  Will it run faster/better if I increase the Ram?
    YUP!
    How large is you HD and how much space do you have left?
    Care to share which OS you are using?
    How can I make my iMac run faster?

  • My Mac Mini seems to have slowed a bit.  I bought it last December 2011.  Is there a simple tune up I can do to make it run faster?

    My Mac Mini, which I bought last December 2011, seems to have slowed a bit.  Is there something I can do to tune it up to get it to run faster?

    Hi Annie,
    Hello, see how many of these you can answer...
    See if the Disk is issuing any S.M.A.R.T errors in Disk Utility...
    http://support.apple.com/kb/PH7029
    Open Activity Monitor in Applications>Utilities, select All Processes & sort on CPU%, any indications there?
    How much RAM & free space do you have also, click on the Memory & Disk Usage Tabs.
    Open Console in Utilities & see if there are any clues or repeating messages when this happens.
    In the Memory tab, are there a lot of Pageouts?

  • Why does Firefox run supper slow? Can u fix it to run faster on webstie

    every time i get on a website it never loads right running to slow it takes for every on the websites. on www.yahoo.com @ www.Face book.com @ www.tagged.com I have trouble with fire fox all the time on these website they run to freaking slow it sucks please can you fix to run faster it was before working right please fix ty

    Firefox running supper slow on these websites. on www.yahoo www.Facebook www.tag. It sucks please fix ty they were running great for a while and now back at the same running slow again.

  • How can i make my macbook run faster again?

    Hey, i own 15 inch macbook pro 2011 that came with snow leopard and i upgraded it to lion but i observed that my computer got slower speacially when i start up i wait much more longer than i used to.I don't have many programs downloaded i mean only 130 gb is used out 500 so, is there anything i can do to make my mac run faster? In addition i am thinking about to make participation with win7 does it affect the speed of my computer negative? Thank you.

    If you have only 4GBs of RAM, this article may help you - https://discussions.apple.com/thread/3238726
    You may need to upgrade the RAM or make changes to the apps you use..  Since your Hard Drive is nicely underutilized and is probably behaving well, that should not be the problem.
    Check to see if you are getting Page Outs and read the article above

  • How can I make my program run faster ? (changing colour indicators quicker)

    Hi everyone, I have a program with 100 indicator colour backgrounds that change according to 100 temperatures. A case structure (with 100 cases) sets the background colours one after the other and runs in a while loop with no timing (as fast as possible). The temperatures are loaded up from an array that is initialized at the beginning of the program. The idea is to have an overall view of the change of temperatures (just by looking at the change of colours). Everything works fine except that it doesn’t run fast enough... The change of colours is not smooth at all ... you can really see the increments. It works fine with 20 temperatures for instance. 1) Would anybody have a solution to improve this? I was wondering if Labview perhaps actualises all of the values each time one changes (just like with the excel cells: an option that you can desactivate and make things run quicker when you use a macro) which would make a big loss of time....  
    There is no data saving this is just a post treatment program. So My my program isn't doing anything else.
     2) I have attached a screen print of a problem a faced when making up the VI I attached. Why can’t I wire directly to the Index Array that is in the For Loop in my VI… I had to go throw a shift register to make up the example. When going back to my original program I couldn’t use the index array a second time (screen shot). Thanks a lot for any help, Regards, User  
    Solved!
    Go to Solution.
    Attachments:
    Forum question.vi ‏13 KB
    forum.JPG ‏50 KB

    Here's a possible solution:
    Ton
    Message Edited by TCPlomp on 11-03-2010 11:16 AM
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!
    Attachments:
    Forum question.png ‏23 KB

  • What sql function can I use?

    Dear all,
    I have 2 sets of data and they are the followings:
    Invoice No. Invoice Date Apply Date Amount
    ======================================
    A123 01-Nov-2005 11-Nov-2005 1000
    A123 01-Nov-2005 18-Nov-2005 500
    Under this circumstances, for the same "Invoice No." for different "Apply Date", I want to get the minimum Apply Date. As a result, the following 2 sets of data I would like to get.
    Invoice No. Invoice Date Apply Date Amount
    ======================================
    A123 01-Nov-2005 11-Nov-2005 1000
    A123 01-Nov-2005 11-Nov-2005 500
    Thanks,
    Amy

    Try this.
    select invoice_no, invoice_date,
    min(invoice_date) over (partition by invoice_no) as apply_date,
    amount
    from your_table;

  • Why is my macbook pro running slow and I can also hear the fan running continuously

    My macbook pro started running slow last night.  I turned it off and waited til this morning to turn it on again.  It is still running really slow when I browse through my dock or apps and everything takes forever to open, my fan is also running pretty loud, I could not hear it running until last night. Can anyone help me out?

    Okay so I followed those steps, what exactly does this mean?
    Last login: Fri Jun 29 22:11:31 on console
    bobbo-MacBook-Pro:~ bobbo$ kextstat -kl | awk '!/com\.apple/ {print $6 $7}'
    bobbo-MacBook-Pro:~ bobbo$ sudo launchctl list | sed 1d | awk '!/0x|com\.apple/ {print $3}'
    WARNING: Improper use of the sudo command could lead to data loss
    or the deletion of important system files. Please double-check your
    typing when using sudo. Type "man sudo" for more information.
    To proceed, enter your password, or type Ctrl-C to abort.
    Password:
    Sorry, try again.
    Password:
    Sorry, try again.
    Password:
    org.x.privileged_startx
    org.postfix.master
    org.ntp.ntpd
    org.cups.cupsd
    edu.mit.Kerberos.krb5kdc
    edu.mit.Kerberos.kadmind
    com.vix.cron
    bobbo-MacBook-Pro:~ bobbo$
    Bobbo-MacBook-Pro:~ bobbo$ launchctl list | sed 1d | awk '!/0x|com\.apple/ {print $3}'
    com.readytapgo.MorningsHelper
    org.x.startx
    org.openbsd.ssh-agent
    edu.mit.Kerberos.KerberosAgent
    com.facebook.videochat.bobbo.updater
    edu.mit.Kerberos.CCacheServer
    bobbo-MacBook-Pro:~ bobbo$ ls -1A /e*/mach* {,/}L*/{Ad,Compon,Ex,Fram,In,Keyb,La,Mail/Bu,P*P,Priv,Qu,Scripti,Servi,Spo,Sta} * L*/Fonts 2> /dev/null
    /Library/Components:
    /Library/Extensions:
    /Library/Frameworks:
    NyxAudioAnalysis.framework
    PluginManager.framework
    iLifeFaceRecognition.framework
    iLifeKit.framework
    iLifePageLayout.framework
    iLifeSQLAccess.framework
    iLifeSlideshow.framework
    iTunesLibrary.framework
    /Library/Input Methods:
    /Library/Internet Plug-Ins:
    Flash Player.plugin
    JavaAppletPlugin.plugin
    Quartz Composer.webplugin
    QuickTime Plugin.plugin
    flashplayer.xpt
    iPhotoPhotocast.plugin
    nsIQTScriptablePlugin.xpt
    /Library/Keyboard Layouts:
    /Library/LaunchAgents:
    /Library/LaunchDaemons:
    /Library/PreferencePanes:
    Flash Player.prefPane
    Perian.prefPane
    /Library/PrivilegedHelperTools:
    /Library/QuickLook:
    iWork.qlgenerator
    /Library/QuickTime:
    AC3MovieImport.component
    AppleIntermediateCodec.component
    AppleMPEG2Codec.component
    Perian.component
    /Library/Spotlight:
    AppleWorks.mdimporter
    Microsoft Office.mdimporter
    iWork.mdimporter
    /Library/StartupItems:
    /etc/mach_init.d:
    dashboardadvisoryd.plist
    /etc/mach_init_per_login_session.d:
    /etc/mach_init_per_user.d:
    Library/Address Book Plug-Ins:
    SkypeABDialer.bundle
    SkypeABSMS.bundle
    Library/Fonts:
    Library/Input Methods:
    .localized
    Library/Internet Plug-Ins:
    .DS_Store
    Library/Keyboard Layouts:
    Library/LaunchAgents:
    com.apple.FTMonitor.plist
    com.apple.FolderActions.enabled.plist
    com.apple.FolderActions.folders.plist
    com.apple.imagent.plist
    com.apple.marcoagent.plist
    com.facebook.videochat.brandanburgess.plist
    Library/PreferencePanes:
    Bobbo-MacBook-Pro:~ bobbo$ osascript -e 'tell application "System Events" to get the name of every login item'
    iTunesHelper
    Bobbo-MacBook-Pro:~ bobbo$

  • Lenovo G575: Can it be made to run Windows 8?

    I have a Lenovo G575 running Windows 7 but really I want a machine that will run Windows 8. I have previously tried running Windows 8 on it but it was not a complete success and after discovering that the G575 is not compatable with Windows 8 I removed it.
    Is there any way to upgrade the G575 so that it can run 8? Perhaps a different processor might help, or should I just get a fresh computer?
    I'm going to do a clean install of 7 and see if I can improve the current overall performance of the machine because it is being rather tempermental at present.

    You won't get much help with Over Clocking on this site mate, it's not something Nokia approve of.
    You can try Google but I don't think anyone has Over Clocked an N8 yet.
    For me processor speed isn't the problem, I think Ram may become an issue with Belle, all those Home Screens have to be stored somewhere.
    Hopefully they have some slick paging going on.
    N95 (RM159) V31.0.017, N8 (RM596) Belle 111.040.1511

  • Any Ideas How I can Make this Formating Program Run Faster?

    I'm using LabView 8.0.1 to extract columns and rows from MS Excel to format to a specific format which can be read into a software program we use in-house.
    The software program requires a specific header which declares variables, etc and also fomats the extracted data in an arcane way.
    Due to an error in the software program we use, the file format that has to be read in is not uniform and has the first line containing  two point sets (see attached file for an idea of what I am talking about). Any other format will not be read by the program.
    This introduced some problems, and finally, I ended up with an highly inefficient program. It runs, but is relatively slow.
    The programs, the input excel file and output file are given for example. 
    A couple of notes on the files:
    1) The file type used as input is just an excel file which has been saved in space-delimited format.
    2)  To speed up the process,I  permitted the formating of only 2 variable types (x, y, z, variable 1, variable 2). I haven't gotten to adding more variables. Ideally, I would like to count the number of columns on the excel file, read the headers and then write the output file automatically with all the variable names.
    3) I used sequenced loops in the vi, which is probably not the best way to do this. I am guessing that I can interweave all the numbers into one large array before writing --- but have no idea how I can accomplish that.
    The output file extension is actually .fvp. I've renamed it in order to upload the file.
    Any help/suggests would be greatly appreciated!!
    ~Janak
    Files are attached.
    Attachments:
    ParticlePathExport-SlowVi.vi ‏65 KB
    Input_File_Example.txt ‏1 KB
    Output_File_Example.txt ‏1 KB

    Use the Format Into String Function instead of the large concatenation.  Most of your inputs are constants, so they could be put into the Format string of that function.  It looks like you have only 2 truly variable string inputs, so they would show up as %s in the format string.
    So your format string would be something like this (\codes turned on)  (VI is LV 8.5)
    Message Edited by Ravens Fan on 09-28-2007 05:05 PM
    Attachments:
    Example_BD.png ‏20 KB
    Untitled 2.vi ‏16 KB

  • What can I do if script runs faster than network?

    I've written an inter-application script that moves from InDesign, where it starts in AppleScript, to Photoshop, where the AppleScript runs a JavaScript to perform various tasks.
    It runs beautifully on my laptop at home where I do my development. Yesterday, using myself as guinea pig, I tried it in the office.
    On about the third run, I was horrified to see the ExtendScript Toolkit pop up with an error message (about as welcome as seeing an AppleScript inviting the user to open the Script Editor and fix a script).
    The error message was that app.bringToFront(); was not a valid function.
    This was true in InDesign, which has a different activation function, and I realised that even though my AppleScript had called for Photoshop to activate I was still in InDesign.
    The JavaScript app.bringToFront had been called as well because I had enclosed my code in the Tranberry template.
    So I pressed the stop button on ExtendScript, went back to InDesign and ran the script again. This time it worked as usual.
    Occasionally on our network we spend some time beachball-watching as some communication goes on in the background. So I imagine that the time the error was thrown was on one of those network slowdowns.
    The switch from InDesign to Photoshop did not happen fast enough, but the script ran on and issued a Photoshop JavaScript command while I was still in InDesign.
    In AppleScript such unfortunate communication with users can be avoided using "try... on error" blocks.
    Would there be any error-handling equivalent in JavaScript which would enable me to avoid them being thrown into ExtendScript Toolbox and would give them a friendly message apologising, explaining what had happened and inviting them to try again?

    Also AppleScript has a default timeout of 60 seconds before it wants to execute its next command. If in you case the opening and processing of the image in JavaScript takes any longer than this wrap your call out to Photoshop in a timeout block thus extending the alloted time to whatever you think may be suitable? Like so:
    tell application "Adobe InDesign CS2"
    activate
    tell active document
    set This_Image to image 1 of item 1 of rectangle 1
    set Image_Path to file path of item link of (item 1 of This_Image) as alias
    my Call_Photoshop(Image_Path)
    delay 1 -- same as sleep(1000);
    update item link of (item 1 of This_Image)
    end tell
    end tell
    on Call_Photoshop(Image_Path)
    with timeout of 180 seconds
    tell application "Adobe Photoshop CS2"
    activate
    set display dialogs to never
    open Image_Path
    set ID_Image to the current document
    tell ID_Image
    -- do my stuff
    close with saving
    end tell
    end tell
    end timeout
    end Call_Photoshop

  • How can i make my imac run faster?

    I have an 8 year old iMac. I am running OS X.
    Hardware Overview:
      Model Name: iMac
      Model Identifier: iMac5,1
      Processor Name: Intel Core 2 Duo
      Processor Speed: 2.16 GHz
      Number Of Processors: 1
      Total Number Of Cores: 2
      L2 Cache: 4 MB
      Memory: 1 GB
      Bus Speed: 667 MHz
      Boot ROM Version: IM51.0090.B09
    I am a graphic designer so I need to run InDesign, Adobe Illustrator & Photoshop usually simultaneously. I also have Microsoft Office installed.
    It is now running very slow and is sluggish. I've not tried anything yet to solve my problem,
    Any tips what I can do to speed it up, would appreciate any helpl!

    I have an 8 year old iMac.
    IMHO, here is no magic bullet to make a very old computer run applications like the ones you describe fast.
    Compare the specs on your machine with a 27" iMac (current line):
    27-inch: 3.2GHz
    Specifications
    3.2GHz quad-core Intel Core i5
    Turbo Boost up to 3.6GHz
    8GB (two 4GB) memory
    1TB hard drive1
    NVIDIA GeForce GT 755M with 1GB video memory
    I don't spend other people's money, but if it were my money I would seriously consider a new computer.
    Barry
    Model Name: iMac
      Model Identifier: iM
      Processor Name: Int
      Processor Speed: 2
      Numbe
      L2 Cache: 4 MB
      Memory: 1 GB

Maybe you are looking for

  • How do I get DVD for the Windows 7 that should have come with my new laptop please

    This is my first message here so please bear with me. I have just bought a new Lenovo Essentials B570 laptop which has come with Windows 7 pre-installed. Previously I used to buy Dell laptops which used to come with OS Re-installation DVDs which chec

  • Can't Delete/Change Schedule Line in Sceduling Agreement

    Hi    I can't delete schedule line in scheduling agreement.    Actually The PO History has diff data & Scheline screen have diff data.    In Po History the Delivered Qty is 1520 GI Qty is 1520 GR Qty is 1520 but when I checked in Delivery Schedule sc

  • Office 2010 Custom Template - folder icon

    Hi, I made a XML custom templates files with many templates for word. I also made a registry patch to make word parsing this xml. Everything works, but I would like to change the categroy folder icon. Is there a way to do so ? BR, SL

  • Cannot Locate Patterns

    I am on CS3 trying to add a Pattern Overlay. When I click on Pattern Overlay in the Layer Style Window only one pattern is shown to the right under the Preview check box. In the main box no pane appears to let me select others only General and Advanc

  • Upgarding to struts 1.3.8

    Hi all, I am quite new to struts and have, perhaps a quite stupid error. Until now a used Struts 1.2.9 (because my IDE had it onboard). Now I want to use some features of the version 1.3.8 and moved to this version that for. But now I have a strange