Writing user defined function the same way as the oracle functions

Hi Guys,
In one of the interviews , I have attended the guy asked me to write a user defined function which will take the column name and list all the values .
For example
Table Name:Employees
Column Name: Employee_Name
Employee_name
Scott
Ivgun
Jack
Shane
The query should be in this fromat
SELECT col_agg(Employee_name) emp_name from Employees;
The output shoulld be
Emp_names
scott,ivgun,jack,shane
Please let me know if this is possible
Any suggestions will be highly appreciated.
Thanks,
Ranjan

You could certainly write a user defined aggregate function if you like...
e.g. this function will aggregate strings into a CLOB...
create or replace type clobagg_type as object
  text clob,
  static function ODCIAggregateInitialize(sctx in out clobagg_type) return number,
  member function ODCIAggregateIterate(self in out clobagg_type, value in clob) return number,
  member function ODCIAggregateTerminate(self in clobagg_type, returnvalue out clob, flags in number) return number,
  member function ODCIAggregateMerge(self in out clobagg_type, ctx2 in clobagg_type) return number
create or replace type body clobagg_type is
  static function ODCIAggregateInitialize(sctx in out clobagg_type) return number is
  begin
    sctx := clobagg_type(null) ;
    return ODCIConst.Success ;
  end;
  member function ODCIAggregateIterate(self in out clobagg_type, value in clob) return number is
  begin
    self.text := self.text || value ;
    return ODCIConst.Success;
  end;
  member function ODCIAggregateTerminate(self in clobagg_type, returnvalue out clob, flags in number) return number is
  begin
    returnValue := self.text;
    return ODCIConst.Success;
  end;
  member function ODCIAggregateMerge(self in out clobagg_type, ctx2 in clobagg_type) return number is
  begin
    self.text := self.text || ctx2.text;
    return ODCIConst.Success;
  end;
end;
create or replace function clobagg(input clob) return clob
  deterministic
  parallel_enable
  aggregate using clobagg_type;
SQL> select trim(',' from clobagg(ename||',')) as enames from emp;
ENAMES
SMITH,ALLEN,WARD,JONES,MARTIN,BLAKE,CLARK,SCOTT,KING,TURNER,ADAMS,JAMES,FORD,MILLER
SQL> ed
Wrote file afiedt.buf
  1  with t as
  2    (select 'PFL' c1, 0 c2,110 c3 from dual union all
  3     select 'LHL', 0 ,111 from dual union all
  4     select 'PHL', 1, 111 from dual union all
  5     select 'CHL', 2, 111 from dual union all
  6     select 'DHL', 0, 112 from dual union all
  7     select 'VHL', 1, 112 from dual union all
  8     select 'CPHL', 0, 114 from dual union all
  9     select 'WDCL', 1, 114 from dual union all
10     select 'AHL' ,2 ,114 from dual union all
11     select 'NFDL', 3, 114 from dual)
12  --
13  -- end of test data
14  --
15  select trim(clobagg(c1||' ')) as c1, c3
16  from (select * from t order by c3, c2)
17  group by c3
18* order by c3
SQL> /
C1                                     C3
PFL                                   110
LHL CHL PHL                           111
DHL VHL                               112
CPHL AHL NFDL WDCL                    114Ok, it's more than just a function as it uses an object type linking into the internals of the ODCI... but it does what you ask. :)

