In Ref cursor, user defined functions give "invalid column" error in EJB.

Hello,
I have written PL/SQL stored procedures/functions in Oracle 8i. They return the result set as a ref cursor.
These procedures are accessed by EJB (weblogic) using Type 4 (100% Java) JDBC Driver.
My problem is - if I use a user defined function to fetch a value in the select statement of the reference cursor, the EJB gives an error msg - invalid column name.
If instead of using the function I get the value directly from the table, it works fine. Refer the code below :
//In the PL/SQL function -
//instead of writing :
Open rc for
Select empcode, empname
from emp ;
//If I write :
Open rc for
Select empcode, mypack.getempname(empcode)
from emp ;
//getempname(empcode) is a function in
//in a package named 'mypack'
//and returns name for empcode.
//The java code gives error
//error : invalid column name
//While both are working fine and
//returning currect result in SQL Navigator.
Help me solve this mystery ?
Thanks in advance.
Swati.
null

Hi:
When use inline Function to simplify the SQL statements, there is one thing that one should conside--Purity Level.
if you create standalone stored pl/sql function. Oracle implicitly determines the PURITY level during compilation of the stored objects or at execution of an anonymous pl/sql block.
if you implement Package inline Function( in your case),unlike standalone stored pl/sql functions, the PL?SQL Engine does not determine the purity level of package functions. Therefore, you must explicity assign the correct purity levels for the function to be called inline.
the code like:
create or replace package mypack is
function getempname(empcode emp%empid%type)
return varchar2;
PRAGMA RESTRICT_REFERENCES(getempname,WNDS,WNPS,RNPS);
end mypack;
I think it can solve your problem if you use enough "pure"to be called inline function. Or you can create the standalone function to do it.
good luck!
Yali
<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Swati Agrawal ([email protected]):
Hello,
I have written PL/SQL stored procedures/functions in Oracle 8i. They return the result set as a ref cursor.
These procedures are accessed by EJB (weblogic) using Type 4 (100% Java) JDBC Driver.
My problem is - if I use a user defined function to fetch a value in the select statement of the reference cursor, the EJB gives an error msg - invalid column name.
If instead of using the function I get the value directly from the table, it works fine. Refer the code below :
//In the PL/SQL function -
//instead of writing :
Open rc for
Select empcode, empname
from emp ;
//If I write :
Open rc for
Select empcode, mypack.getempname(empcode)
from emp ;
//getempname(empcode) is a function in
//in a package named 'mypack'
//and returns name for empcode.
//The java code gives error
//error : invalid column name
//While both are working fine and
//returning currect result in SQL Navigator.
Help me solve this mystery ?
Thanks in advance.
Swati.
<HR></BLOCKQUOTE>
null

