How to avoid multiple call to function:

In our datawarehouse we have a huge receipt row table where all metrics ar stored in the local currency. On top over that we have views which calculate metrics to the desired currency.
So basically all views looks like this
select geo_region,
product_group,
customer_group,
metric1 * (select get_exchange_rate(currency_id) from dual) metric1,
metric1 * (select get_exchange_rate(currency_id) from dual) metric2,
metric1 * (select get_exchange_rate(currency_id) from dual) metricx,
group by..
As we have about 20 metrics we notices that the function is called 20 times per row.
Is there really anyway to avoid that? Shouldn't it be it's just the exact same call with the same in-parameters over and over again.
We've tried with local sys_context and the performance is better but the call to the context is still performed 20 times. Any Ideas?

Can you avoid multiple function calls? Maybe, if as in your example all the function calls values are computing the same result. If they operate on different columns then you'll have to perform the function call anyway.
Either way you should be able to eliminate the (near as I can tell) pointless subquery from dual
You might be able to avoid the repeated function calls if the values are always the same. If every computation you could save the function call (and subquery!) by doing it once and then using assignments after the initial query using variables after the initial query, perhaps using NULL in the query as placeholders to select into a record - something like
select inital_region,
         product_group,
         customer_group,
         metric1 * exchange_rate(currency_id) metric1,
         null metric2,
v_metric2 := metric1;
...Message was edited by (fixed typo):
riedelme