Similar Messages

  • User - defined functions for calculating the taxes of state and country

    hi expects,
        how can write user-defined function in message mapping in which i want to calculate the states taxes (2500) and country taxes (5000) and give the result as grand total in output.please help me?

    Hi,
    Activities
    1. To create a new user-defined function, in the data-flow editor, choose Create New Function (This
    graphic is explained in the accompanying text), which is located on the lower left-hand side of the
    screen. In the menu, choose Simple Function or Advanced Function.
    2. In the window that appears, specify the attributes of the new function:
    Name
    Technical name of the function. The name is displayed in the function chooser and on the data-flow
    object.
    Description
    Description of how the function is used.
    Cache
    Function type (see above)
    Argument Count
    In this table, you specify the number of input values the function can process, and name them. All
    functions are of type String.
    3. In the window that appears, you can create Java source code:
    a. You can import Java packages to your methods from the Imports input field, by specifying them
    separated by a comma or semi-colon:
    You do not need to import the packages java.lang., java.util., java.io., and java.lang.reflect. since
    all message mappings require these packages and therefore import them. You should be able to
    access standard JDK and J2EE packages of the SAP Web Application Server by simply specifying the
    package under Import. In other words, you do not have to import it as an archive into the Integration
    Repository. You can also access classes of the SAP XML Toolkit, the SAP Java Connector, and the
    SAP Logging Service (see also: Runtime Environment (Java-Mappings)).
    In addition to the standard packages, you can also specify Java packages that you have imported as
    archives and that are located in the same, or in an underlying software component version as the
    message mapping.
    b. Create your Java source text in the editor window or copy source text from another editor.
    4. Confirm with Save and Close.
    5. User-defined functions are limited to the message mapping in which you created the function. To
    save the new function, save the message mapping.
    6. To test the function, use the test environment.
    The new function is now visible in the User-Defined function category. When you select this category,
    a corresponding button is displayed in the function chooser pushbutton bar. To edit, delete, or add the
    function to the data-flow editor, choose the arrow next to the button and select from the list box
    displayed.
    Regards
    Seshagiri

  • Accessing container element in the User Defined Function

    Hi All,
    I am accessing a container element in the user defined function.
    But it is not working. Actually i want to split a message(1800 records) into a batch of 200.
    But it goes in a infinite loop.
    Please can you tell me where i am wrong.
    Smita
    The code is :
    public void SplitMsg(String[] a,ResultList result,Container container){
    Object container1;
    String counter;
    int i,j=0;
    container1 = container.getParameter("value");
    if( container1 == null){
    counter  =  "0";
    else {     
         counter = container.toString();
         j = Integer.valueOf(counter).intValue();
    for ( i = j ; i <= j + 199 ; i++){
         if ( i  >= a.length){
              container.setParameter("value","9999999");
              break;
         result.addValue(a<i>);
         j += 200;
         counter = Integer.toString(j);
         container.setParameter("value", counter);

    Here is another way to accomplish what you wanted.
    For the target mapping, use this sequence for mapping
    Source element -> removeContext -> Your User-defined Function -> Target Element
    When defining User-Defined Function, select "Cache Queue" option.
    Since you are using removeContext before calling the UserDefined function, your input to the user defined function will be a String array without ResultList.CC.
    Now manipulate the array the way you want it, and build the ResultList result.
    After every 200 records, use method
    void addContextChange().
    This will insert the ResultList.CC at the appropriate places.
    Use Display Queue in the Mapping Editor to see the debug values.

  • Converting the iif function in MS Access97 to an user defined function in Oracle

    Hi ,
    I have a problem here we are working with Visual Basic 6.0(ADOs 2.5) with Oracle 8i release 2. we have some queries stored in the tables which contains the iif function of MS Access 97 do we have a similar built in function in Oracle which replaces this iif function of Ms Access 97.
    we cannot use decode (built in function) of oracle b'cos it cannot be used in a where clause and we cannot write a user defined function also because it cannot be generalized for use b'cos sometimes we use
    field names and sometimes values as expression in the iif functions
    If anybody could suggest me some idea
    please mail me at [email protected]
    with best regards
    Jai

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Jai:
    Hi ,
    I have a problem here we are working with Visual Basic 6.0(ADOs 2.5) with
    Oracle 8i release 2. we have some queries stored in the tables which contains the iif function of MS Access 97 do we have a similar built in function in Oracle which replaces this iif function of Ms Access 97.we cannot use DECODE (built in function) of oracle b'cos it cannot be used in a where clause and we cannot write a user defined function also because it cannot be generalized for use b'cos sometimes we use field names and
    sometimes string values as expression in the iif functions. is there any other built in function ? can anybody suggest me some idea
    please mail me at [email protected]
    regards
    Jai<HR></BLOCKQUOTE>
    Hi,
    You still can use the seccond approach - with a udf IIF() that you place in a package and OVERLOAD it. See the documentation for limitations of Overloading
    Overloading permits you to declare several functions with the same name but havind different behaviours depending on the number and type of the parameters.
    George

  • 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

  • USER DEFINED FUNCTION in the formula editor

    How do you create a USER DEFINED FUNCTION in the formula editor using BADI

    <a href="http://help.sap.com/saphelp_nw04/helpdata/en/04/f3683c05ea4464e10000000a114084/frameset.htm">This</a> may help.

  • Need user define function for the message  mapping structure

    Hi All
    I am new to XI.I need the java code for Udf for the following structure.
    i have two input and one out put as error.
    order_nos----
    user define function-------error message
    order_details----
    num of orders---- i.e. 10
    order_details------ i.e. whole order records details
    1.i have to compare the 1st  input with 2nd one means if the ist input contain 10 means there are 10 orders in 2nd input.if not then i have to give error message .
    2.then i have to check the fields in 2nd input has no null values.if no values the output will be error message.
    Edited by: Rohit Kumar on Dec 18, 2008 4:43 PM

    Hi Sudhir
    thanks for your continues help.i need some help so that i can fulfill my requirmrnt
    this is my message mapping xml.
    <?xml version="1.0" encoding="UTF-8" ?>
    - <ns0:methodCall_MT xmlns:ns0="http://www.dfdsf">
      <num_orders>10</num_orders>
      <test_mode />
    - <order_x>                        ( which is order details)
      <order_id>t78tyu8t</order_id>
      <order_date />
      <mfg_id />
      <catalog_id />
      <first_name />
      <last_name />
      <recipient />
      <message />
      <address1 />
      <address2 />
      <address3 />
      <city />
      <state />
      <zip />
      <country />
      <country_code />
      <phone />
      <subtotal />
      <tax />
      <shipping />
      <total />
      <shopatron_total />
      <fulfiller_total />
      <shipment_id />
    - <additional_info>
      <in_store_pickup />
    - <express_shipping>
      <express_shipping_flag />
      <express_shipping_text />
      <express_shipping_arrival />
      </express_shipping>
      </additional_info>
    - <discount>
      <discount_description />
      <discount_percentage />
      <discount_total />
      </discount>
      <lang_id />
      <currency_id />
      <packing_list />
      <num_items />
    - <items>
      <item_id />
      <quantity />
      <price />
      <part_number />
      <fulfiller_total />
      <shopatron_total />
    - <options>
      <option_x />
      </options>
      </items>
      </order_x>
      </ns0:methodCall_MT>
    this my mapping where under one element number elements are there.when i am excuting the code to check the null value its always giving the there is null val but i have filled evrything.its due to first its checking the order_x and which will be always null.uder this all data will be filled.please suggest what to change in the udf.the code  given by u is working fine but its failing in this scenario because it getting the parent filed is null.

  • System ID in the user defined function

    Folks,
    I am trying to get the system id of the XI system with in the user defined function. How can I get it? I have looked into the technical context objects/contants and could not find any which gives you the XI system ID (3 character system ID).
    Any input is greatly appreciated.
    - Shanth

    Hi,
    Adding to the link whihc Michael has given...
    There is another system property which gives sap system name...rather than taking 'user.name' and parsing....
    Please the code below.....
    System.getProperty("SAPSYSTEMNAME");
    this returns the 3 letter system id.....i got XID !!!!
    Thanks,
    Renjith

  • Find the Database where user defined function is ??

    Hi,
      I have one user defined function , but i couldn't find where the function is and where the function is using.. anyone pls help me to overcome this one.
    Thanks

    Hi again,
    This is a combination of both previews response. I used
    Latheesh's script to execute, but since  sys.sql_expression_dependencie contains  information in the current database, therefore I used
    Praveen Rayan idea of using sp_MSforeachdb in order to check all databases (I used sp_MSforeachdb and not sp_foreachdb as I recomend to do usually).
    DECLARE @ObjectName NVARCHAR(100)
    SET @ObjectName = N'Ariely' --Give your function
    Declare @MyQuery NVARCHAR(MAX) = N'
    USE [?]
    SELECT DISTINCT
    SourceSchema = OBJECT_SCHEMA_NAME(sed.referencing_id)
    ,SourceObject = OBJECT_NAME(sed.referencing_id)
    ,ReferencedDB = ISNULL(sre.referenced_database_name, DB_NAME())
    ,ReferencedSchema = ISNULL(sre.referenced_schema_name,
    OBJECT_SCHEMA_NAME(sed.referencing_id))
    ,ReferencedObject = sre.referenced_entity_name
    FROM sys.sql_expression_dependencies sed
    CROSS APPLY sys.dm_sql_referenced_entities(OBJECT_SCHEMA_NAME(sed.referencing_id) + ''.'' + OBJECT_NAME(sed.referencing_id), ''OBJECT'') sre
    WHERE sed.referenced_entity_name like ''%' + @ObjectName + '%'' AND sre.referenced_entity_name like ''%' + @ObjectName + '%''
    PRINT @MyQuery
    EXEC sp_MSforeachdb @MyQuery
    I hope that ths give you what you need :-)
    [Personal Site]  [Blog]  [Facebook]

  • What is the purpose of User-Defined Functions under Excel Service Application?

    Hello, I have done a lot of research and have concluded that we cannot use VBA present under Excel sheet code in sharepoint.
    Today I was reading on excel services in sharepoint. I came across User-defined functions under Excel Service Application settings. I believe that User defined functions refer to the Calculations and VBA (am I wrong on this?).
    If true, then, does this bring hope that we can use embedded VBA code present into excel sheet in SharePoint also?

    Hi Nachiket,
    When you set  ‘Allow External Data’ to None, it disables all external data connections for the trusted file location.
    When you set  ‘Allow External Data’ to ‘Trusted data connection libraries and embedded’, it enables connections that are embedded in the workbook file or connections that are stored in a trusted data connection library.
    More information, please refer to the link:
    http://technet.microsoft.com/en-us/library/jj219699.aspx
    As your description, when you tried to set Allow External Data to None, the external data also was displayed, it may be caused by data cache or time delay.
    I hope this helps.
    Thanks,
    Wendy
    Wendy Li
    TechNet Community Support

  • Calling the function NUMBER_GET_NEXT from an XI User Defined Function

    Hi there,
    A number range object has been created on our XI server, called, ZBC_BKSTMT.
    I need to call the function NUMBER_GET_NEXT (standard SAP function for number range objects) with the parameters:
    NR_RANGE_NR = 01
    OBJECT = ZBC_BKSTMT
    Calling the NUMBER_GET_NEXT function will return a unique integer.  However, i need to call it from a User Defined Function because I need to make use of the returned integer in my message mapping.
    Thanks,

    Hello,
    If you have SP13, SAP provides a RFC API which can be called during the mapping. Refer to this document:
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/xi/xi-code-samples/xi%20mapping%20lookups%20rfc%20api.pdf
    Also check this weblog :
    /people/siva.maranani/blog/2005/08/23/lookup146s-in-xi-made-simpler
    For pre-SP13 systems, refer to this How-To
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/xi/xi-how-to-guides/how%20to%20perform%20sap%20data%20lookups%20within%20xi%20mappings
    ***************Reward points,if found useful

  • User defined function for getting last string in the line

    Hi Experts,
    I am not java expert, can anyone give me user defined function for getting last string in the line.
    for example if the source field is "NEW ARBOUR SQUARE"  i want to pass to target field only last string that is "SQUARE"
    please help me out of this.
    Kind Regards.
    Praveen.

    You don't even need a UDF for this. In the graphical editor look for the standard functions and once you do a scroll over on 'text functions; you will find what you are looking for.
    Just a piece of advice, try keeping UDF's to minimum unless really required or it is complicated without it.
    regards

  • User Defined Function (Part 2)

    Hi,
    István Korös has finally solved my problem on User Defined Function.
    See
    My objective was to write a simple UDF to represent the following formula which Gordon Du gave me:
    (DATEADD (s, -1, 
             DATEADD (mm, (DATEDIFF (m,0,@refdtzz ) + @mthnumber),  0)))
    However, the solution proposed by István, although it works perfectly, leaves me scratching my head. Let's see why?
    The only difference between my solution and that proposed by István is that István enclosed the UDF name between .
    I wonder how this can make the vital difference between a (simple query!) that works well and one that gets blocked.
    I tried several combinations of and am in for a few surprises, listed below. Can anybody explain what's going on?
    Solution proposed by István:
    CREATE FUNCTION [dbo].[udf_EndOfMonth]
    and executed as:
    select  [dbo].udf_EndOfMonth (@refdt1 , 1)
    Remarks: works perfectly
    If I execute the UDF with exaclly the same name as in CREATE, it does not work
    CREATE FUNCTION [dbo].[udf_EndOfMonth]
    and executed as:
    select  [dbo].[udf_EndOfMonth] (@refdt1 , 1)
    Error Msg: Must specify table to select from
    If I don't put the , the function is created, but the execution of the calling query returns error
    CREATE FUNCTION dbo.udf_EndOfMonth
    Remarks : Creation OK
    and executed as:
    select  dbo.udf_EndOfMonth (@refdt1 , 1)
    Error Msg: Must specify table to select from
    It seems that the only combination that works is that provided by István.
    This is surely a simple UDF.
    I don't know what to do if I attack a more complicated UDF.
    Grateful if anybody could help light my way.
    Thanks
    Leon Lai

    Hi Leon,
    As István has already pointed out, there is no documentation for those small differences to make the SQL work or not. He must be tested quite a few times to find the actual working code. This question can only be answered by the developer who made this part for B1.
    Thanks,
    Gordon

  • How to use pl/sql code as ODI user defined function

    Hi All,
    i have a pl/sql code and i want to create ODI user defined function using this code .
    please find the pl/sql code below:
    ============================
    declare
    v_no_of_duplicate_rec number := 0;
    begin
    select count(*)
    into v_no_of_duplicate_rec
    from ( select 1
    from temp_pre_selections
    group by svb_number, selection_id
    having count(*) > 1);
    if v_no_of_duplicate_rec = 0 then
    return 'N';
    else
    return 'Y';
    end if;
    end if;
    ==========================
    please help me how to achieve the same .
    Thanks
    Vinod

    2 ways:
    a. implement logic in odi function directly: getCount, Oracle implementation:
    select case count(1) when 0 then 'N' else 'Y' end
    from hr.employees
    when you use this function to refresh a variable, the refresh statement should only be getCount, you shoueld not write select getCount from dual, otherwise it will become
    select select .... from ... from dual
    b. if your logic is complex, I suggest to write function directly in your database, then call this function in your ODI function
    eg:
    CREATE OR REPLACE FUNCTION hr.test RETURN varchar2 IS
    tmpVar NUMBER;
    BEGIN
    select count(1) into tmpVar from hr.employees;
    if tmpVar=0 then
    return 'N';
    else
    return 'Y';
    end if;
    END test;
    then create a ODI function, Oracle implementation is
    hr.test
    in your variable refresh statement, you can write select getCount from dual
    if you use the odi function in other locations expect for refreshing variable, the idea is similar

  • User defined function in a cursor

      Hi All,
    I  need to use a user defined function(which returns a value based on my Procedure's input parameter) in my explicit cursor. Something like
    create or replace procedure test(pi_input number)
    cursor c1
    is
    select  col1,
               col2,
              func(pi_input),
              col4
    from table;
    begin
    end;
    Is this possible? I

    Hi,
    User-defined functions can appear in SQL statements, including cursors, if they follow certain rules (e.g., all arguments are IN arguments, in one of the SQL data types).
    You really need to post your code. You don't need to post the compete code; a simplified version that gets the same error would serve just as well (actually better).  Include CREATE TABLE and INSERT statements for any tables used, the function code, the code that calls the function, and the results you want from that code, given the sample data you posted.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002
    Does your function work the way you want when it is not in a cursor?

Maybe you are looking for