Similar Messages

  • 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?

  • User defined function in where IN clause

    Hi,
    I have a Function who returns in priview:
    (1,2,3,4)
    Now i am using this function in SQL where clause
    Select from debug where id in debug.debug_process()
    On execute select i am getiing ORA-01722 invalid number , i understand that functions return not only numbers but  character symbols too '(,)'
    Are it posible to use user defined function who do not return NUMBER in Where clause IN statement ?  If not what tips can sugest me for getting list of values for use in IN Clause?
    ID.
    Thanks!

    Hi,
    Please try:
    You can use SYS REFCURSOR for return your data.
    create or replace function get_debug return sys_refcursor is
         v_rc sys_refcursor;
       begin
         open v_rc for 'select * from debug where id in '|| debug.debug_process();
         return v_rc;
       end;
    Function created.
    Now, if we look at using this through SQL*Plus we first create ourselves a ref cursor variable to accept the results of the function, and then call the function to get the ref cursor back..
    SQL> var rc refcursor
    SQL> exec :rc := get_debug ;
    SQL> print rc;
    Regards
    Mahir M. Quluzade

  • User-defined function in package

    Hi all,
    is it possible to return more than 1 value when using user-defined function in package?

    I'll try to describe my situation. My need is to find correct client type by its cid number. If it's individual (ct.officialtype = 3) then function returns 3. If it's not individual (ct.officialtype <> 3) then function should check ENTERPRISETYPE.id, 910 is small business (function should return 1), else it returns 2. You can find my try below, it returns
    ORA-24344: success with compilation error
    13/29   PLS-00201: identifier 'US1' must be declared
    13/34   PL/SQL: ORA-00904: : invalid identifier
    13/1    PL/SQL: SQL Statement ignored
    17/4    PLS-00201: identifier 'US1' must be declared
    17/1    PL/SQL: Statement ignored
    9/13    PLS-00323: subprogram or cursor 'F_CLIENTTYPE' is declared in a package specification and must be defined in the package bodyCould you please give me solution on how do I write this procedure? It should be procedure, because I need to use it in SELECT statement.
    CREATE OR REPLACE PACKAGE creator.marco_function_clienttype
      IS
      -- 0 - not found
      -- 1 - small business
      -- 2 - corporate
      -- 3 - individual
       FUNCTION f_clienttype
         (cid number
         RETURN NUMBER;
    END;
    CREATE OR REPLACE PACKAGE BODY creator.marco_function_clienttype
    IS
    FUNCTION f_clienttype
         (ccid number)
         RETURN NUMBER
    IS
        Us NUMBER;
    Begin
    --officialtype = 2 - corporate, officialtype = 3 - individual
    select ct.officialtype into Us1
    from contragenttype ct, contragent d
    where d.id = ccid and ct.cid = d.contragenttypeid;
    IF Us1 = 3 THEN
    select '3' as t into Us from dual;
    ELSE
    --ENTERPRISETYPE.id = 910 - small business
    select dd.enterprisetypeid into Us2
    from contragent dd
    where dd.id = ccid ; 
    IF Us2 = 910 THEN
    select '1' as t into Us from dual;
    ELSE
    select '2' as t into Us from dual;
    END IF;
    END IF;
    Return nvl(Us,0);
    END;
    END;
    /

  • 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

  • How to create user defined functions in xi.

    how to create user defined functions in xi.
    can anyone give info with screen shots.

    Hi,
    Please follow the  steps mentioned in below link
    http://help.sap.com/saphelp_nw04/helpdata/en/f8/2857cbc374da48993c8eb7d3c8c87a/frameset.htm
    also refer below links to know more about UDF
    udf
    Thanks
    Swarup
    Edited by: Swarup Sawant on Mar 3, 2008 3:59 PM

  • User define function explanation.

    Hi ,
    Can any one explain what these user define function will do , since this is mapped in message mapping.
    I am writing the code which is written in it.I dont understand what it means and how it will give result.
    Please explain..
    1:
    public void ValidateQualifiers(String[] a,String[] b,String[] c,ResultList result,Container container){
    for ( int i=0;i<a.length;i++)
    if (a<i>.equals(c[0])){
         result.addValue(b[ i] );
    2: User-Defined function..
    public String getCounter(String a,Container container){
    GlobalContainer gc = container.getGlobalContainer();
    if (gc.getParameter(a) != null) {
                 return String.valueOf(gc.getParameter(a));
    } else {
    return "1";
    Edited by: mayank verdia on Jun 10, 2009 3:52 PM

    Hi,
    First func makes some actions which are semantically hardly described just by code. Provide with xml sample and use case.
    Regarding 2nd func: basically it gets from memory value that is named as a value of first parameter. try to find another func like "setCounter" and post its code here. for more info refer http://help.sap.com/saphelp_nw70/helpdata/en/75/8e0f8f3b0c2e4ea5f8d8f9faa9461a/frameset.htm - GlobalContainer Object.
    Regards,
    Dmitriy.

  • 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

  • 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.

  • User Defined Function VS join - Performance....

    Hi All,
    while linking the mulitple table and getting the values ....which one is the best ?
    Joining or User defined function.....
    single row function
    select a.name , get_salary(empid) from emp a;
    Note : get_salary function will return the salary from salary tables.
    Using joins
    select a.name ,b.salary from emp a, salary b
    where a.empid=b.empid;
    which is the performancewise best ?
    also if you give any related document also fine.
    Thanks in advance.
    Edited by: BASKAR NATARAJAN on Jan 6, 2011 10:09 PM

    Don't use such functions for joins. The function itself has to query the salary table. It will run the query against the salary table separately for each row that it reads from the emp table. You will end up with multiple recursive calls and possibly inconsistency in the output. (Imagine what would happen if the salary table were updated and commited while this query was running -- some rows would have been read with the pre-update values and others with the updated values).
    Specifying the join in the query ensures that a single SQL call is executed and provides read consistency across all the rows it reads. And it is much faster, being one single parse and execute.
    Hemant K Chitale
    http://hemantoracledba.blogspot.com

  • User Defined Function is not recognizing java class in IR.

    Hi All,
    i have written one normal java class, and i imported that java class into IR using imported Archive as a .jar file,
    it will add just two values .
    now in message mapping i created one user defined function in that
    iam trying to call this java class. while testing it is showing error as cannot resolve symbol java class name
    so experts please help me in this or it would be appreciate if any one will provide
    step by step process of one java class and one USD just to add two numbers.
    thanks in advance,
    jasmine .

    Hi,
    The steps are as follows:
    1) Create a java file with .java extension.
    2)Compile it to create a .class file.
    3) Create a zip file for this .class file using any compressed archive program(ex-winrar)
    4) Upload this zip file as an imported archive ,save and activate.
    When you go to this archive,below , you can see your .class file with the older path,for below ex:
    ObjRecord.class     jxl/biff/drawing/
    you have to give following entry in imports section:
    jxl.biff.drawing.ObjRecord;
    Please try this and let us know if this works.
    Thanks.
    Regards,
    Shweta

  • 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

  • User-defined function in message mappings

    Hi experts,
    I'm a senior c++ programmer, but I never write program by abap/java.
    I want to create a user-defined function for mapping. Who can give me some instruction?
    Many thanks.

    SDN can. A simple search on SDN could provide you the steps and code as well. Try a search and come up with more specific doubts. I am sure most of the doubts would be gone.
    Regards,
    Prateek

  • Help in Mapping: User defined function

    Hi All, I need your help in doing the following mapping:
    The source contains the below fields:
    Source_MT -- Under this          1...1
       LineItem                                 1...Unbounded
         CompanyCode          1..1
         Amount               1..1
       SubTotal                               1...Unbounded
         CompanyCode          1...1
         Amount               1...1
    And the Target strunture should be:
    Target_MT -- Under this
       Target                               1...unbounded
         CompanyCode          1...1
         AmountMatched          1...1
    There will be multiple line items in the source for each compony code which I need to loop through and add the amounts. For a company code, The sum of the amounts in the line items should match with the amount in the Subtotal/Amount.
    For each company code, a target should be created with the result whther the amounts were matched or not.
    Below is the data example:
    Source:
    Line Item :
         CompanyCode          Amount
         ABC               5
         ABC               5
         XYZ               10
         ABC               7     
         XYZ               6
    Sub Total :
         CompanyCode          Amount
         ABC               17
         XYZ               5
    Target should be:
    CompanyCOde          Amount
    ABC               Matched
    XYZ               Not Matched
    Hope I am clear with my requirement. Please let me know if you need more clarity.
    I was able to create mapping, if the line items contains single company code. Need help with multiple company codes.
    Any help would be appreciated.
    Edited by: GP on Jan 29, 2008 5:55 PM
    Edited by: GP on Jan 29, 2008 5:57 PM

    I am still working on the same map (please refer above) for which you gave th3e solution. The solution almost worked.
    I need to validate the line items with the subtotals. If the validation fails, I should throw an custom exception. If the validation is successful, then do nothing (do not create the target element).
    Hope I am clear. Please let me know if I am not clear.
    LineItem1: 10
    LineItem2: 20
    SubTotal1: 30
    LineItem3: 5
    LineItem4: 5
    SubTotal2: 15
    In the above example, eventhough LineItem1 and LineItem2 sum up to Subtotal1,  LineItem3 and LineItem4 doesn't sum up to SubTotal2. So it should throw an exception because second validation failed.
    Also, it should not create target element because first validation was successful.
    I used the logic int he below link :
    [http://www.flickr.com/photo_zoom.gne?id=2229287904&size=o]
    In the "else" part of "If else" statement, I have a user defined function which throws exception.
    If the output is "true", I am avoiding creating the target element using "Createif" statement.
    But strangely, when the vaildation of first set fails (LineItem1, LineItem2 and Subtotal1), then it is throwing the exception.
    But when the validation of second set fails, then it is not throwing the exception.
    My current map looks like below:
    [http://www.flickr.com/photos/23389577@N02/2234471441/sizes/l/]
    Edited by: GP on Feb 1, 2008 6:46 PM
    Edited by: GP on Feb 1, 2008 6:50 PM
    Edited by: GP on Feb 1, 2008 7:01 PM

  • User-defined function(java)

    hi expects,
    how to write user defined finction in javain meesage mapping.please help me.

    Hi Rohit,
    In order to create UDFs, you need to have a basic idea about using Core Java. Also, based on the kind of functonality of the code, you will need to know if you require any extra jar files.
    To create a UDF, all you need to do is click on LHS icon in the graphical mapping editor. Also, keep in min that the input and otput of a udf is always in strings.
    To test your functions, you can either use the test tab present in the mapping editor or you can even use the following editor(blog by Sravya):-
    /people/sravya.talanki2/blog/2006/07/24/integrating-java-editor-in-xi-integration-stack
    I think info will be enough for you to start off with creating and using UDFs:)
    This link for User Defined Functions,
    http://help.sap.com/saphelp_nw04/helpdata/en/d9/718e40496f6f1de10000000a1550b0/content.htm
    Writing use defrined functions in XI is quite simple. Create a simple UDF, give the import parameters and then just go ahead with the logic coding and then return the output from the UDF.
    Just remember that all inputs and outputs to an UDF are always Strings.
    Cheers...
    Vasu
    <b>** REward Points if found useful **</b>

Maybe you are looking for