Similar Messages

  • How to avoide multiple duplicate entries in adress book?

    How to avoide multiple duplicate entries in adress book? I can add the same contact name and number more than twice and the phone isn't warning me at all!!! I's quite a heck for me.

    not possible from inside AB AFAIK. but you can do the following. in finder open the folder /users/username/library/application support/address book/metdata. switch to the list mode and sort by date modified. quicklook the vcards at the top to see which ones they are.

  • How to update multiple calling hours based on business partner

    Hi All,
    please help me in this issue : how to update multiple calling hours based on business partner in SAP CRM.
    Regards,
    Siva kumar.

    Check maintainance view V_TB49, add new scheduling type.

  • How to avoid multiple copies of data in page refresh

    How to avoid multiple copies of data in page refresh

    If you are talking about a page with an insert query, ignore the fact that it's a page refresh.  It's just another way that someone can insert duplicate records.  I like to handle this in my insert query.
    insert into thetable
    (f1, f2, etc)
    select distinct
    value1, value2, etc
    from some_small_table
    where you don't already have that record

  • How to avoid multiple listing for same artist?

    How to avoid multiple listing for same artist?

    Sounds like there might be blanks in the artist name.
    For instance "Lou Reed" and "Lou Reed_" will not match.
    (Pretend the underscore _ is a blank).
    Select all the Lou Reed songs, Get Info, and type "Lou Reed" in the artist field. That should fix it.

  • How to avoid multiple votings?

    Hello All. How can I avoid, that there are multiple votings from one person?

    I think there is no option to avoid multiple votings. Adobe has not implemented this funktion.
    Formstack is as alternative to Formcentral. The Fieldoption there is called - Unique.
    Unique allows you to restrict submissions of the same value in this field. For example, you can allow only one submission for a particular email address or physical address.
    That is the option i was looking too.
    Formcentral is useless for me in this way.

  • How to avoid multiple LOGIN with same user in database.

    Hi All,
    Using database triggers how to control multiple logins of a pertiuclar user.
    thanks in advance

    Don't forget to activate the RESOURCE_LIMIT parameter, which default is FALSE :
    alter system set RESOURCE_LIMIT = true;
    Laurent, I had a similar problem some time ago : I didn't want to avoid multiple access, but only control who was doing what. That's because moving from Client/Server to Web the TERMINAL column in V$SESSION becomes useless.
    I tried your solution, but I had to give up with it, because in my Forms9i application some forms call Reports, which generate a new session.
    I decided to use DBMS_APPLICATION_INFO, and this is satisfactory for my requirements, but I'm interested to discover other solutions.
    P.S. with my solution I'm able to limit accesses, because in the CLIENT_INFO string I put, among other things, the
    application user, so I can control if an user is already connected. The problem is that existing applications have to be modified .....:-(

  • How to avoid multiple password prompt for intarnet portal

    we have developed a intranet portal in Share Point 2013 with multiple site collection. when accessing through IE, Chrome, we can do settings to avoid multiple password prompt by adding the domain name of site in Trusted sites. How we can achieve the same in Safari while accessing through MAC or IPAD

    first time when you call the BSP application from the browser (or by double clicking the BSP_APPLICATION link from SAP GUI) you need to pass user credentials. For further windows this will not be required as browser will remember your info.
    if you need to <b>somehow</b> avoid this then the only option is to hard code the user id and password in the service in transaction SICF or by passing the same via URL.
    Another option is that if you port this application in a SAP portal environment, SSO can be used .
    Hope this helps.
    Regards
    Raja

  • How to avoid multiple DataConnections with LCD ES2

    Hi, we are just starting using the data connections to connect via a database with LiveCycle Designer. It seems we are missing something important regarding to manipulation of data from the PDF.
    At first we have tried to apply a INSERT command to our first table and be able to browse through the items in the database. We are able to browse through the database only before we have inserted something.
    If we insert an item and then try to browse through the database with (Next, Previous, Last or First) it will crash and have an error of the following :
    (Next, Previous, Last or First) failed. Multiple-step operation generated errors. check each status value [ID:@11]
    So then we have decided to create a second data connection which would have each of the column in the database except for the ID which appears to make everything crash.
    E.G.:  Table_1
    DataConnection1 --> ID, Field1, Field2, Field3, Field4          SELECT Command connection
    DataConnection2 --> Field1, Field2, Field3, Field4               INSERT Command connection
    Seems like we can't have a SELECT and INSERT in the same DataConnection because with those 2 different connections it works fine....
    Then we are trying to show multiple data's in a table which is linked with the ID of the Selected ID in DataConnection1.. To show the data is all fine using a 3rd connection for that Table_2, then we are making sure a blank row is always there at the end of the table to be able to add this new entry to the database with a Add button to INSERT into the Table_2... Unfortunately we do not have a 2nd connection to that table because we cannot link those fields with the database for the purpose of a multiple entry view.
    We have tried to make a 2nd connection for the purpose of the INSERT but it doesnt work at all.
    We are basing ourselves on the sample provided by Stefan Cameron in his blog http://forms.stefcameron.com/2006/12/18/databases-inserting-updating-and-deleting-records/
    I am wondering if we are using the right functionalities and if it is the simplest way to work with databases...
    If anyone can help, it would be greatly appreciated!!
    Thanks in advance!
    Mag

    Don't forget to activate the RESOURCE_LIMIT parameter, which default is FALSE :
    alter system set RESOURCE_LIMIT = true;
    Laurent, I had a similar problem some time ago : I didn't want to avoid multiple access, but only control who was doing what. That's because moving from Client/Server to Web the TERMINAL column in V$SESSION becomes useless.
    I tried your solution, but I had to give up with it, because in my Forms9i application some forms call Reports, which generate a new session.
    I decided to use DBMS_APPLICATION_INFO, and this is satisfactory for my requirements, but I'm interested to discover other solutions.
    P.S. with my solution I'm able to limit accesses, because in the CLIENT_INFO string I put, among other things, the
    application user, so I can control if an user is already connected. The problem is that existing applications have to be modified .....:-(

  • How to unrigister the call back function,in vb6 with DAQmx 8.5

    I use daqmx api which named DAQmxRegisterEveryNSamplesEvent to register my call back function,When I invoke the function  DAQmxErrChk (DAQmxStopTask(taskHandleAnalog)) to stop my Task.then i call the procedure AD_OPEN  again,it raise an error ,tell me that i need to unregister the event,the data has transfer into the buffer.how can i unregister the event,please look at the following code.
    Spoiler (Highlight to read)
    Private Sub create()
       Dim channel As String
        Dim minVoltage, maxVoltage As Double
        Dim samplesPerChannelPerRead As Double
        Dim sampleMode As Long
        Dim boolVal As Boolean
        On Error GoTo AdErrorHandler:
        ' Get values from UI controls
        channel = "Dev2/ai1:2"
        minVoltage = -10
        maxVoltage = 10
        samplesPerChannelPerRead = 100
         If (taskHandleAnalog <> 0) Then
             DAQmxErrChk (DAQmxStopTask(taskHandleAnalog))
            DAQmxErrChk (DAQmxClearTask(taskHandleAnalog))
            taskhandle = 0
        End If
        ' Configure the task
        DAQmxErrChk (DAQmxCreateTask("", taskHandleAnalog))
         DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandleAnalog, "Dev2/ai0", "", DAQmx_Val_InputTermCfg_RSE, minVoltage, maxVoltage, DAQmx_Val_VoltageUnits2_Volts, vbNullString))
        DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandleAnalog, channel, "", DAQmx_Val_InputTermCfg_Diff, minVoltage, maxVoltage, DAQmx_Val_VoltageUnits2_Volts, vbNullString))
    End Sub
    Private Sub AD_Open()
        DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandleAnalog, "", 200, DAQmx_Val_Rising, DAQmx_Val_AcquisitionType_ContSamps, samplesPerChannelPerRead))
        'Find number of samples specified
        DAQmxErrChk (DAQmxGetTaskNumChans(taskHandleAnalog, numChannels))
        'Configure Event Callbacks
        DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(taskHandleAnalog, 1, 4, 0, AddressOf EveryNSamplesEventHandler1, Nothing))
     ReDim dataBuffer(numChannels * samplesPerChannelPerRead - 1)
        ' Start the DAQmx Task
    '    DAQmxErrChk (DAQmxCfgDigEdgeStartTrig(taskHandleAnalog, "/Dev1/PFI2", DAQmx_Val_Edge1_Falling))
        DAQmxErrChk (DAQmxStartTask(taskHandleAnalog))
        ' Update UI
        Exit Sub
    AdErrorHandler:
        MsgBox Err.Description
    End Sub

    This may be a bit late, so hopefully you found this on your own. But in order to unregister the event pass a null value for the callback function parameter in the DAQmxRegisterEveryNSamplesEvent function (Nothing in VB).
    National Instruments
    Product Support Engineer

  • How to avoid multiple users to access same tcode

    Hi all,
    Am creating one z tcode to display the material details for the particular reservation number. How can  I avoid multiple users to access the same tcode simultaneously. If anybody works over that tcode then no other user should be able to access the same tcode until or unless the first user works over it.
    Regards,
    Ramya

    HI,
    you can even use import and export logic and check if user has entered the transaction ..
    Regards,
    Santosh
    Message was edited by:
            Santosh Kumar Patha

  • How to avoid multiple if else using design patterns.

    Hi,
    Which design patterns is used to avoid lot of if else in our code . Say for example if the user press 1 the out put should be one, if he press 2 it should be two like this upto 10. So we need to include lot of if-else part. How to avoid the multiple if else using design patter for this scenario. I can't find the solution for this problem can you guys help me?.

    I'm too lazy to read a whole text book, but the first google link provides a code sample which made me laugh.
    http://www.refactoring.com/catalog/replaceConditionalWithPolymorphism.html
      double getSpeed() {
        switch (_type) {
          case EUROPEAN:
            return getBaseSpeed();
          case AFRICAN:
            return getBaseSpeed() - getLoadFactor() * _numberOfCoconuts;
          case NORWEGIAN_BLUE:
            return (_isNailed) ? 0 : getBaseSpeed(_voltage);
        throw new RuntimeException ("Should be unreachable");
      }My implementation of The Bridge Over The Parrot Shop
    package forums;
    import java.util.Random;
    abstract class Bird {
      private static final Random random = new Random();
      abstract double getAirSpeed();
      public double getBaseSpeed() {
        return randomDouble(18.96);
      protected static double randomDouble(double max) {
        return random.nextDouble() * max;
      protected static int randomInt(int max) {
        return random.nextInt(max);
    class EuropeanSwallow extends Bird {
      double getAirSpeed() {
        return getBaseSpeed();
    class AfricanSwallow extends Bird {
      private int _numberOfCoconuts;
      public AfricanSwallow() {
        this(randomInt(4));
      public AfricanSwallow(int numberOfCoconuts) {
        _numberOfCoconuts = numberOfCoconuts;
      double getAirSpeed() {
        return getBaseSpeed() - getLoadFactor() * _numberOfCoconuts;
      public double getLoadFactor() {
        return randomDouble(3.12);
    class NorwegianBlue extends Bird {
      private boolean _isNailed;
      private double _voltage;
      public NorwegianBlue() {
        this(randomInt(10)<2, randomDouble(12.0));
      public NorwegianBlue(boolean isNailed, double voltage) {
        _isNailed = isNailed;
        _voltage = voltage;
      double getAirSpeed() {
        return _isNailed ? 0 : getBaseSpeed(_voltage);
      double getBaseSpeed(double voltage) {
        return getBaseSpeed() * (1+(voltage/Math.PI));
    public class AirSpeedTest
      public static void main(String[] args)
        System.out.println("EUROPEAN: "+new EuropeanSwallow().getAirSpeed());
        System.out.println("AFRICAN: "+new AfricanSwallow().getAirSpeed());
        System.out.println("NORWEGIAN_BLUE: "+new NorwegianBlue().getAirSpeed());
    }... and the requisite background for the uninitiated [NORWEGIAN_BLUE|http://www.youtube.com/watch?v=4vuW6tQ0218] and [EUROPEAN v AFRICAN|http://www.youtube.com/watch?v=4b4bGAoVR7g].
    You have to know these things when you're a King you know.
    Cheers. Keith.

  • Query: how to avoid multiple POs  from being combined into  delivery

    Hi all,
    We are working on an enhancement.
    The requirement is:
    We need to avoid multiple POs from being combined into one delivery.
    Any pointers in this regard would be highly appreciated.
    regards
    Gurpreet

    Hi Murali,
    I think your suggestion should solve Gurpreets problem.
    I have a query here.
    In the copy controls VLTA, defines between sales doc to dlivery doc.
    Here we want to maintain copy control between purchasing doc to delivery doc.
    How do we achive this?
    Also in my view we should write a new combination requirement.
    Please check if combination requirement 51 can be used?
    Regards
    Abhishek

  • How to avoid multiple selection in ALV tree control?

    Hi,
    Experts,
    I want to avoid multiple selections on Alv tree control after pressing control keyboard button(Ctrl). Even by pressing Ctrl keyword button i want to select only one row of a Alv tree control.i have used cl_salv_tree class for it is there any method to achieve this please pass some code/idea on it.
    Thanks in advance,
    Shabeer ahmed.

    I haven't tried it before but it should help.
    [https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/cda3992d-0e01-0010-90b2-c4e1f899ac01|https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/cda3992d-0e01-0010-90b2-c4e1f899ac01]

  • How to get a called procedure/function name within package?

    Hi folks,
    is it possible to obtain a called procedure/function name within package?
    For a measuring and tracing purpose, I would like to store an info at the beginning of each procedure/function in package with timestamp + additional details if needed.
    For example:
    CREATE OR REPLACE PACKAGE BODY "TEST_PACKAGE" IS
       PROCEDURE proc_1 IS
       BEGIN
          api_log.trace_data(sysdate, 'START.' || ???????);
          api_log.trace_data(sysdate, 'END.' || ???????);
       END;
       PROCEDURE proc_2 IS
       BEGIN
          api_log.trace_data(sysdate, 'START.' || ???????);
          proc_1;
          api_log.trace_data(sysdate, 'END.' || ???????);
       END;
    END; I would like to replace "???????" with a function which would return a name of called procedure, so result of trace data after calling TEST_PACKAGE.proc_2 would be:
       11.1.2013 09:00:01    START.*TEST_PACKAGE.proc_2*
       11.1.2013 09:00:01    START.*TEST_PACKAGE.proc_1*
       11.1.2013 09:00:01    END.*TEST_PACKAGE.proc_1*
       11.1.2013 09:00:01    END.*TEST_PACKAGE.proc_2*I tried to use "dbms_utility.format_call_stack" but it did not return the name of procedure/function.
    Many thanks,
    Tomas
    PS: I don't want to use an hardcoding

    You've posted enough to know that you need to provide your 4 digit Oracle version (result of SELECT * FROM V$VERSION).
    >
    is it possible to obtain a called procedure/function name within package?
    For a measuring and tracing purpose, I would like to store an info at the beginning of each procedure/function in package with timestamp + additional details if needed.
    >
    I usually use this method
    1. Create a SQL type for logging information
    2. Put the package name into a constant in the package spec
    3. Add a line to each procedure/function for the name.
    Sample package spec
          * Constants and package variables
              gc_pk_name               CONSTANT VARCHAR2(30) := 'PK_TEST';Sample procedure code in package
          PROCEDURE P_TEST_INIT
          IS
            c_proc_name CONSTANT VARCHAR2(80)  := 'P_TEST_INIT';
            v_log_info  TYPE_LOG_INFO := TYPE_LOG_INFO(gc_pk_name, c_proc_name); -- create the log type instance
          BEGIN
              NULL; -- code goes here
          EXCEPTION
          WHEN ??? THEN
              v_log_info.log_code := SQLCODE;  -- add info to the log type
              v_log_info.log_message := SQLERRM;
              v_log_info.log_time    := SYSDATE;
              pk_log.p_log_error(v_log_info);
                                    raise;
          END P_PK_TEST_INIT;Sample SQL type
    DROP TYPE TYPE_LOG_INFO;
    CREATE OR REPLACE TYPE TYPE_LOG_INFO AUTHID DEFINER AS OBJECT (
    *  NAME:      TYPE_LOG_INFO
    *  PURPOSE:   Holds info used by PK_LOG package to log errors.
    *             Using a TYPE instance keeps the procedures and functions
    *             independent of the logging mechanism.
    *             If new logging features are needed a SUB TYPE can be derived
    *             from this base type to add the new functionality without
    *             breaking any existing code.
    *  REVISIONS:
    *  Ver        Date        Author           Description
    *   1.00      mm/dd/yyyy  me               Initial Version.
        PACKAGE_NAME  VARCHAR2(80),
        PROC_NAME     VARCHAR2(80),
        STEP_NUMBER   NUMBER,
        LOG_LEVEL   VARCHAR2(10),
        LOG_CODE    NUMBER,
        LOG_MESSAGE VARCHAR2(1024),
        LOG_TIME    TIMESTAMP,
        CONSTRUCTOR FUNCTION type_log_info (p_package_name IN VARCHAR2 DEFAULT 'Uninitialized',
                                            p_proc_name IN VARCHAR2 DEFAULT 'Uninitialized',
                                            p_step_number IN NUMBER DEFAULT 1,
                                            p_LOG_level IN VARCHAR2 DEFAULT 'Uninit',
                                            p_LOG_code IN NUMBER DEFAULT -1,
                                            p_LOG_message IN VARCHAR2 DEFAULT 'Uninitialized',
                                            p_LOG_time IN DATE DEFAULT SYSDATE)
                    RETURN SELF AS RESULT
      ) NOT FINAL;
    DROP TYPE BODY TYPE_LOG_INFO;
    CREATE OR REPLACE TYPE BODY TYPE_LOG_INFO IS
        CONSTRUCTOR FUNCTION type_log_info (p_package_name IN VARCHAR2 DEFAULT 'Uninitialized',
                                            p_proc_name IN VARCHAR2 DEFAULT 'Uninitialized',
                                            p_step_number IN NUMBER DEFAULT 1,
                                            p_LOG_level IN VARCHAR2 DEFAULT 'Uninit',
                                            p_LOG_code IN NUMBER DEFAULT -1,
                                            p_LOG_message IN VARCHAR2 DEFAULT 'Uninitialized',
                                            p_LOG_time IN DATE DEFAULT SYSDATE)
         RETURN SELF AS RESULT IS
        BEGIN
          self.package_name  := p_package_name;
          self.proc_name     := p_proc_name;
          self.step_number   := p_step_number;
          self.LOG_level   := p_LOG_level;
          self.LOG_code    := p_LOG_code;
          self.LOG_message := p_LOG_message;
          self.LOG_time    := p_LOG_time;
          RETURN;
        END;
    END;
    SHO ERREdited by: rp0428 on Jan 11, 2013 10:35 AM after 1st cup of coffee ;)

Maybe you are looking for

  • Running Photoshop CS 6 on my Windows 7 desktop and now I just purchased a Mac Pro laptop

    I just purchased a Mac Pro laptop and would like to run Photoshop CS 6 I currently am using my desktop which is Windows 7 what is the best way to purchase a license for my laptop

  • Safari crashing with gmail: new event since Sept 2011

    Safari repeatedly crashes when Igoogle (has access to gmail) or gmail is signed in. I have tried: Installing security updates for safari Clearing the cache Clearing history Clearing the keychain and updating passwords Posting a question to the gmail

  • Forecasting Alerts in SCM 7.0

    Hello, I'm trying to set up forecasting alerts in an SCM 7.0 system. In previous releases it was just selecting the required alerts and go, however in this release I cannot get it to work. I'm trying to get simple alerts like MAD / MAPE upper limit e

  • Combining Statments In A Formula

    I'm trying to combine all records with a closed date and rejection_withdrawal date in two different columns in a table. If I run each of the below statements separately, I get 520 for for closed date and 382 for rejection_withdrawal date, but when I

  • Configuring BO DB params in Solaris

    Hi, I am trying to setup the BO XI 3.1 server on Solaris 10.  I have imported the .biar file however I am not able to make the reports point to the correct Reporting DB to generate the reports. Curently I due to teh network settings I am unable to us