Using User Defined Function is SQL

Hi
I did the following test to see how expensive it is to use user defined functions in SQL queries, and found that it is really expensive.
Calling SQRT in SQL costs less than calling a dummy function that just returns
the parameter value; this has to do with context switchings, but how can we have
a decent performance compared to Oracle provided functions?
Any comments are welcome, specially regarding the performance of UDF in sql
and for solutions.
create or replace function f(i in number) return number is
begin
  return i;
end;
declare
  l_start   number;
  l_elapsed number;
  n number;
begin
  select to_char(sysdate, 'sssssss')
    into l_start
    from dual;
  for i in 1 .. 20 loop
    select max(rownum)
      into n
      from t_tdz12_a0090;
  end loop;
  select to_char(sysdate, 'sssssss') - l_start
    into l_elapsed
    from dual;
  dbms_output.put_line('first: '||l_elapsed);
  select to_char(sysdate, 'sssssss')
    into l_start
    from dual;
  for i in 1 .. 20 loop
    select max(sqrt(rownum))
      into n
      from t_tdz12_a0090;
  end loop;
  select to_char(sysdate, 'sssssss') - l_start
    into l_elapsed
    from dual;
  dbms_output.put_line('second: '||l_elapsed);
  select to_char(sysdate, 'sssssss')
    into l_start
    from dual;
  for i in 1 .. 20 loop
    select max(f(rownum))
      into n
      from t_tdz12_a0090;
  end loop;
  select to_char(sysdate, 'sssssss') - l_start
    into l_elapsed
    from dual;
  dbms_output.put_line('third: '||l_elapsed);
end;
Results:
   first: 303
   second: 1051
   third: 1515
Kind regards
Taoufik

I find that inline SQL is bad for performance but
good to simplify SQL. I keep thinking that it should
be possible somehow to use a function to improve
performance but have never seen that happen.inline SQL is only bad for performance if the database design (table structure, indexes etc.) is poor or the way the SQL is written is poor.
Context switching between SQL and PL/SQL for a User defined function is definitely a way to slow down performance.
Obviously built-in Oracle functions are going to be quicker than User-defined functions because they are written into the SQL and PL/SQL engines and are optimized for the internals of those engines.
There are a few things you can do to improve function
performance, shaving microseconds off execution time.
Consider using the NOCOPY hints for your parameters
to use pointers instead of copying values. NOCOPY
is a hint rather than a directive so it may or may
not work. Optimize any SQL in the called function.
Don't do anything in loops that does not have to be
done inside a loop.Well, yes, but it's even better to keep all processing in SQL where possible and only resort to PL/SQL when absolutely necessary.
The on-line documentation has suggested that using a
DETERMINISTIC function can improve performance but I
have not been able to demonstrate this and there are
notes in Metalink suggesting that this does not
happen. My experience is that DETERMINISTIC
functions always get executed. There's supposed to
be a feature in 11g that acually caches function
return values.Deterministic functions will work well if used in conjunction with a function based index. That can improve access times when querying data on the function results.
You can use DBMS_PROFILER to get run-time statistics
for each line of your function as it is executed to
help tune it.Or code it as SQL. ;)

