Using custom functions in a query

Hi, I have a query in a PLSQL procedure where some of the fields are data retreived from custom functions,
i. e.
select a, b, funcThatNeedsA(a), funcThatNeedsB(b)
from xxxx
where ...
but I also could use those functions by making a loop to a cursor
i. e.
cursor c_data is select a, b from xxxx where ...
for r_data in c_data loop
l_a = funcThatNeedsA(r_data.a);
l_b = funcThatNeedsB(r_data.b);
end loop;
So, my question is: what is more efficient, to use the functions directly in the query or in a loop of a cursor?

the overhead of calling your functions will not change based on using them in a loop vs a cursor. the concern is the performance of ANY loop vs not using a loop at all. so what else are you doing in the loop? does it really need to be in a loop? for example, this
insert into a select * from b
is faster than
for rec in (select * from b) loop insert into a values(rec); end loop;

Similar Messages

  • Error in using aggregate function in Outer Query in Siebel Analytics

    Hi,
    When I am using aggregate function in outer query in Siebel Analytics I am facing error.
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P:OI2DL65P
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 59111] The SQL statement must include a GROUP BY clause. (HY000)
    Bellow is the code.
    SELECT test1.username saw_0, test1.desg saw_1,COUNT (test2.querydate) saw_2
    FROM (SELECT POSITION.CBL username,
    POSITION.CBP desg
    FROM "CM"
    WHERE (POSITION.BPTCD = 'Marketing')
    AND (POSITION.EDate =TIMESTAMP '1899-01-01 00:00:00'
    ) test1,
    (SELECT users.UN username,
    measures."Query Count" querycount,
    measures."Max Total Time" secs,
    topic.db dashboardname,
    "Query Time".DATE querydate
    FROM "Plan"
    WHERE (topic."Dashboard Name" IN ('DS'))) test2
    WHERE test2.username = LOWER (test1.username)
    AND test2.dashboardname = 'DS'
    GROUP BY test1.username, test1.desg

    Should your query be a valid SQL query?
    I can't think that the query you have would be valid in a SQL plus window.
    Chris

  • Can I use table function inside Dynamic query ?

    Dear Gurus,
    I have following code
    DECLARE
    TYPE CRITERIA_LIST_TABLE AS TABLE OF VARCHAR2(20);
    OtherNoList CRITERIA_LIST_TABLE; /* CRITERIA_LIST_TABLE is index by table*/
    QUERY_STRING VARCHAR2(4000);
    BEGIN
    OtherNoList := CRITERIA_LIST_TABLE();
    SELECT DISTINCT REGEXP_SUBSTR('1,5,6,4', '[^\,]+',1, LEVEL ) BULK COLLECT INTO OtherNoList
    FROM DUAL
    CONNECT BY LEVEL <= REGEXP_COUNT('1,5,6,4', '\,') + 1 ;
    QUERY_STRING := 'INSERT INTO TAB1 (C1,C2) '||
    'SELECT C1,'||
    'C2 '||
    'FROM TAB1 ,'||
    'TABLE( '||
              'CAST (OtherNoList AS CRITERIA_LIST_TABLE) '||
                   ') OTHRNOS '||
    'WHERE TAB1.C1 = OTHRNOS.COLUMN_VALUE ';
    DBMS_OUTPUT.PUT_LINE('Query String is '||QUERY_STRING);
    EXECUTE IMMEDIATE QUERY_STRING;
    END;
    Can I use Table function inside dynamic query.
    Thanking in advance
    Sanjeev

    Try:
    DECLARE
    TYPE CRITERIA_LIST_TABLE AS TABLE OF VARCHAR2(20);
    OtherNoList CRITERIA_LIST_TABLE; /* CRITERIA_LIST_TABLE is index by table*/
    QUERY_STRING VARCHAR2(4000);
    BEGIN
    OtherNoList := CRITERIA_LIST_TABLE();
    SELECT DISTINCT REGEXP_SUBSTR('1,5,6,4', '[^\,]+',1, LEVEL ) BULK COLLECT INTO OtherNoList
    FROM DUAL
    CONNECT BY LEVEL <= REGEXP_COUNT('1,5,6,4', '\,') + 1 ;
    QUERY_STRING := 'INSERT INTO TAB1 (C1,C2) '||
    'SELECT C1,'||
    'C2 '||
    'FROM TAB1 ,'||
    'TABLE( '||
    'CAST (:OtherNoList AS CRITERIA_LIST_TABLE) '||
    ') OTHRNOS '||
    'WHERE TAB1.C1 = OTHRNOS.COLUMN_VALUE ';
    DBMS_OUTPUT.PUT_LINE('Query String is '||QUERY_STRING);
    EXECUTE IMMEDIATE QUERY_STRING using OtherNoList;
    END;p.s. not tested
    Amiel Davis

  • Inconsistent Errors when processing  IDocs using custom Function Module

    I am encountering a most perplexing error. Here is the situation.
    We have a custom function module to update data in the EH&S system. We are having a bizarre error occurring. This is the basic processing of the function module:
    1. IDoc data is read and loaded into an internal table.
    2. Data is run through a series of checks to determine if the data is valid for entry into the system.
    3. After validation we use function module  C1F2_SUBSTANCES_READ_WITH_REF to read  characteristic data for the  substance. This data is used to validate whether current data exists to allow for loading of the IDoc data. (This is the step where the IDoc is receiving an error even if the data is valid. This only occurs if we are processing a large amount of Idocs and one IDoc contains valid data and another invalid data for the same substance. It occurs even if the Idocs are not processed in sequence.  If individually processed or reprocessed after initial failure they pass. This is what is so confusing!) If it exists, a flag is set and  the data is loaded using function module BAPI_BUS1077_CHANGE to modify the data.
    4. If the flag is set to allow further processing, the function module C1F2_SUBSTANCES_READ_WITH_REF is used again to select different characteristic data for the substance. A similar validation process occurs and if it passes, data is loaded using BAPI_BUS1077_CHANGE to update and BAPI_BUS1077_CREATE to create new data.
    Here is the situation:
    When processing one valid record for one substance, the record loads successfully.  When processing multiple valid records (all are valid) for one substance, they all load successfully.  The problem occurs when attempting to load valid and invalid records for the same substance.  Some times the program successfully loads the valid data (as expected).  Other times, it will not load any records.  It is not consistent!
    The order of IDoc processing does not have an impact on the success of the load.  Whether the valid or invalid record processes first does not have an impact on the success of the valid substance load.
    Does anyone have ANY Idea of what is going on? I am clearing all fields in the function module before processing occurs. I cannot find what is causing the error to occur.
    HELP!
    Jim Hardy

    I have some further information. It seems that if data for a substance is sent in two separate Idocs, one with valid and one with invalid data, As long as the two IDocs are processed consecutively, they process correctly. If they are separated by IDocs containing other substance information, they fail.
    thanks
    Jim

  • Using Custom function in Validation

    I have a custome function that returns a varchar of TRUE or FALSE.
    I have tested the function and even hardcoded with TRUE.
    However when I use it in the Validation and even thought all lines return True they get pushed into the Fail table.
    I have the rule Enabled and action on Fail is set to "Send To Fail"
    I have printed out the data being returned and all Pass so why are they being sent to the Fail.
    I call the function like this.
    So I assume that if the vlaue returned is True it should go to the true table.
    P2CMM01_LKP_STORAGE_LOC("Material Type(MTART)", "+STORAGE_LOCATION","+MATERIAL_NUMBER") = 'True'

    what is the value returned by the function True or False or TRUE or FALSE ?
    you will have to do a case-sensitive comparision
    TRUE = True  will fail

  • SIT on SSHR using custom function

    Dear Group,
    I am implementing SSHR for a customer, the customer needs to have some special request that need to be entered from SSHR then follow an approval path.
    So I have created a SIT and copy the original process using workflow and create a custom function in SSHR with different parameter for process and pCalledfrom.
    My problem is that the with I try to display my segment only it’s not getting displayed
    For example:
    SIT: XX_Ticket_Request
    Segments:
    No_Ticket_Request
    Ticket_Type
    In the personalization:
    In the segment field I wrote:
    XX_Ticket_Request|SEGMENT1| SEGMENT2| SEGMENT3|
    Nothing is displayed only start date and new date if I try to insert a new line the required segment are displayed.
    How I can display the required fields only. before insert mode.

    You need to use the name of the flex segments, not the columns, e.g.,:
    XX_Ticket_Request|No_Ticket_Request|Ticket_Type|
    Let us know if that works!

  • Adding Fields to Custom Infotype Using Custom Infoset in SAP QUERY

    Hi All,
    We have a requirement to add fileds to a custom infotype for querying Custom Infoset in SAP Query.
    We are facing problem as the added field is not getting displayed in the Query set so that we can select and display it in the Basic List along with the other filds.
    Kindly suggest a solution.
    Full points will be rewarded.
    Thanks in Advance
    Kumar

    Hi Salman,
    Thank you for your valuable information. I haven't Configured Dynamic Actions yet. Is it simple to write the Logic for Dynamic Actions. Is this the only way to solve this Issue?
    I tried by adding the standard fields, but they are not populating the values; but just appearing as Input Fields with Input help option.
    Please let me know if you have any suggestion in this direction?
    Regards,
    Hems.

  • How to use custom function.

    i write a custom funciton contain a sql sentence like this:
    SELECT sum(QTY) INTO SUM_OUTPUTQTY FROM V_DW_SALE_INVOICE
    WHERE V_DW_SALE_INVOICE.INVOICEDATE LIKE 'aaa%' AND
    P2=MENUFACTURER_ID AND P3=METERIELNAME AND P4 =SPEC AND
    P5=ORG_ID;
    the table V_DW_SALE_INVOICE is in the source database.
    when i deploy the function,it response table or view is not exist.
    how to deploy the function?
    thx

    How did you create your custom function? The step-by-step instructions are in the User Guide here http://download.oracle.com/docs/html/B12146_01/maptransf.htm#i1149862 Note you can also import existing PL/SQL packages as described there.
    Minor comment: INTO [variable] is a PL/SQL element, not SQL.
    Nikolai Rochnik

  • Update the custom table by using Custom Function module.

    Hi Experts,
            My requirement is ,
    1) To create the Custom Z table with fields
               vbak-vbeln
               likp-vbeln
               vbuk-vbeln
      After creating this Z table.
    2) I have to create one custom function module.
        Based on this function module i have to update that Z table.
    3) Before these steps i have to write down an ALV report based on the tables vbak and vbeln, in that table i have to print vbak-vbeln. and also in report i generated check box and one custom button in application toolbar. after the report will displayed , when ever i click the button in application tollbar , this function module will executed and the table will be updated.
        But I developed the ALV report with custom button and check box successfully.
      My doubt is how to write the function module and based on that function module how to update the table.
          Please suggest me on this requirement.
        Thanks in Advance.
    Thanks and Regards
    Srihari.

    HI ,
         Can any one help me out on my above requiremnet..
    Thanks and Regards
    Srihari.

  • Problem using DECODE() function with a Query of Queries

    I
    posted
    on my blog about an issue I was having trying to use the PL/SQL
    DECODE() function with a Coldfusion Query of Queries. This function
    works fine when you query a database for information. However, when
    you query another query, it seems that CF doesn't recognize it. I
    got errors stating that it found a left parenthesis where it
    expected a FROM key word. Here is a simplified version of what I am
    trying to do:
    quote:
    <!--- Simulated query; similar to what I was calling from
    my database --->
    <cfscript>
    qOriginal = queryNew("Name,Email,CountryCode",
    "VarChar,VarChar,VarChar");
    newRow = queryAddRow(qOriginal, 5);
    querySetCell(qOriginal, "Name", "Joe", 1);
    querySetCell(qOriginal, "Email", "[email protected]", 1);
    querySetCell(qOriginal, "CountryCode", "AMER", 1);
    querySetCell(qOriginal, "Name", "Sally", 2);
    querySetCell(qOriginal, "Email", "[email protected]", 2);
    querySetCell(qOriginal, "CountryCode", "AMER", 2);
    querySetCell(qOriginal, "Name", "Bob", 3);
    querySetCell(qOriginal, "Email", "[email protected]", 3);
    querySetCell(qOriginal, "CountryCode", "ASIA", 3);
    querySetCell(qOriginal, "Name", "Mary", 4);
    querySetCell(qOriginal, "Email", "[email protected]", 4);
    querySetCell(qOriginal, "CountryCode", "EURO", 4);
    querySetCell(qOriginal, "Name", "John", 5);
    querySetCell(qOriginal, "Email", "[email protected]", 5);
    querySetCell(qOriginal, "CountryCode", "EURO", 5);
    </cfscript>
    <cfquery name="qCountries" dbtype="query">
    SELECT DISTINCT(CountryCode) AS CountryCode,
    DECODE(states, "AMER", "North America &amp; Canada",
    "EURO", "Europe &amp; Africa", "ASIA", "Japan &amp;
    Asia","") CountryName
    FROM qOriginal
    ORDER BY CountryCode
    </cfquery>
    <cfdump var="#qCountries#">
    <!--- ========== END OF CODE ========== --->
    So running this returned the following error:
    Query Of Queries syntax error.
    Encountered "(. Incorrect Select Statement, Expecting a
    'FROM', but encountered '(' instead, A select statement should have
    a 'FROM' construct.
    Does anybody know why this doesn't work? Is it just not
    supported? Please note that I have also tried to use the CASE()
    function instead of DECODE() and that resulted in basically the
    same error. For now I an looping over my distinct query with a
    switch statement and manually loading a new query with the data how
    I want it. But it would be a lot cleaner and less code to have the
    DECODE() to work. Thx!

    DECODE() is an Oracle function, not generic SQL. Q-of-Q is a
    very limited subset of SQL and lacks many functions and clauses
    available in standard SQL, especially what you may be used to using
    in your particular RDBMS.
    See
    Query
    of Queries user guide
    Phil

  • Replace Values for a Col under a Table using Replace Function in Sql Query

    Hi all
    I have a Custom Table by Name RESP_TABLE which stores the Responsibility Names under the Column RESPONSIBILITY.
    The Sample Value for this col is as follows :
    PF <CNTRY> Gl Analyst <CCY>.
    This <CNTRY> Stands for Country Short Name
    and <CCY> Stands for Currency.
    The <CNTRY> & <CCY> should be passed as a parameter at the run time.
    Based on the value given at the run time it should change accordingly.
    For example
    PF <CNTRY> Gl Analyst <CCY>
    <CNTRY> Value passed at runtime : BE
    <CCY> Value passed at runtime : CAD
    So the resulting value should be as follows :
    PF BE Gl Analyst CAD.
    I had already used the query given below :
    SELECT REPLACE(RESPONSIBILITY,'<CNTRY>','&MARKET') FROM RESP_TABLE.
    This works fine for Country Code alone but not for currency.
    I need both the Country Code and Currency Code to be changed to the respective values given at the runtime.
    Could anybody please help me on this ?
    Regards
    Nakul Venkataraman.

    Hi Nakul,
    Why not just adding another REPLACE to what you still have achieved? :)
    Regards,
    Guido

  • Optmizing use of function in a query

    select a1.*, test_pkg.test_function(section_id) record_id
    from (
    select project_id, student_id, max(se.section_id) section_id
    from college c, students s, sections se, zone z
    where c.college_id in (121, 123, 124)
    and s.student_id = c.student_id
    and s.section_id = z.response_id
    and z.section_id = s.section_id
    group by c.project_id, s.student_id) a1;
    the question is I am hitting the test_pkg.test_function for each student_id
    I want it only in case the section_id is different i.e for unique section_id..
    right now i use the inner query to populate the table and then use a cursor to update the
    record_id. this is fast since in the cursor i hit the funtion only for unique section_id's
    Is there a way to make my query faster and in 1 go instead of updating it later...
    I mean can i populate the table using a single query...
    NOTE: May be the joins are wrong, i just manipulated them.....
    using oracle 10g
    thank you

    Something else you can try is to use an inline view. Here when you say you only have 1500 sections, i'm assuming that's the number of records in your section table. I've also added the NO_MERGE hint in to this so that the optimizer doesn't decide to merge this inline query into the rest of the joins (then it would apply the function many more times).
    select project_id, student_id, max(se.section_id) section_id, se.record_id
    from college c, students s, (select /*+ NO_MERGE */ section_id, test_pkg.test_function(section_id) as record_id from sections) se, zone z
    where c.college_id in (121, 123, 124)
    and s.student_id = c.student_id
    and s.section_id = z.response_id
    and z.section_id = s.section_id
    [pre]
    as you said in your original post, the joins are not all correct (there is NO join to the sections table in your query....i'd assume there should be one.
    If the performance of that isn't acceptable you could look into making a materialized view, or a function based index, etc...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Unable to use string function in REST query

    I am querying for duplication of column name in the web using REST query. My query is as per below:
    http://siteCollection/sites/Project1/_api/Web/Fields?$select=InternalName&$filter=toupper(InternalName) eq 'TITLE'.
    The reference I got from MSDN site. But whenever I am running the same query in the REST Client I am getting following error:
    The function operator 'toupper' is not supported or its usage is invalid.
    What am I missing in my query? Or this is not a way for doing the case insensitive query then which way is preferable?

    toupper is
    not supported. Below is the list of
    supported functions
    On the other hand if you use ListData.svc endpoint
    you can use toupper to
    perform a similar query.

  • Cannot use MAX function in PS Query

    I am trying to use Query to select the max ( effdt ) from a table.
    First, I use the 'Criteria' page to have
    (1) Expression 1 = A.EFFDT - Effective Date, (2) Condition type = equal to, (3) Expression 2 = Subquery
    Then the Subquery is:
    (1) In the 'Field' page, I choose field E.EFFDT - Effective Date, (2) then click on 'EDIT', (3) then click on 'Max', (4) then click on 'OK' button
    I then get this message: 'This field is an aggregate field but is being used in non-having criteria.(139,136). The query may fail if this is not corrected'
    And as i try run anyway this query, i get this message:
    SQL error. Stmt #: 5653 Error Position: 349 Return: 934 - ORA-00934: group function is not allowed here
    A SQL error occurred. Please consult your system log for details.
    Error in running query because of SQL Error, Code=934, Message=ORA-00934: group function is not allowed here (50,380)
    NOTE: This max sql would work if i run using SqlPlus
    How can i get Query to use max( effdt ) ?
    Any clue anyone ? THANKS

    Yes Using it as MAX is OK.
    Problem is once you use it as MAX of a field, it wouln't allow this field for you to use it anymore.
    A workaround i found that helped is to use the expression let's say 'MAX( a.JOB )' and use this as field.
    This way, the system will allow me to use the JOBCODE field.
    Thank you for all your helps as it leads me to the soln.

  • Segmentation in CRM Marketing - Using customer hierarchy in BI query

    Hi all,
    We are using segmentation in CRM 7.0. As part of this we are creating DataSources based upon BI queries.
    This works fine when we create queries with 0CUSTOMER in the rows. However when we assign a hierarchy to 0customer in the query designer, we are not able to select any customers in segmentation.
    Does anyone know if it is possible to use hierarchies on customer/business partner for segmentation ?
    Thanks Mikkel

    Hi
    I am also having this issue currently , can you let me know if you found any solution to this.
    Thanks
    Manga
    Edited by: Manga Paidikondala on Feb 6, 2011 7:58 AM

Maybe you are looking for

  • SRM 5.0 Installation Documents

    Hi I am planning to install SRM 5.0 Can anybody send me Installation and configuration documents as well as cookbook for the same. I will be really very thankful. My email id is [email protected] Thanks Vitthal prabhu

  • Enter Net Price Error in SRM System

    Dear Gurus, The user has created Purchase order in SRM Portal without flagging 'Confirmation-Related Invoice Verification' and 'Invoice Expected'.  The PO is transferred to R/3 system with '0' price and free goods indicator.  Then the user modified t

  • Can't get Xbox Media Connect to work with WRT54GX4 router

    My Xbox 360 and 2 computers all run through my WRT54GX4 router. They all use wired connections. I can't get Media Connect to work so I can stream pics and videos through my Xbox. I have the correct ports set up and enabled per Xbox instructions. but

  • File Sharing in Portal

    Hi, I need to implement file sharing in Portal. By "File Sharing" I assume i need to utilize the KM functionality i.e creating repository. Is my assumption right? If so, on what criteria i can decide which type of repository to make use of ? Awaiting

  • Importing VHS

    What is the easiest way to import a VHS cassete of football highlights onto my comuter to use on imovie? thanks