Similar Messages

  • Multi mapping question using user defined function

    Hi,
    I have a message with multiple occuring nodes (i.e. one message with multiple orders (header + detail)) that I need to map to a idoc. I need to filter out of the source based on order type (in header) from creating an idoc.. How do I do it using user defined function + message mappping ?
    mad

    All - Thanks much.. Here is my requirement that is no solved by regular mapping
    <Root>
    <Recordset>
      <Ordheader>
        <ord>
        <ord_type>
      </Ordheader>
       <Ord_line>
         <ord>
         <Linnum>
       </Ord_line>
      </Recordset>
    <Recordset>
      <Ordheader>
        <ord>
        <ord_type>
      </Ordheader>
       <Ord_line>
         <ord>
         <Linnum>
       </Ord_line>
    </Recordset>
    <Root>
    As you see above, each recordset has order transaction. One Root message can contain multiple of these. So, when I map to the IDOC, I want to filter out any ord_type <> XX.
    If I use regular graphical map, it only looks at first recordset and accepts all or rejects all.
    I need to use UDF. In the UDF, what comes in as input ? Resultset is output -correct ? Now how do I usse graphical mapping with UDF to generate the correct target info

  • How to Use Sequence Object Inside User-defined Function In SQL Server

    I'm trying to call sequence object inside SQL Server user-defined function. I used 
    Next Value for dbo.mySequence  to call the next value for my sequence created. But I'm getting an error like below.
    "NEXT VALUE FOR function is not allowed in check constraints, default objects, computed columns, views, user-defined functions, user-defined aggregates, user-defined table types, sub-queries, common table expressions, or derived tables."
    Is there any standard way to call sequence inside a function?
    I would really appreciate your response.
    Thanks!

    The NEXT
    VALUE FOR function cannot be used for User Defined function. It's one of the limitation.
    https://msdn.microsoft.com/en-us/library/ff878370.aspx
    What are you trying to do? Can you give us an example and required output?
    --Prashanth

  • Error in conditional map using User Defined Function

    All,
    In my mapping I basically have a user defined function that returns the filename of my inbound file from the adapter-specific message attributes (file adapter).  I know this is coded properly because if I simply assign this function to my destination field I can see the filename in the payload XML.
    However if I conditionally check that returned value using if,then,else I get an error message stating:
    "During the application mapping com/sap/xi/tf/_MaterialData2ZcustProdMastMulti_ a com.sap.aii.utilxi.misc.api.BaseRuntimeException was thrown: RuntimeException in Message-Mapping transformation"
    Essentially in my if I'm checking if the value returned by my user defined function is equal to the constant "SOMECONSTANT" then I'm setting my destination field to some other constant value.  Otherwise it's equal to a different constant value.
    Any thoughts?

    Claus,
    Thanks for the help.  I actually had figured the problem out on my own.  Sorry for not updating the thread sooner.  What happened was this (as I suspected it wasn't related to my user defined function).  For the newbies out there (of which I'm one) the problem was I was comparing strings in the graphical mapping tool using the Boolean "EQUALS" rather than the Text "EQUALSS".
    Can you give yourself points for solving

  • How to resolve the error while using user defined function.

    EPN Assembly file
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:osgi="http://www.springframework.org/schema/osgi"
    xmlns:wlevs="http://www.bea.com/ns/wlevs/spring"
    xmlns:jdbc="http://www.oracle.com/ns/ocep/jdbc"
    xmlns:spatial="http://www.oracle.com/ns/ocep/spatial"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/osgi
    http://www.springframework.org/schema/osgi/spring-osgi.xsd
    http://www.bea.com/ns/wlevs/spring
    http://www.bea.com/ns/wlevs/spring/spring-wlevs-v11_1_1_3.xsd
    http://www.oracle.com/ns/ocep/jdbc
    http://www.oracle.com/ns/ocep/jdbc/ocep-jdbc.xsd
    http://www.oracle.com/ns/ocep/spatial
    http://www.oracle.com/ns/ocep/spatial/ocep-spatial.xsd">
         <wlevs:event-type-repository>
              <wlevs:event-type type-name="TestEvent">
                   <wlevs:class>com.bea.wlevs.event.example.FunctionCEP.TestEvent</wlevs:class>
              </wlevs:event-type>
         </wlevs:event-type-repository>
         <wlevs:adapter id="InputAdapter"
              class="com.bea.wlevs.adapter.example.FunctionCEP.InputAdapter">
              <wlevs:listener ref="inputStream" />
         </wlevs:adapter>
         <wlevs:channel id="inputStream" event-type="TestEvent">
              <wlevs:listener ref="processor" />
         </wlevs:channel>
         <wlevs:processor id="processor">
              <wlevs:listener ref="outputStream" />
              <wlevs:function function-name="sum_fxn" exec-method="execute">
              <bean>com.bea.wlevs.example.FunctionCEP.TestFunction</bean>
              </wlevs:function>
         </wlevs:processor>
         <wlevs:channel id="outputStream" event-type="TestEvent">
              <wlevs:listener ref="bean" />
         </wlevs:channel>
         <bean id="bean" class="com.bea.wlevs.example.FunctionCEP.OutputBean">
         </bean>
    </beans>
    Event class
    package com.bea.wlevs.event.example.FunctionCEP;
    public class TestEvent {
         private int num_1;
         private int num_2;
         private int sum_num;
         public int getSum_num() {
              return sum_num;
         public void setSum_num(int sumNum) {
              sum_num = sumNum;
         public int getNum_1() {
              return num_1;
         public void setNum_1(int num_1) {
              this.num_1 = num_1;
         public int getNum_2() {
              return num_2;
         public void setNum_2(int num_2) {
              this.num_2 = num_2;
    Adapter class
    package com.bea.wlevs.adapter.example.FunctionCEP;
    import com.bea.wlevs.ede.api.RunnableBean;
    import com.bea.wlevs.ede.api.StreamSender;
    import com.bea.wlevs.ede.api.StreamSource;
    import com.bea.wlevs.event.example.FunctionCEP.TestEvent;
    public class InputAdapter implements RunnableBean, StreamSource {
    private StreamSender eventSender;
    public InputAdapter() {
    super();
    public void run() {
         generateMessage();
    private void generateMessage() {
         TestEvent event = new TestEvent();
         event.setNum_1(10);
         event.setNum_2(20);
         eventSender.sendInsertEvent(event);
    public void setEventSender(StreamSender sender) {
    eventSender = sender;
    public synchronized void suspend() {
    Output Bean class
    package com.bea.wlevs.example.FunctionCEP;
    import com.bea.wlevs.ede.api.StreamSink;
    import com.bea.wlevs.event.example.FunctionCEP.TestEvent;
    import com.bea.wlevs.util.Service;
    public class OutputBean implements StreamSink {
         public void onInsertEvent(Object event) {
              System.out.println("In Output Bean");
              TestEvent event1 = new TestEvent();
              System.out.println("Num_1 is :: " + event1.getNum_1());
              System.out.println("Num_2 is :: " +event1.getNum_2());
              System.out.println("Sum of the numbers is :: " +event1.getSum_num());
    Function Class
    package com.bea.wlevs.example.FunctionCEP;
    public class TestFunction {
         public Object execute(int num_1, int num_2)
              return (num_1 + num_2);
    config.xml file
    <?xml version="1.0" encoding="UTF-8"?>
    <wlevs:config xmlns:wlevs="http://www.bea.com/ns/wlevs/config/application"
    xmlns:jdbc="http://www.oracle.com/ns/ocep/config/jdbc">
         <processor>
              <name>processor</name>
                   <rules>
                   <view id="v1" schema="num_1 num_2">
                        <![CDATA[
                             select num_1, num_2 from inputStream     
                        ]]>
                   </view>
                   <view id="v2" schema="num_1 num_2">
                   <![CDATA[
                   select sum_fxn(num_1,num_2), num_2 from inputStream // I am getting error when i am trying to call this function
                   ]]>
                   </view>
                   <query id="q1">
                        <![CDATA[
                             select from v2[now] as num_2*     // Showing error while accessing the view also               ]]>
                   </query>
              </rules>
         </processor>
    </wlevs:config>
    Error I am getting is :
    Invalid statement: "select >>sum_fxn<<(num_1,num_2),age from inputStream"
    Description: Invalid call to function or constructor: sum_fxn
    Cause: Probable causes are: Function name sum_fxn(int,int) provided is invalid, or arguments are of
    the wrong type., or Error while handling member access to complex type. Constructor sum_fxn of type
    sum_fxn not found. or Probable causes are: Function name sum_fxn(int,int) provided is invalid, or
    arguments are of the wrong type., or Error while handling member access to complex type.
    Constructor sum_fxn of type sum_fxn not found.
    Action: Verify function or constructor for complex type exists, is not ambiguous, and has the correct
    number of parameters.
    I have made a user defined function in a java class and configured this function in the EPN assembly file under the processor tag.
    But when i am trying to access the function in the config.xml file , it is giving me an error in the query.
    Please provide urgent help that how to write the exact query.

    Hi,
    In the EPN Assembly file use
    <bean class="com.bea.wlevs.example.FunctionCEP.TestFunction"/>
    instead of
    <bean>com.bea.wlevs.example.FunctionCEP.TestFunction</bean>
    Best Regards,
    Sandeep

  • Error while using user defined function in reports

    Hi,
    When I use the below user defined function in oracle reports I got the wrong number of arguments error
    select test_function(id,a_number,v_date-14,b_number) from dual;
    If I remove -14 from the argument it works. But iIneed to subtract 14 days from the date.
    Thanks for your help.

    select test_function(id,a_number,v_date-14,b_number) from dual;
    you have to give the command like this to_date(v_date,'dd-mon-yyyy')-14
    because the v_Date you choose in the parameter form is not having the corrent date format
    the format dd-mon-yyyy is the format in which v_date is passed by the user.

  • Getting error while using user-defined function in transform activity

    Hi
    I designed one user-defined function to add 2 nos following the
    link:http://docs.oracle.com/cd/E16764_01/integration.1111/e10224/bp_xslt_mpr.htm .
    Under this i followed the portion creating user-defined function.
    After deploying,i'm getting an error stating:"<summary>
    An error occurs while processing the XPath expression; the expression is ora:doXSLTransformForDoc("xsl/Transformation_1.xsl", $inputVariable.payload).
    </summary>
    <detail>
    XPath expression failed to execute.
    An error occurs while processing the XPath expression; the expression is ora:doXSLTransformForDoc("xsl/Transformation_1.xsl", $inputVariable.payload).
    The XPath expression failed to execute; the reason was: javax.xml.transform.TransformerException: oramds:/deployed-composites/PO/HelloWorld_rev1.0/xsl/Transformation_1.xsl<Line 6, Column 104>: XML-22045: (Error) Extension function error: Class not found '
         Missing class: addition.add
    can anybody help me in this regard     
    Thanks
    Avinash

    Did you copy the jar file of your java classes to MIDDLEWARE_Home/user_projects/domains/soa_domain/lib?
    http://georgie-soablog.blogspot.com/2010/06/soasuite-11g-implement-user-defined.html
    hope this helps

  • Error when use User-Defined Function

    I just create User defined function "getfilename" and I put there:
    "DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
    String ourSourceFileName = conf.get(key);
    return ourSourceFileName; ".
    But In test mapping I have worning:
    "Runtime exception during processing target field mapping /ns1:Z_KBFI_INPUT_FILE/IS_IFILE/FILE_NAME. The message is: Exception:[java.lang.NullPointerException] in class com.sap.xi.tf._KBFIMsgMapping_ method get_fname$[com.sap.aii.mappingtool.tf3.rt.Context@37d4662c] com.sap.aii.mappingtool.tf3.MessageMappingException: Runtime exception during processing target field mapping /ns1:Z_KBFI_INPUT_FILE/IS_IFILE/FILE_NAME. The message is: Exception:[java.lang.NullPointerException] in class com.sap.xi.tf._KBFIMsgMapping_ method get_fname$[com.sap.aii.mappingtool.tf3.rt.Context@37d4662c] at com.sap.aii.mappingtool.tf3.AMappingProgram.processNode(AMappingProgram.java:284) at com.sap.aii.mappingtool.tf3.AMappingProgram.processNode(AMappingProgram.java:238)...."
    And in RWB in Communication Channel Monitoring I can not see file name in the payload.
    Maby I do something wrong, please tell me.

    my source file 200610.txt is like this:
    HR 0610 061030 061021
    DR 03 C 0610 820114 00010111 0000015000 PLN descr...
    DR 03 D 0610 403201 00010111 0000015000 PLN descr..
    TR 0000000002
    Then in sxmb_moni in inbound message (payload) I have:
    <?xml version="1.0" encoding="utf-8" ?>
    - <ns:KBFIMsgTypeSource xmlns:ns="http://p4.org/xi/KBFI/Interface">
    - <FIRecordset>
    - <HeaderLine>
      <LineKey>HR</LineKey>
      <PostingPeriod>0610</PostingPeriod>
      <PostingEndDate>061030</PostingEndDate>
      <PostingDate>061021</PostingDate>
      </HeaderLine>
    - <PostingLine>
      <LineKey>DR</LineKey>
      <ServerID>03</ServerID>
      <DCFlag>C</DCFlag>
      <PostingPeriod>0610</PostingPeriod>
      <GLAccount>820114</GLAccount>
      <SubAccount>00010111</SubAccount>
      <NetValue>0000015000</NetValue>
      <Currency>PLN</Currency>
      <Description>descr...</Description>
      </PostingLine>
    - <PostingLine>
      <LineKey>DR</LineKey>
      <ServerID>03</ServerID>
      <DCFlag>D</DCFlag>
      <PostingPeriod>0610</PostingPeriod>
      <GLAccount>403201</GLAccount>
      <SubAccount>00010111</SubAccount>
      <NetValue>0000015000</NetValue>
      <Currency>PLN</Currency>
      <Description>descr..</Description>
      </PostingLine>
      </FIRecordset>
      </ns:KBFIMsgTypeSource>
    But I don't have payload for Response (black and white flag).
    In DynamicConfiguration i have:
    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    - <!--  Response
      -->
    - <SAP:DynamicConfiguration xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="1">
      <SAP:Record namespace="http://sap.com/xi/XI/System/File" name="SourceFileSize">141</SAP:Record>
      <SAP:Record namespace="http://sap.com/xi/XI/System/File" name="FileType">txt</SAP:Record>
      <SAP:Record namespace="http://sap.com/xi/XI/System/File" name="SourceFileTimestamp">20061212T121622Z</SAP:Record>
      <SAP:Record namespace="http://sap.com/xi/XI/System/File" name="FileEncoding">ISO646-US</SAP:Record>
      <SAP:Record namespace="http://sap.com/xi/XI/System/File" name="FileName">200610.txt</SAP:Record>
      <SAP:Record namespace="http://sap.com/xi/XI/System/File" name="Directory">/usr/sap/PXD/put/archive</SAP:Record>
      </SAP:DynamicConfiguration>

  • Using User Defined Function in BO XI3.1 Universe

    Hi Everyone,
    Is it possible to call a database defined function in a universe?   I would like to create a universe object to call the function then make the object available to users as a dimension when creating reports.  If it's possible, can someone provide the details on how to crease such an object. 
    I'm using BO XI 3.1 and SQL Server 2005.
    Thanks.

    Hi Rudolph,
    What'd be the actual syntax of calling UDF in an object, as per the below info.
    Funtion Name: F1
    Table Name: T1
    Column Name: C1
    Database is SQL Server 2008.
    Appreciate your help.
    Thanks,
    Mahboob Mohammed

  • Problems with After Report trigger Updating using User-defined functions

    Hi,
    I have a report which uses SQL to select data that uses a user-defined stored function in the WHERE clause.
    I use the same SQL in the After Report trigger with and UPDATE statement to flag all records selected as being run.
    Data is being selected by the report no problem, but the records are not being updated. In a test, If I remove the conditions using the user functions, the records update as expected. In Live conditions I must have these conditions in the script.
    I originally tried putting the UPDATE in a formual column, but that would not fire on records where that page was not paged through (or paged to end) in the Runtime Previewer.
    Can anyone advise?

    In case anyone is interested.
    The issue was that the stored functions have roles assigned for security.
    PL/SQL for After Report doesn't seem to recognise the roles having been assigned for the report, so the implicit cursor update/select I had wouldn't work.
    I changed the SELECT into an explicit CURSOR and introduced a FOR LOOP, keeping the UPDATE as an implicit statement.
    I know see this was more of a PL/SQL issues than a report one, but such is life. So if anyone feels the urge to move it to the PL/SQL forum, then feel free!!
    Have a problem free afternoon. :-)

  • Using user defined function in where clause

    Hi,
    I have defined function to get maximum date before passed date on the table 'A' and I'm using the same function to get details on that date from the same table 'A' in where clause.
    for ex:
    SELECT x,y,z
    FROM A
    WHREE a.date = max_date;
    But on one database instance it is running fine and on other it is going in a infinite loop.
    Pls help me out
    Thanks in advance,
    Prashant

    Hello Siva,
    sorry, but I don't understand your reply:
    This is not right forum to posting this question.
    You are from which module or working any 3rd party application.
    MaxDB 7.7.07.16 is the community version of MaxDb,
    we are not using it for SAP
    and no 3rd party software is required to reproduce my problem,
    Sql Studio or Database Studio will do.
    Regards,
    Silke Arnswald

  • SQL Performance issue: Using user defined function with group by

    Hi Everyone,
    im new here and I really could need some help on a weird performance issue. I hope this is the right topic for SQL performance issues.
    Well ok, i create a function for converting a date from timezone GMT to a specified timzeone.
    CREATE OR REPLACE FUNCTION I3S_REP_1.fnc_user_rep_date_to_local (date_in IN date, tz_name_in IN VARCHAR2) RETURN date
    IS
    tz_name VARCHAR2(100);
    date_out date;
    BEGIN
    SELECT
    to_date(to_char(cast(from_tz(cast( date_in AS TIMESTAMP),'GMT')AT
    TIME ZONE (tz_name_in) AS DATE),'dd-mm-yyyy hh24:mi:ss'),'dd-mm-yyyy hh24:mi:ss')
    INTO date_out
    FROM dual;
    RETURN date_out;
    END fnc_user_rep_date_to_local;The following statement is just an example, the real statement is much more complex. So I select some date values from a table and aggregate a little.
    select
    stp_end_stamp,
    count(*) noi
    from step
    where
    stp_end_stamp
    BETWEEN
    to_date('23-05-2009 00:00:00','dd-mm-yyyy hh24:mi:ss')      
    AND
    to_date('23-07-2009 00:00:00','dd-mm-yyyy hh24:mi:ss')
    group by
    stp_end_stampThis statement selects ~70000 rows and needs ~ 70ms
    If i use the function it selects the same number of rows ;-) and takes ~ 4 sec ...
    select
    fnc_user_rep_date_to_local(stp_end_stamp,'Europe/Berlin'),
    count(*) noi
    from step
    where
    stp_end_stamp
    BETWEEN
    to_date('23-05-2009 00:00:00','dd-mm-yyyy hh24:mi:ss')      
    AND
    to_date('23-07-2009 00:00:00','dd-mm-yyyy hh24:mi:ss')
    group by
    fnc_user_rep_date_to_local(stp_end_stamp,'Europe/Berlin')I understand that the DB has to execute the function for each row.
    But if I execute the following statement, it takes only ~90ms ...
    select
    fnc_user_rep_date_to_gmt(stp_end_stamp,'Europe/Berlin','ny21654'),
    noi
    from
    select
    stp_end_stamp,
    count(*) noi
    from step
    where
    stp_end_stamp
    BETWEEN
    to_date('23-05-2009 00:00:00','dd-mm-yyyy hh24:mi:ss')      
    AND
    to_date('23-07-2009 00:00:00','dd-mm-yyyy hh24:mi:ss')
    group by
    stp_end_stamp
    )The execution plan for all three statements is EXACTLY the same!!!
    Usually i would say, that I use the third statement and the world is in order. BUT I'm working on a BI project with a tool called Business Objects and it generates SQL, so my hands are bound and I can't make this tool to generate the SQL as a subselect.
    My questions are:
    Why is the second statement sooo much slower than the third?
    and
    Howcan I force the optimizer to do whatever he is doing to make the third statement so fast?
    I would really appreciate some help on this really weird issue.
    Thanks in advance,
    Andi

    Hi,
    The execution plan for all three statements is EXACTLY the same!!!Not exactly. Plans are the same - true. They uses slightly different approach to call function. See:
    drop table t cascade constraints purge;
    create table t as select mod(rownum,10) id, cast('x' as char(500)) pad from dual connect by level <= 10000;
    exec dbms_stats.gather_table_stats(user, 't');
    create or replace function test_fnc(p_int number) return number is
    begin
        return trunc(p_int);
    end;
    explain plan for select id from t group by id;
    select * from table(dbms_xplan.display(null,null,'advanced'));
    explain plan for select test_fnc(id) from t group by test_fnc(id);
    select * from table(dbms_xplan.display(null,null,'advanced'));
    explain plan for select test_fnc(id) from (select id from t group by id);
    select * from table(dbms_xplan.display(null,null,'advanced'));Output:
    PLAN_TABLE_OUTPUT
    Plan hash value: 47235625
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |    10 |    30 |   162   (3)| 00:00:02 |
    |   1 |  HASH GROUP BY     |      |    10 |    30 |   162   (3)| 00:00:02 |
    |   2 |   TABLE ACCESS FULL| T    | 10000 | 30000 |   159   (1)| 00:00:02 |
    Query Block Name / Object Alias (identified by operation id):
       1 - SEL$1
       2 - SEL$1 / T@SEL$1
    Outline Data
      /*+
          BEGIN_OUTLINE_DATA
          FULL(@"SEL$1" "T"@"SEL$1")
          OUTLINE_LEAF(@"SEL$1")
          ALL_ROWS
          OPTIMIZER_FEATURES_ENABLE('10.2.0.4')
          IGNORE_OPTIM_EMBEDDED_HINTS
          END_OUTLINE_DATA
    Column Projection Information (identified by operation id):
       1 - (#keys=1) "ID"[NUMBER,22]
       2 - "ID"[NUMBER,22]
    34 rows selected.
    SQL>
    Explained.
    SQL>
    PLAN_TABLE_OUTPUT
    Plan hash value: 47235625
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |    10 |    30 |   162   (3)| 00:00:02 |
    |   1 |  HASH GROUP BY     |      |    10 |    30 |   162   (3)| 00:00:02 |
    |   2 |   TABLE ACCESS FULL| T    | 10000 | 30000 |   159   (1)| 00:00:02 |
    Query Block Name / Object Alias (identified by operation id):
       1 - SEL$1
       2 - SEL$1 / T@SEL$1
    Outline Data
      /*+
          BEGIN_OUTLINE_DATA
          FULL(@"SEL$1" "T"@"SEL$1")
          OUTLINE_LEAF(@"SEL$1")
          ALL_ROWS
          OPTIMIZER_FEATURES_ENABLE('10.2.0.4')
          IGNORE_OPTIM_EMBEDDED_HINTS
          END_OUTLINE_DATA
    Column Projection Information (identified by operation id):
       1 - (#keys=1) "TEST_FNC"("ID")[22]
       2 - "ID"[NUMBER,22]
    34 rows selected.
    SQL>
    Explained.
    SQL> select * from table(dbms_xplan.display(null,null,'advanced'));
    PLAN_TABLE_OUTPUT
    Plan hash value: 47235625
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |    10 |    30 |   162   (3)| 00:00:02 |
    |   1 |  HASH GROUP BY     |      |    10 |    30 |   162   (3)| 00:00:02 |
    |   2 |   TABLE ACCESS FULL| T    | 10000 | 30000 |   159   (1)| 00:00:02 |
    Query Block Name / Object Alias (identified by operation id):
       1 - SEL$F5BB74E1
       2 - SEL$F5BB74E1 / T@SEL$2
    Outline Data
      /*+
          BEGIN_OUTLINE_DATA
          FULL(@"SEL$F5BB74E1" "T"@"SEL$2")
          OUTLINE(@"SEL$2")
          OUTLINE(@"SEL$1")
          MERGE(@"SEL$2")
          OUTLINE_LEAF(@"SEL$F5BB74E1")
          ALL_ROWS
          OPTIMIZER_FEATURES_ENABLE('10.2.0.4')
          IGNORE_OPTIM_EMBEDDED_HINTS
          END_OUTLINE_DATA
    Column Projection Information (identified by operation id):
       1 - (#keys=1) "ID"[NUMBER,22]
       2 - "ID"[NUMBER,22]
    37 rows selected.

  • Strange errors when using user defined function in where clause

    Hello,
    I am having trouble with a function that, when used in the where clause of a select will cause an error if the first column selected is of type INTEGER. Not sure whether I am doing something wrong or whether this is a bug.
    Here is a very simple test case:
    create table test(
    col1 integer not null,
    col2 varchar(20) ascii default ''
    insert into test values(1,'2011-03-15 05:00:00')
    insert into test values(2,'2011-03-15 07:00:00')
    CREATE FUNCTION BTR_TAG  RETURNS VARCHAR AS
        VAR ret VARCHAR(20);
      SET ret='2011-03-15 06:00:00';
      RETURN ret;
    Select * from test where col2 >= BTR_TAG()
    Select col1,col2 from test where col2 >= BTR_TAG()
    =>  Error in assignment;-3016 POS(1) Invalid numeric constant
    Select '',* from test where col2 >= BTR_TAG()
    Select col2,col1 from test where col2 >= BTR_TAG()
    => works as it should
    MaxDB V 7.7.07.16 running on Windows Server 2003
    I can replicated the test case above with Sql Studio and other ODBC based tools.
    Thanks in advance,
    Silke Arnswald

    Hello Siva,
    sorry, but I don't understand your reply:
    This is not right forum to posting this question.
    You are from which module or working any 3rd party application.
    MaxDB 7.7.07.16 is the community version of MaxDb,
    we are not using it for SAP
    and no 3rd party software is required to reproduce my problem,
    Sql Studio or Database Studio will do.
    Regards,
    Silke Arnswald

  • How to use user defined function in select query using Toplink

    Hi Friends
    I am little bit of new in Toplink stuff... so please help me...
    I have to database functions 1. encrypt and 2. decrypt.
    I want to exceute the following sql query using toplink
    select port, database, user_name, decrypt(encrypt('String which is to be encrypt ','password'),'password') from CONFIGURATION
    can anyone tell me , how to write code in toplink which will give the about sql output.
    thanks .....

    The "Specifying a Custom SQL String in a DatabaseQuery" section in the TopLink Developer's Guide may help... http://download-uk.oracle.com/docs/cd/B32110_01/web.1013/b28218/qrybas.htm#BCFHDHBG

  • How to use User defined Function in Update statement

    Hi All,
    I have written below update statement to update column based on value return by function. but it is not working. Could any one help me on this. This function will return only one value for each project.
    thanks in advance.
    UPDATE dg2.OD_PROJ_LOOKUP_TEMP o
    SET Months_In_Stage_Cnt = select Months_In_Stage_Cnt_ret(o.project_id) from dual;
    thanks
    deb

    hi,
    CREATE FUNCTION fn_emp_ename (p_empno IN emp.empno%TYPE)
       RETURN VARCHAR2
    IS
       v_ename   emp.ename%TYPE;
    BEGIN
       SELECT ename
         INTO v_ename
         FROM emp
        WHERE empno = p_empno;
       RETURN v_ename;
    EXCEPTION
       WHEN NO_DATA_FOUND
       THEN
          RETURN NULL;
       WHEN OTHERS
       THEN
          RETURN NULL;
    END fn_emp_ename;
    SQL>
    SQL> select * from emp;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17-DEC-80        800                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
          7839 KING       PRESIDENT            17-NOV-81       5000                    10
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
          7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
    14 rows selected.
    SQL>  select fn_emp_ename (empno) as  emp_name from emp;
    EMP_NAME
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER
    14 rows selected.
    SQL> update emp
      2  set ename= fn_emp_ename (7936)
      3  where empno=7934;
    1 row updated.
    SQL> commit;
    Commit complete.
    SQL>  select * from emp where empno=7934;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTN
          7934            CLERK           7782 23-JAN-82       1300                    1
    SQL> i hope this helps .........
    Thanks,
    P Prakash
    Edited by: prakash on Nov 17, 2011 11:52 PM

Maybe you are looking for

  • Photo gallery will not show first folder

    Hello, My Photo Gallery will not show the first folder.  It is 'under' the albums header.  Anyone seen this, or know how to fix this? I have the most recent update (4.3.3)

  • Apex fop add ttf fonts

    Hello, Im solving problem with PDF printing in Apex 4.1.1 and fop 0.93 running on oc4j . There is problem with some characters displayed as "#" in output pdf. This usually means the selected font doesn't have a glyph for the character. I have studied

  • Problem with trackpad - clicking by touch

    Since upgraded to ML, trackpad clicks by touch every time I rest my fingers on it for more than 2 or 3 seconds. With Lion, I need to PRESS and physical click the trackpad. This is very very irritating since I need to move the fingers away from the tr

  • How do I close the aps that stay open on the "updates" page

    How do I close aps that stay open on my "updates" page

  • Multiple header pages

    I am creating a large report where the header section spans 2 pages. Currently, reports prints just the first page in the header section. How can I get the other page to print? I tried the vertical panels per page property, but that doesn't seem to w