OracleDbType for function OBJECT return type

Hi all,
I inherited an oracle function that has an object as a return type:
create or replace TYPE OBJECTPATH IS OBJECT (OBJECTID NUMBER);
create or replace TYPE OBJECTPATH_TAB AS TABLE OF OBJECTPATH;
create or replace FUNCTION GETOBJECTINPATH ( pobjectid in NUMBER, role1 varchar2, role2 varchar2 ) RETURN OBJECTPATH_TAB
IS
v_tmp_tab OBJECTPATH_TAB:=OBJECTPATH_TAB();
parentid NUMBER;
rowno INTEGER;
BEGIN
rowno:=0;
parentid:=pobjectid;
loop
select objectid into parentid from dual left join (select ro2.objectid from relationshipobject ro1, relationshipobject ro2
where ro1.role=role1 and ro2.role=role2 and ro1.relationshipid=ro2.relationshipid and ro1.objectid=parentid)
on 1=1;
if parentid is null then
exit;
end if;
v_tmp_tab.extend;
rowno:=rowno1;+
v_tmp_tab(rowno) := OBJECTPATH(parentid);
end loop;
RETURN v_tmp_tab;
END;
On my application side, I am trying to run this function and retrieve the return value with ODP.NET as below. However, I am stumped when I need to supply an OracleDbType for the function return type.
1. What is the OracleDbType I should use for the return type? I read that there used to be support for OracleDbType.Object, but it seems like it is now not supported. I am using ODP.NET 11g. Am I getting the situation correct?
2. If retrieving an object return type is not as straightforward as setting the parameters (as what I have done below), what is the workaround to achieve it?
OracleCommand runGetPObjectInPathCmd = new OracleCommand("GETOBJECTINPATH", conn);
runGetPObjectInPathCmd.CommandType = CommandType.StoredProcedure;
runGetPObjectInPathCmd.Parameters.Add(new OracleParameter("pobjectid", OracleDbType.Decimal)).Value = pobjectId;
runGetPObjectInPathCmd.Parameters["pobjectid"].Direction = ParameterDirection.Input;
runGetPObjectInPathCmd.Parameters.Add(new OracleParameter("role1", OracleDbType.Varchar2, 255)).Value = role1;
runGetPObjectInPathCmd.Parameters["role1"].Direction = ParameterDirection.Input;
runGetPObjectInPathCmd.Parameters.Add(new OracleParameter("role2", OracleDbType.Varchar2, 255)).Value = role2;
runGetPObjectInPathCmd.Parameters["role2"].Direction = ParameterDirection.Input;
runGetPObjectInPathCmd.Parameters.Add("OBJECTPATH_TAB", OracleDbType.Decimal); // this is not correct as the return type is not a NUMBER
runGetPObjectInPathCmd.Parameters["OBJECTPATH_TAB"].Direction = ParameterDirection.ReturnValue;
runGetPObjectInPathCmd.ExecuteNonQuery();
Thanks in advance for any help and would greatly appreciate it.

Hi Greg,
Thanks for your reply. I am not exactly sure whether I am using 11.1.0.6.21. The Oracle.DataAccess.dll I see under my \ODP.NET\bin\2.x directory is of Assembly/Product Version 2.111.6.0 - is this version 11.1.0.6.21? I also do not have the samples directory. Am I working on a wrong version? Thanks for your patience as I am really new to this and appreciate your guidance.

Similar Messages

  • Function with return type boolean

    I have created a function with return type boolean as:
    CREATE OR REPLACE FUNCTION fn RETURN BOOLEAN
    AS
    exp EXCEPTION;
    BEGIN
    return TRUE;
    EXCEPTION
    when OTHERS then RAISE exp;
    END;
    FUNCTION fn compiledThen I was trying to call this function into dbms_output.put_line procedure, I got this error:
    EXECUTE DBMS_OUTPUT.PUT_LINE(fn);
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'Can someone please help me understand, why this happened?
    Is this because of boolean return type?

    952040 wrote:
    I have created a function with return type boolean as:
    Then I was trying to call this function into dbms_output.put_line procedure, I got this error:
    EXECUTE DBMS_OUTPUT.PUT_LINE(fn);
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'
    What is the parameter signature for DBMS_OUTPUT.put_line() ?
    Is is string - as detailed in Oracle® Database PL/SQL Packages and Types Reference guide.
    So how can you pass a boolean data type as parameter value, when the parameter's data type is string?
    PL/SQL supports implicit data conversion. So you can for example pass a number or date value to DBMS_OUTPUT.put_line() - and the PL/SQL engine automatically (and implicitly) converts that (using the TO_CHAR() functions) to a string.
    However, the TO_CHAR() parameter signature supports number and date - not boolean. It cannot convert a boolean value into a string.
    So passing a boolean value means the implicit conversion fails - and results in the above error.
    To make it work, you need to perform an explicit conversion. As as a data type conversion function from boolean to string is not available, you need to write a user defined function. E.g.
    SQL> create or replace function BoolToChar( b boolean ) return varchar2 is
      2  begin
      3    case
      4       when b then return( 'TRUE' );
      5       when not b then return( 'FALSE' );
      6    else
      7      return( null );
      8    end case;
      9  end;
    10  /
    Function created.
    SQL>
    SQL> exec DBMS_OUTPUT.put_line( 'Flag is '||BoolToChar(true) );
    Flag is TRUE
    PL/SQL procedure successfully completed

  • Copy activity fails while copying/reading sql object return type

    Hi,
    Please help me by providing some information for the following issue
    i am executing a db adapter in BPEL service ,i am calling a stored procedure it returns a object type . i can see the outputparameters retrun values in the audit(BPEL console) but i am unable to copy the object return type using assign copy operation.
    it shows parser error.Please find below mentioned error information.
    fault message:
    ULNAPP_JW_100_02_OutputVariable>
    -<part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="OutputParameters">
    -<db:OutputParameters xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:db="http://xmlns.oracle.com/pcbpel/adapter/db/DEVJ2EE/ULNAPP_JW_100_02/EDIT/">
    -<IV_EDI_REC_T>
    <EDI_EDIT>CNLNCE_APP_EDIT_00
    </EDI_EDIT>
    <EDI_SUPER_PRODUCT_TYPE_CD>CN
    </EDI_SUPER_PRODUCT_TYPE_CD>
    <EDI_PRODUCT_TYPE_CD>LN
    </EDI_PRODUCT_TYPE_CD>
    <EDI_FUNDING_TYPE_CD>CE
    </EDI_FUNDING_TYPE_CD>
    <EDI_PTC_COMPANY>ALL
    </EDI_PTC_COMPANY>
    <EDI_PCB_BRANCH>ALL
    </EDI_PCB_BRANCH>
    <EDI_STATE_CD>ALL
    </EDI_STATE_CD>
    <EDI_PRD_PRODUCT>ALL
    </EDI_PRD_PRODUCT>
    <EDI_EDIT_TYPE_CD>ORG-ENTRY
    </EDI_EDIT_TYPE_CD>
    <EDI_ENABLED_IND>Y
    </EDI_ENABLED_IND>
    <CREATED_BY>SETUP
    </CREATED_BY>
    <CREATION_DATE>2008-01-30T17:02:35.000+05:30
    </CREATION_DATE>
    <LAST_UPDATED_BY>SETUP
    </LAST_UPDATED_BY>
    <LAST_UPDATE_DATE>2008-01-30T17:02:35.000+05:30
    </LAST_UPDATE_DATE>
    <EDI_RESULT_CD>ERROR
    </EDI_RESULT_CD>
    <EDI_OVR_RESPONSIBILITY_CD>UNDEFINED
    </EDI_OVR_RESPONSIBILITY_CD>
    <EDI_ERE_ID>102688
    </EDI_ERE_ID>
    </IV_EDI_REC_T>
    <IV_RESULT>0
    </IV_RESULT>
    <IV_ERR_DESC xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
    </db:OutputParameters>
    </part>
    <part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="response-headers">[]
    </part>
    </ULNAPP_JW_100_02_OutputVariable>
    </messages>
    Assign_1
    [2008/04/10 20:01:50] Updated variable "TMP_Output"More...
    -<TMP_Output>
    -<part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="OutputParameters">
    -<OutputParameters xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/DEVJ2EE/ULNAPP_JW_100_02/EDIT/">
    -<IV_EDI_REC_T xmlns="">
    <EDI_EDIT>CNLNCE_APP_EDIT_00
    </EDI_EDIT>
    <EDI_SUPER_PRODUCT_TYPE_CD>CN
    </EDI_SUPER_PRODUCT_TYPE_CD>
    <EDI_PRODUCT_TYPE_CD>LN
    </EDI_PRODUCT_TYPE_CD>
    <EDI_FUNDING_TYPE_CD>CE
    </EDI_FUNDING_TYPE_CD>
    <EDI_PTC_COMPANY>ALL
    </EDI_PTC_COMPANY>
    <EDI_PCB_BRANCH>ALL
    </EDI_PCB_BRANCH>
    <EDI_STATE_CD>ALL
    </EDI_STATE_CD>
    <EDI_PRD_PRODUCT>ALL
    </EDI_PRD_PRODUCT>
    <EDI_EDIT_TYPE_CD>ORG-ENTRY
    </EDI_EDIT_TYPE_CD>
    <EDI_ENABLED_IND>Y
    </EDI_ENABLED_IND>
    <CREATED_BY>SETUP
    </CREATED_BY>
    <CREATION_DATE>2008-01-30T17:02:35.000+05:30
    </CREATION_DATE>
    <LAST_UPDATED_BY>SETUP
    </LAST_UPDATED_BY>
    <LAST_UPDATE_DATE>2008-01-30T17:02:35.000+05:30
    </LAST_UPDATE_DATE>
    <EDI_RESULT_CD>ERROR
    </EDI_RESULT_CD>
    <EDI_OVR_RESPONSIBILITY_CD>UNDEFINED
    </EDI_OVR_RESPONSIBILITY_CD>
    <EDI_ERE_ID>102688
    </EDI_ERE_ID>
    </IV_EDI_REC_T>
    <IV_RESULT xmlns="">0
    </IV_RESULT>
    <IV_ERR_DESC xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns=""/>
    </OutputParameters>
    </part>
    </TMP_Output>
    </sequence>
    </flow>
    <switch>
    Assign_Output (faulted)
    [2008/04/10 20:01:50] Error in evaluate <from> expression at line "399". The result is empty for the XPath expression : "/ns9:OutputParameters/ns9:IV_RESULT". More...
    oracle.xml.parser.v2.XMLElement@d2838
    [2008/04/10 20:01:50] "{http://schemas.xmlsoap.org/ws/2003/03/business-process/}selectionFailure" has been thrown.less
    -<selectionFailure xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
    -<part name="summary">
    <summary>
    empty variable/expression result.
    xpath variable/expression expression "/ns9:OutputParameters/ns9:IV_RESULT" is empty at line 399, when attempting reading/copying it.
    Please make sure the variable/expression result "/ns9:OutputParameters/ns9:IV_RESULT" is not empty.
    </summary>
    </part>
    </selectionFailure
    Thanks in advance,

    I'm having a similar problem where I'm unable to copy data from a single element from a response from a stored procedure (through an ESB service). If I copy the entire response xml to another variable it works fine however.
    Working code:
    <variable name="VariableOut" messageType="ns10:OutputParameters_reply"/>
    <assign name="assignStatusCode">
    <copy>
    <from variable="VariableOut" part="OutputParameters" query="/ns11:OutputParameters/ns11:EnclosureOutput/ns11:P_STATUS_CODE"/>
    <to variable="statusCodeFromEnclosures"/>
    </copy>
    </assign>
    results in:
    Updated variable "VariableOut"
    <invokeAPPS_DB_Enclosures_Out_execute_OutputVariable>
    <part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="OutputParameters">
    <OutputParameters xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/DOC_INT/DOC_INV_ENCLOSURE_PKG/SEND_ENCLOSURES/">
    <P_ENCLOSURES xsi:nil="true"/>
    <P_STATUS_CODE>1</P_STATUS_CODE>
    <P_STATUS_TEXT>My text</P_STATUS_TEXT>
    </OutputParameters>
    </part>
    </invokeAPPS_DB_Enclosures_Out_execute_OutputVariable>
    Not working code:
    <variable name="statusCodeFromEnclosures" type="xsd:unsignedInt"/>
    <assign name="assignStatusCode">
    <copy>
    <from variable="VariableOut" part="OutputParameters" query="/ns11:OutputParameters/ns11:EnclosureOutput/ns11:P_STATUS_CODE"/>
    <to variable="statusCodeFromEnclosures"/>
    </copy>
    </assign>
    results in:
    Error in evaluate <from> expression at line "195". The result is empty for the XPath expression : "/ns11:OutputParameters/ns11:EnclosureOutput/ns11:P_STATUS_CODE".
    oracle.xml.parser.v2.XMLElement@14d4901

  • Guideline for deciding method return type

    Hi All,
    I have some concerns in deciding the return type of some specific methods in the application (web service application to be specific).
    Concern: There are methods like 'deleteData', 'cancelProcess', 'uploadData' etc. Ideally these methods don't require server to perform complex business logic. Now there are 2 views to decide the return type of these methods. The first approach could be to return a boolean indicating whether the operation is successful or not and the other apporach is to return void but throw an exception if anything goes wrong.
    Both approaches have their own advantages and drawbacks. Sending a boolean seems to be cleaner but in case of unsuccess caller won't get the exact exception but just a flag. In second apporach, the caller has to rely on try/catch to decide the logical flow.
    I know, there can't be any generic answer to this question but I just wanted to know comments from experts on this or probably some guidelines.
    Thanks and Regards,
    Ashish Arya

    If there is a legitimate reason why your method might not actually do what it should, then use the boolean return value.
    Example: someList.remove("foo") will return false if "foo" is not actually in the list (because remove() simply specifies that it will make sure that the element is not in the list after the call. Since this is fulfilled in this case, there's no case to throw an exception, even if it didn't actually remove anything).
    If the only reason for not doing what it should is some error condition, then throw an exception:
    Example: someList.get(100) will throw an exception, when the list has less than 101 elements.

  • Convert Object return type columns

    Hi Team
    Hi,
    I have created a object type as
    create type emp_obj_dtl as OBJECT (ename varchar2(50),mgr NUMBER)
    create type emp_dtl_obj_typ as TABLE of emp_obj_dtl
    Using the these object i have created on function as
    CREATE OR REPLACE FUNCTION emp_test_func (peno NUMBER)
    RETURN emp_dtl_obj_typ
    AS
    lv_emp_dtl emp_dtl_obj_typ := emp_dtl_obj_typ ();
    BEGIN
    SELECT emp_dtl_obj_typ(emp_obj_dtl (ename, mgr))
    INTO lv_emp_dtl
    FROM emp
    WHERE empno = peno;
    RETURN lv_emp_dtl;
    END;
    Now if i am executig query as
    SELECT empno, emp_test_func (empno) emp_dtls
    FROM emp
    It is returning me the data as
    EMPNO | EMP_DTLS
    7500 | (DATASET)
    7382 | (DATASET)
    7569 | (DATASET)
    7800 | (DATASET)
    But I want the result set as
    EMPNO | ENAME | MGR
    7500 | SMITH | 7863
    7382 | JAMES | 7896
    7569 | KING | 7856
    7800 | SANGR | 7456
    Appricate your help to get the resultset as above.
    thank you & Rgrds
    VIKAS ARORA

    Don't really like the approach you've used in your sample code - in effect, that is caching SQL data using very expensive PL memory (called PGA). It is wrong for performance reasons. It is wrong for scalability reasons.
    It is returning me the data as
    EMPNO | EMP_DTLS
    7500 | (DATASET)Correct. As the dataset is not a scalar data type like varchar2, date or number, but a complex object type. And not just a object type, but a collection (table) object type.
    You need to decide how you want to treat that object data that the SQL projection returns.
    Here's a more comprehensive example:
    SQL> create or replace type TPerson as object (ename varchar2(50), empno number );
      2  /                                                                           
    Type created.
    SQL>           
    SQL> create or replace type TDirectReports as table of TPerson;
      2  /                                                        
    Type created.
    SQL>           
    SQL> create or replace function DirectReports( manager number ) return TDirectReports as
      2  -- returns list of employees that directly reports to manager                     
      3          list    TDirectReports;                                                   
      4  begin                                                                             
      5          select                                                                    
      6                  TPerson( InitCap(e.ename), e.empno ) bulk collect into list       
      7          from    emp e                                                             
      8          where   e.mgr = manager                                                   
      9          order by ename;                                                           
    10                                                                                    
    11          return( list );                                                           
    12  end;                                                                              
    13  /                                                                                 
    Function created.
    SQL>
    SQL> col ENAME format a10
    SQL> col DIRECT_REPORTS format a100
    SQL> select ename, DirectReports(empno) as "DIRECT_REPORTS" from emp;
    ENAME      DIRECT_REPORTS(ENAME, EMPNO)
    SMITH      TDIRECTREPORTS()                                                                                   
    ALLEN      TDIRECTREPORTS()                                                                                   
    WARD       TDIRECTREPORTS()                                                                                   
    JONES      TDIRECTREPORTS(TPERSON('Ford', 7902), TPERSON('Scott', 7788))                                      
    MARTIN     TDIRECTREPORTS()                                                                                   
    BLAKE      TDIRECTREPORTS(TPERSON('Allen', 7499), TPERSON('James', 7900), TPERSON('Martin', 7654), TPERSON('Tur
               ner', 7844), TPERSON('Ward', 7521))                                                                
    CLARK      TDIRECTREPORTS(TPERSON('Miller', 7934))
    SCOTT      TDIRECTREPORTS(TPERSON('Adams', 7876))
    KING       TDIRECTREPORTS(TPERSON('Blake', 7698), TPERSON('Clark', 7782), TPERSON('Jones', 7566))
    TURNER     TDIRECTREPORTS()                                                                     
    ADAMS      TDIRECTREPORTS()                                                                     
    JAMES      TDIRECTREPORTS()                                                                     
    FORD       TDIRECTREPORTS(TPERSON('Smith', 7369))                                               
    MILLER     TDIRECTREPORTS()
    14 rows selected.Note that the dataset is a collection object - that contains zero or more nested objects. In this case, a list of employees that directly reports to the current employee.
    How can we use this collection object? Here is a basic example:
    SQL> col 1ST_EMPLOYEE format a15
    SQL> with MANAGER_LIST as(
      2          select ename, DirectReports(empno) as "DIRECT_REPORTS" from emp
      3  )
      4  select
      5          l.ename,
      6          (select count(*) from TABLE(l.direct_reports)) as "NO_OF_EMPLOYEES",
      7          (select d.ename from TABLE(l.direct_reports) d where rownum = 1) as "1ST_EMPLOYEE",
      8          (select max(d.empno) from TABLE(l.direct_reports) d ) as "LAST_EMPLOYEE"
      9  from       manager_list l
    10  /
    ENAME      NO_OF_EMPLOYEES 1ST_EMPLOYEE    LAST_EMPLOYEE
    SMITH                    0
    ALLEN                    0
    WARD                     0
    JONES                    2 Ford                     7902
    MARTIN                   0
    BLAKE                    5 Allen                    7900
    CLARK                    1 Miller                   7934
    SCOTT                    1 Adams                    7876
    KING                     3 Blake                    7782
    TURNER                   0
    ADAMS                    0
    JAMES                    0
    FORD                     1 Smith                    7369
    MILLER                   0
    14 rows selected.Just note that this example merely illustrates how to use and reference objects in SQL. This is not the preferred way to address the problem it does - as the same could have been a lot easier achieved using a simple self-join.
    So make sure that when you use objects in SQL, it is for the right technical reasons.

  • Column Function Return Type Number is forcing to cast to Decimal

    Hi - I am using Oracle 11g Release 11.2.0.2.0 and ODP.NET 4.112.3.0.
    Whenever I am trying to execute a package query with column function and return type is number, it is throwing cast exception whenever I am trying to cast it as GetInt32.
    The workaround we have for now is to get it decimal and cast to Int32, this is going to be painful moving forward because it means that we have to check each of our packages and need to know if each package has column function and do this special casting.
    Is this a known bug?

    Oracle Number is 6.
    Run the below script to your machine and the sample code below so you can see what I am talking about.
    --drop table aninalfarm;
    --drop table birdfarm;
    --drop public synonym animalfarm;
    --drop public synonym birdfarm;
    --drop public synonym birdfarm_Pkg;
    --drop public synonym animalfarm_Pkg;
    create table animalfarm
            (code                                 NUMBER(6),
            description                        varchar2(10));
    create table birdfarm
           (code                               number(6),
           description                         varchar2(10));
    create public synonym  animalfarm for db.animalfarm;
    create public synonym  birdfarm for db.birdfarm;
    grant select, delete, insert, update on  animalfarm to public;
    grant select, delete, insert, update on  birdfarm to public;
    delete from animalfarm;
    delete from birdfarm;
    commit;
    insert into animalfarm (code, description) values(111122, 'Horse');
    insert into animalfarm (code, description) values(111133, 'Chicken');
    insert into animalfarm (code, description) values(111144, 'Cow');
    insert into animalfarm (code, description) values(111155, 'Pig');
    insert into animalfarm (code, description) values(111166, 'Sheep');
    insert into birdfarm (code, description) values(222, 'Pigeon');
    insert into birdfarm (code, description) values(333, 'Sparrow');
    insert into birdfarm (code, description) values(444, 'Chickadee');
    insert into birdfarm (code, description) values(555, 'Blue Jay');
    insert into birdfarm (code, description) values(666, 'Loon');
    commit;
    create or replace package birdfarm_Pkg is
    function get_key_from_desc(bird_name_in in birdfarm.description%type) return number;
    end birdfarm_Pkg;
    create or replace package body birdfarm_Pkg is
    function get_key_from_desc(bird_name_in in birdfarm.description%type) return number is
    RETURN_VALUE birdfarm.code%TYPE;
    BEGIN
           select code into RETURN_VALUE from birdfarm where description = bird_name_in;
           return RETURN_VALUE;
    end get_key_from_desc;
    END birdfarm_Pkg;
    create or replace package animalfarm_Pkg is
    --region Define Record Type for Strong Type REF CURSOR
    TYPE AnimalFarmRecord is
      RECORD(
                      code animalfarm.code%type,
          description animalfarm.description%type,
                      birdfarm_code birdfarm.code%type
    --endregion
    TYPE animalfarmCur is REF CURSOR RETURN AnimalFarmRecord;
    procedure get_code_two_ways(cur_OUT OUT animalfarmCur);
    end animalfarm_Pkg;
    create or replace package body animalfarm_Pkg is
    procedure get_code_two_ways(cur_OUT OUT animalfarmCur) is
    BEGIN
      open cur_OUT for
           select animalfarm.code,
                  animalfarm.description,
                  birdfarm_pkg.get_key_from_desc('Pigeon') birdfarm_code
           from animalfarm
           order by code;
    end get_code_two_ways;
    END animalfarm_Pkg;
    create public synonym birdfarm_Pkg for db.birdfarm_Pkg;
    grant execute on birdfarm_Pkg to public;
    create public synonym animalfarm_Pkg for db.animalfarm_Pkg;
    grant execute on animalfarm_Pkg to public;
    See the sample code below:
                 var conn = new OracleConnection(OraDB);
                conn.Open();
                conn.ClientId = "Sample";
                var command = new OracleCommand
                                      Connection = conn,
                                      CommandText = "DB.animalfarm_Pkg.get_code_two_ways",
                                      CommandType = CommandType.StoredProcedure
                command.Parameters.Add(new OracleParameter
                                       ParameterName = "cur_OUT",
                                       OracleDbType = OracleDbType.RefCursor,
                                       Direction = ParameterDirection.Output
                OracleDataReader dr = command.ExecuteReader(); // C#
                dr.Read();
                var code =dr.GetInt32(dr.GetOrdinal("Code")); //This is ok
                var description = dr.GetString(dr.GetOrdinal("Description"));
                var codeError = dr.GetInt32(dr.GetOrdinal("birdfarm_code"));//Throw invalid cast exception
                                                                            //because it is column function
                conn.Close();
                conn.Dispose();

  • Problem when calling a return type BOOLEAN SQL Function in a package

    Hi All,
    I am having problem when trying to call a SQL function in a package with return type BOOLEAN
    The SQL function signature is as follows
    CREATE OR REPLACE PACKAGE RMSOWNER.ORDER_ATTRIB_SQL ****
    FUNCTION GET_PO_TYPE_DESC(O_error_message IN OUT VARCHAR2,
    I_PO_TYPE       IN     VARCHAR2,
    O_PO_TYPE_DESC  IN OUT VARCHAR2)
    RETURN BOOLEAN;
    Following is my java code
    +CallableStatement cs3 = conn.prepareCall("{?=call ORDER_ATTRIB_SQL.GET_PO_TYPE_DESC(?,?,?)}");+
    +cs3.registerOutParameter(1, java.sql.Types.BOOLEAN);+
    +cs3.registerOutParameter(2, java.sql.Types.VARCHAR);+
    +cs3.registerOutParameter(4, java.sql.Types.VARCHAR);+
    +cs3.setString(2, "");+
    +cs3.setString(3, "ST");+
    +cs3.setString(4, "");+
    +ResultSet rs3 = cs3.executeQuery();+
    I get the following exception, i tried changing the sql type(registerOutParameter) from boolean to bit but i still getting this exception.
    But when i call any other functions with return type other than boolean they work perfectly fine.
    Please can anyone help me fix this issue, i am not sure if its anything to do with vendor JDBC classes?
    +java.sql.SQLException: ORA-06550: line 1, column 13:+
    +PLS-00382: expression is of wrong type+
    +ORA-06550: line 1, column 7:+
    +PL/SQL: Statement ignored+
    +     at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)+
    +     at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)+
    +     at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)+
    +     at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)+
    +     at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:215)+
    +     at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:954)+
    +     at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1168)+
    +     at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3316)+
    +     at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3422)+
    +     at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4394)+
    #####

    Hello People!
    There is another workaround!!
    See the example below:
    private String callBooleanAPi(String tableName,String apikey,String dtInicio,String dtFim,String comando) throws SQLException {
                   CallableStatement cs = null;
                   String call = "";
                   String retorno = null;
                   try {
                        if(comando.equalsIgnoreCase("INSERT")){
                             call = "declare x BOOLEAN; y varchar2(2);begin x :=PKG.INSERT(?,?,?,?,?); if x then y := 'S'; else y :='N'; end if; ? := y;end;";
                        } else if(comando.equalsIgnoreCase("UPDATE")){
                             call = "declare x BOOLEAN; y varchar2(2);begin x := PKG.UPDATE(?,?,?,?,?); if x then y := 'S'; else y :='N'; end if; ? := y;end;";
                        } else if(comando.equalsIgnoreCase("DELETE")){
                             call = "declare x BOOLEAN; y varchar2(2);begin x := PKG.DELETE(?,?,?,?,?); if x then y := 'S'; else y :='N'; end if; ? := y;end;";
                        cs = conn.prepareCall(call);
                        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
                        SimpleDateFormat sdfToSqlDate = new SimpleDateFormat("yyyy-MM-dd");
                        java.util.Date dataInicialVigencia =null;
                        java.util.Date dataFinalVigencia = null;
                        Date dtInicialFormatada =null;
                        Date dtFinalFormatada = null;
                        if(dtInicio != null && !dtInicio.equals("")){
                             dataInicialVigencia = sdf.parse(dtInicio);
                             dtInicio =sdfToSqlDate.format(dataInicialVigencia);
                             dtInicialFormatada = Date.valueOf(dtInicio);
                        if(dtFim != null && !dtFim.equals("")){
                             dataFinalVigencia = sdf.parse(dtFim);
                             dtFim =sdfToSqlDate.format(dataFinalVigencia);
                             dtFinalFormatada = Date.valueOf(dtFim);
                        cs.setString(1, tableName);
    cs.setString(2, apikey);
    cs.setDate(3, dtInicialFormatada );
    cs.setDate(4, dtFinalFormatada );
    cs.registerOutParameter(5, java.sql.Types.VARCHAR);
    cs.registerOutParameter(6, java.sql.Types.VARCHAR );
    cs.execute();
                        retorno = cs.getString(6);
                        System.out.println( cs.getString(5));
                   } catch(SQLException e){
                   throw new SQLException("An SQL error ocurred while calling the API COR_VIGENCIA: " + e);
                   } catch(Exception e){
                   Debug.logger.error( "Error calculating order: " + id, e );
                   } finally {
                   if (cs != null) {
                   cs.close();
                   cs = null;
                   return retorno;
    As you can see the CallableStatement class acepts PL/SQl blocks.
    Best Regards.

  • ODSI support for return type "PL/SQL TABLE"?

    Hello!
    We are trying to connect our ODSI to an Oracle function with return type "PL/SQL TABLE". The ODSI "wizard" (used to create the physical data service) seems to understand the interface during creation, but when executed it fails. The ODSI server complains about wrong type (PLS-00382: expression is of wrong type) when we execute it from the "test tab".
    The function's metadata is looks like this:
    <params xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xdt="http://www.w3.org/2004/07/xpath-datatypes" xmlns:pn1="ld:physical/rekondis/CALC_DEBITING" >
    <param name="RETURN_VALUE" kind="return" xqueryType="pn1:RETURN_VALUE_ROW" nativeTypeCode="1111" nativeType="PL/SQL TABLE"/>
    <param name="PIN_CASE_ID" kind="in" xqueryType="xs:decimal" nativeTypeCode="3" nativeType="NUMBER"/>
    <param name="PIN_ACTION_CODE" kind="in" xqueryType="xs:decimal" nativeTypeCode="3" nativeType="NUMBER"/>
    <param name="PI_AD_NAME" kind="in" xqueryType="xs:string" nativeTypeCode="12" nativeType="VARCHAR2"/>
    </params>
    Any ideas how we can make this work!? Or is this not even supported in ODSI 10.3?
    Thanks!
    // Mikael

    Please refer to the documentation - http://download.oracle.com/docs/cd/E13162_01/odsi/docs10gr3/datasrvc/Create%20Physical%20Data%20Services%20from%20Stored%20Procedures.html

  • EJB3 Creating Web Services with Complex Return Types

    Hi
    Not sure if this is the right place, but hoping someone can help!
    I have an entity bean that has a collection (list<Address>) of sub-entities. I have then created a session bean to retrieve the Business and populate it's children.
    I then expose this as a web service and although it works and I get appropriate XML out, the WSDL of the deployed service is not as I would like.
    For example:
    The return type is
    <complextype name="Business">
    <sequence>
    <element name="id" type="int"/>
    <element name="addresses" type="ns1:list"/>
    </sequence>
    </complextype>
    <complextype name="Address">
    <sequence>
    <element name="id" type="int"/>
    <element name="addresses1" type="string"/>
    <element name="addresses2" type="string"/>
    <element name="addresses3" type="string"/>
    </sequence>
    </complextype>
    ns1:list is included as a separate schema as a complex extension of the base "collection"
    So, even though the Address type is there it is not referenced from Business.
    So, when I'm calling the Web Service from BPEL or ESB, I have not got the ability to map adequately back from the response.
    I have tried a whole bunch of ways of getting this to work, but so far to no avail...
    Has anyone seen this before, or can I somehow override the mapping from the Entity to the WSDL?
    Any help would be most appreciated.
    Thanks
    Chris

    Thanks. We are using a Java Proxy to consume the web service as we need to use JAX-WS handlers. We created data control from the service stub that was created by the proxy. Our issue is with the response XML which comes as a complex type. Also, the data control is understanding the complex type and is creating the structure right. The problem is when we drag that control on a JSF page. No data is displayed. We think that we are not traversing the complex object properly which is creating the issue.
    I understand that you answer related to the input is applicable to output as well. We can change the structure by flattening it but we thought that in 11G there is some new features where we can use the complex types out of the box without any change. Is that true? Also, any luck in finding the documents (broken links) on your blog page?

  • Querying PL/SQL function which returns SYS_REFCURSOR

    Hello:
    I have a PL/SQL function with return type of SYS_REFCURSOR.
    In SQLPlus, I can query it either as
    var c refcursor
    exec :c := func(...)
    print c
    or
    select func(...) from dual;
    Running the latter in Eclipse 3.3 with oracle DTP extensions installed gives me OracleResultSetImpl object in the SQL Results view.
    Can the code be a little smarter and recognize that a sql query may return "indirect" resultset?
    Regards,
    Ernest

    This is noted; will be the interface better to handle the return values. Thanks

  • Return type for a PL?SQL function

    Hi,
    I am trying to register a PL/SQL function with discoverer which returns more than one numerical values. What return type should i use for this function....cant see an array or something like it from the Diccover end, when I try to register it.
    Please help.
    -S

    S.
    If you create a function, then you can pass in parameters but only return one value for the function.
    That return datatype cannot be an array, but just one value (ie: varchar, number, etc.).
    Russ

  • Problem building schema for return type as custom object

    Hi i am invoking a web service through a partner link. But when i expand the invoke variables( in structure tab ), it shows Exception- Problem building schema.
    Response is of type java:Customer which is a custom object having mobile_no, name, compname.
    Error is--
    Invalid reference: 'java:customobjectproject:Customer'
    wsdl file:
    <?xml version='1.0' encoding='UTF-8'?>
    <definitions name="CustomerDetailServiceDefinitions" targetNamespace="http://customobjectproject" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:s0="http://customobjectproject" xmlns:s1="http://schemas.xmlsoap.org/wsdl/soap/">
    <types>
    <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://customobjectproject" xmlns:s0="http://customobjectproject" xmlns:s1="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="getCustomer">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="mobileNo" type="xs:int"/>
    <xs:element name="name" type="xs:string"/>
    <xs:element name="compName" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    <xs:element name="getCustomerResponse">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="return" type="java:Customer" xmlns:java="java:customobjectproject"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>
    <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="java:customobjectproject" xmlns:s0="http://customobjectproject" xmlns:s1="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType name="Customer">
    <xs:sequence>
    <xs:element minOccurs="1" name="Mobile_no" nillable="false" type="xs:int"/>
    <xs:element minOccurs="1" name="Name" nillable="true" type="xs:string"/>
    <xs:element minOccurs="1" name="CompName" nillable="true" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    </xs:schema>
    </types>
    <message name="getCustomer">
    <part element="s0:getCustomer" name="parameters"/>
    </message>
    <message name="getCustomerResponse">
    <part element="s0:getCustomerResponse" name="parameters"/>
    </message>
    <portType name="CustomerDetail">
    <operation name="getCustomer" parameterOrder="parameters">
    <input message="s0:getCustomer"/>
    <output message="s0:getCustomerResponse"/>
    </operation>
    </portType>
    <binding name="CustomerDetailServiceSoapBinding" type="s0:CustomerDetail">
    <s1:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="getCustomer">
    <s1:operation soapAction="" style="document"/>
    <input>
    <s1:body parts="parameters" use="literal"/>
    </input>
    <output>
    <s1:body parts="parameters" use="literal"/>
    </output>
    </operation>
    </binding>
    <service name="CustomerDetailService">
    <port binding="s0:CustomerDetailServiceSoapBinding" name="CustomerDetailSoapPort">
    <s1:address location="http://localhost:7030/CustomerDetail/CustomerDetail"/>
    </port>
    </service>
    </definitions>
    I am using jdeveloper 10.1.3.3.0. Please help..
    Thanks.

    Well, the problem is caused by the fact that BPEL does not yet support soapenc:Array types. We've created a workaround by defining two Services, one that has only single returntypes and one that has the multiple returntypes (which are defined using soapenc:Array). There are other solutions, but those are very complicated. Hope this helps!

  • PLS-00630: pipelined functions must have a supported collection return type

    Hello, I created an TYPE of OBJECT and a PLSQL Function as shown below, but the function compilation errors with following. Not sure where is the issue?
    PLS-00630: pipelined functions must have a supported collection return typeThis is on Oracle 10g r2
    CREATE OR REPLACE TYPE cxs_plsql_profiler_object_type AS OBJECT (
       cxs_object_name      VARCHAR2 (128),
       cxs_object_type      VARCHAR2 (19),
       cxs_object_status    VARCHAR2 (7),
       cxs_read_execution   NUMBER,
       cxs_buffer_gets      NUMBER,
       cxs_disk_reads       NUMBER,
       cxs_executions       NUMBER,
       cxs_sorts            NUMBER,
       cxs_sharable_mem     NUMBER,
       cxs_address          NUMBER,
       cxs_hashvalue        NUMBER,
       cxs_osuser           VARCHAR2 (30),
       cxs_username         VARCHAR2 (30),
       cxs_module           VARCHAR2 (48),
       cxs_machine          VARCHAR2 (64),
       cxs_status           VARCHAR2 (8),
       cxs_terminal         VARCHAR2 (16),
       cxs_percentconsume   NUMBER,
       cxs_percentrepeat    NUMBER,
       cxs_plan             VARCHAR2 (120),
       target_name          VARCHAR2 (200),
       referenced_name      VARCHAR2 (200),
       referenced_type      VARCHAR2 (200),
       targetowner          VARCHAR2 (200),
       refowner             VARCHAR2 (200)
    )and here is the API
        FUNCTION CXS_GENERATE_PLSQL_PROFILER
    RETURN cxs_plsql_profiler_object_type
    PIPELINED IS
    out_rec cxs_plsql_profiler_object_type ;
    plsbatch plsql_batch;
    skount integer;
    dpendrec depend_tab;
    dkount integer;
    CURSOR objects
          IS
             SELECT object_name, object_type
               FROM dba_objects
              WHERE status = 'VALID'
                AND owner NOT IN ('SYS', 'SYSTEM')
                AND object_type IN ('PACKAGE', 'PROCEDURE', 'FUNCTION');
          CURSOR apis (p_object dba_objects.object_name%TYPE)
          IS
             SELECT DISTINCT *
                        FROM (SELECT   SUBSTR (a.sql_text, 1, 50) sql_text,
                                       TRUNC
                                          (  a.disk_reads
                                           / DECODE (a.executions,
                                                     0, 1,
                                                     a.executions
                                          ) reads_per_execution,
                                       a.buffer_gets, a.disk_reads, a.executions,
                                       a.sorts, a.sharable_mem, a.address,
                                       a.hash_value, b.osuser, b.username,
                                       b.module, b.machine, b.status, b.terminal,
                                       ROUND
                                          (cxs_db_info.kompute_percentofsql
                                                                   (a.sharable_mem),
                                           5
                                          ) percentkonsume,
                                       cxs_db_info.kount_repeat
                                                             (b.osuser,
                                                              b.terminal
                                                             ) percentr,
                                       c.operation explainplan
                                  FROM v$sqlarea a, v$session b, v$sql_plan c
                                 WHERE b.sql_hash_value = a.hash_value
                                   AND b.sql_address = a.address
                                   AND a.hash_value = c.hash_value
                                   AND a.address = c.address
                                   AND b.status = 'ACTIVE'
                                   AND UPPER (a.sql_text) LIKE
                                                            '%' || p_object || '%'
                                   AND c.ID = 0
                              ORDER BY 2 DESC)
                       WHERE ROWNUM <= 50;   --profile option
    BEGIN
    skount := 0;
    dkount := 0;
    FOR i IN objects
          LOOP
             FOR j IN apis (i.object_name)
             LOOP
                skount := skount + 1;
                plsbatch(skount).cxs_object_name  := i.object_name;
       plsbatch(skount).cxs_object_type      :=  i.object_type;
       plsbatch(skount).cxs_object_status    :=  i.object_status;
       plsbatch(skount).cxs_read_execution   := j.reads_per_execution;
       plsbatch(skount).cxs_buffer_gets      := j.buffer_gets;
       plsbatch(skount).cxs_disk_reads       := j.disk_reads;
       plsbatch(skount).cxs_executions       := j.executions;
       plsbatch(skount).cxs_sorts            := j.sorts;
       plsbatch(skount).cxs_sharable_mem     := j.sharable_mem;
       plsbatch(skount).cxs_address          := j.address;
       plsbatch(skount).cxs_hashvalue        := j.hashvalue;
       plsbatch(skount).cxs_osuser           := j.osuser;
       plsbatch(skount).cxs_username         := j.username;
       plsbatch(skount).cxs_module           := j.module;
       plsbatch(skount).cxs_machine          := j.machine;
       plsbatch(skount).cxs_status           := j.status;
       plsbatch(skount).cxs_terminal         := j.terminal;
       plsbatch(skount).cxs_percentconsume   := j.percentconsume;
       plsbatch(skount).cxs_percentrepeat    := j.percentrepeat;
       plsbatch(skount).cxs_plan             := j.explainplan;
             END LOOP;
             FOR dd IN dpend (i.object_name)
             LOOP
                dkount := dkount + 1;
                dependrec (dkount).target_name := dd.NAME;
                dependrec (dkount).refname := dd.referenced_name;
                dependrec (dkount).reftype := dd.referenced_type;
                dependrec (dkount).target_owner := dd.owner;
                dependrec (dkount).refowner := dd.referenced_owner;
             END LOOP;
          END LOOP;
    for a in 1..skount loop
       out_rec.cxs_object_type      := plsbatch(a).object_type;
       out_rec.cxs_object_status    := plsbatch(a).object_status;
       out_rec.cxs_read_execution   := plsbatch(a).reads_per_execution;
       out_rec.cxs_buffer_gets      := plsbatch(a).buffer_gets;
       out_rec.cxs_disk_reads       := plsbatch(a).disk_reads;
       out_rec.cxs_executions       := plsbatch(a).executions;
       out_rec.cxs_sorts            := plsbatch(a).sorts;
       out_rec.cxs_sharable_mem     := plsbatch(a).sharable_mem;
       out_rec.cxs_address          := plsbatch(a).address;
       out_rec.cxs_hashvalue        := plsbatch(a).hashvalue;
       out_rec.cxs_osuser           := plsbatch(a).osuser;
       out_rec.cxs_username         := plsbatch(a).username;
       out_rec.cxs_module           := plsbatch(a).module;
       out_rec.cxs_machine          := plsbatch(a).machine;
       out_rec.cxs_status           := plsbatch(a).status;
       out_rec.cxs_terminal         := plsbatch(a).terminal;
       out_rec.cxs_percentconsume   := plsbatch(a).percentconsume;
       out_rec.cxs_percentrepeat    := plsbatch(a).percentrepeat;
       out_rec.cxs_plan             := plsbatch(a).explainplan;
       PIPE ROW(out_rec);
    end loop;
    for b in 1..dkount loop
        out_rec.target_name := dd.NAME;
                out_rec.refname := dependrec (b).referenced_name;
                out_rec.reftype := dependrec (b).referenced_type;
                out_rec.target_owner := dependrec (b).owner;
                out_rec.refowner := dependrec (b).referenced_owner;
                PIPE ROW(out_rec);
    end loop;
    RETURN;
    EXCEPTION
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE(DBMS_UTILITY.format_error_backtrace);
    DBMS_OUTPUT.PUT_LINE(SQLCODE);
    DBMS_OUTPUT.PUT_LINE(SQLERRM);
    END; and below are tradtional table types that are used in code above.
    TYPE type_plsql_rec IS RECORD (
       cxs_object_name      VARCHAR2 (128),
       cxs_object_type      VARCHAR2 (19),
       cxs_object_status    VARCHAR2 (7),
       cxs_read_execution   NUMBER,
       cxs_buffer_gets      NUMBER,
       cxs_disk_reads       NUMBER,
       cxs_executions       NUMBER,
       cxs_sorts            NUMBER,
       cxs_sharable_mem     NUMBER,
       cxs_address          NUMBER,
       cxs_hashvalue        NUMBER,
       cxs_osuser           VARCHAR2 (30),
       cxs_username         VARCHAR2 (30),
       cxs_module           VARCHAR2 (48),
       cxs_machine          VARCHAR2 (64),
       cxs_status           VARCHAR2 (8),
       cxs_terminal         VARCHAR2 (16),
       cxs_percentconsume   NUMBER,
       cxs_percentrepeat    NUMBER,
       cxs_plan             VARCHAR2 (120)
       TYPE plsql_batch IS TABLE OF type_plsql_rec
          INDEX BY BINARY_INTEGER;
           TYPE type_depend_tab IS RECORD (
          target_name    dba_dependencies.NAME%TYPE,
          refname        dba_dependencies.referenced_name%TYPE,
          reftype        dba_dependencies.referenced_type%TYPE,
          target_owner   dba_dependencies.owner%TYPE,
          refowner       dba_dependencies.referenced_owner%TYPE
       TYPE depend_tab IS TABLE OF type_depend_tab
          INDEX BY BINARY_INTEGER;
    Thank you for your time in reading this post
    R

    Thank you Billy and Saubhik,
    I have followed your guidelines and was able to resolve this error. Now, after successfully compiling the code, I attempted to execute it in a following way.
    SELECT * FROM TABLE (cxs_generate_plsql_profiler);It gives following error: ORA-00904: "CXS_GENERATE_PLSQL_PROFILER": invalid identifier
    I also tried putting in quotes like below
    SELECT * FROM TABLE ('cxs_generate_plsql_profiler');Then, it gives following error:
    ORA-22905: cannot access rows from a non-nested table item
    Any Idea where I am doing wrong?
    Thanks,
    R

  • How to execute a function returning type in oracle

    hi
    i want to execute a function which is returning table from oracle prompt.
    i have created type in order to return table from function.
    /*creating type
    CREATE OR REPLACE TYPE U_VOC.t_in_list_tab AS OBJECT (i_group NUMBER ,
                                  i_company number,
                                  i_estab number
    NOT FINAL ;
    CREATE OR REPLACE TYPE U_VOC.t_in_list_tab_type
    AS TABLE OF U_VOC.t_in_list_tab;
    /*function */
    CREATE OR REPLACE FUNCTION FU_VOC_S_VEHICLES(pi_group number,
                                                      pi_company number,
                                                 pi_estab number
         RETURN t_in_list_tab
    AS
    v_nb_idvehicle           U_REF.V_REF_VEHICLES.NB_IDVEHICLE%type ;
    v_vc_reference           U_REF.V_REF_VEHICLES.VC_REFERENCE%type ;
    v_vc_licenceplate      U_REF.V_REF_VEHICLES.VC_LICENCEPLATE%type ;
    l_tab t_in_list_tab := t_in_list_tab( pi_group ,pi_company, pi_estab );
    BEGIN
              SELECT      V_REF_VEHICLES.NB_IDVEHICLE,
                   V_REF_VEHICLES.VC_REFERENCE,
                   V_REF_VEHICLES.VC_LICENCEPLATE
              INTO      V_NB_IDVEHICLE,
                   V_VC_REFERENCE,
                   V_VC_LICENCEPLATE
              FROM      U_REF.V_REF_VEHICLES
              WHERE      V_REF_VEHICLES.NB_IDGROUP = pi_group
              AND      V_REF_VEHICLES.NB_IDCOMPANY = pi_company
              AND      V_REF_VEHICLES.NB_ESTABL = pi_estab;
    RETURN l_tab;
    END;
    please help
    Thank in advance
    Sandy

    Sandy,
    I have a series of examples on this issue in my demo application. See this one:
    http://htmldb.oracle.com/pls/otn/f?p=31517:146
    You will basicaly need to write it like this:
    CREATE OR REPLACE TYPE u_voc.t_in_list_tab AS OBJECT (
       i_group     NUMBER,
       i_company   NUMBER,
       i_estab     NUMBER
    CREATE OR REPLACE TYPE u_voc.t_in_list_tab_type AS TABLE OF u_voc.t_in_list_tab;
    CREATE OR REPLACE FUNCTION fu_voc_s_vehicles (
       pi_group     NUMBER,
       pi_company   NUMBER,
       pi_estab     NUMBER
       RETURN t_in_list_tab PIPELINED
    AS
       l_tab   t_in_list_tab := t_in_list_tab (NULL, NULL, NULL);
    BEGIN
       FOR c IN (SELECT v_ref_vehicles.nb_idvehicle, v_ref_vehicles.vc_reference,
                        v_ref_vehicles.vc_licenceplate
                   FROM u_ref.v_ref_vehicles
                  WHERE v_ref_vehicles.nb_idgroup = pi_group
                    AND v_ref_vehicles.nb_idcompany = pi_company
                    AND v_ref_vehicles.nb_establ = pi_estab)
       LOOP
          l_tab.i_group := c.nb_idvehicle;
          l_tab.i_company_number := c.vc_reference;
          l_tab.estab_number := vc_licenceplate;
       END LOOP;
       RETURN l_tab;
    END;
    SELECT *
      FROM TABLE (fu_voc_s_vehicles (value1, value2, value3))But looking at your code, your function will return only one record.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/apex/f?p=107:7
    http://htmldb.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • Function not returning table object correctly

    Instead of returning a table, my function is returning this:
    SCHEMA_OWNER.TBL_SUMS([SCHEMA_OWNER.SUMS_OBJ])
    Does anyone see a syntax error in my function or the ddl of my table and object types?
    This is a stripped down, simplified version of my function:
    create or replace FUNCTION "F_TEST" (p_skey number, p_start_date date, p_end_date date)
    RETURN tbl_sums
    IS
    tmp_A NUMBER;
    tmp_B NUMBER;
    l_tbl tbl_sums := tbl_sums();
    BEGIN
    SELECT SUM(FieldA), SUM(FieldB)
    into tmpA, tmpB
    from myTable where SKEY = p_skey
    and DATE_VALUE >= p_start_date
    and DATE_VALUE < p_end_date;
    l_tbl.extend;
    l_tbl(l_tbl.count()) := sums_obj(p_start_date, p_end_date, p_skey, tmpA, tmpB);
    return l_tbl;
    END;
    My types are:
    create or replace type sums_obj is object (start_date DATE, end_date DATE, skey NUMBER, SumA NUMBER, SumB NUMBER);
    create or replace type tbl_sums is table of sums_obj;
    Thanks!

    >
    RETURN tbl_kpi
    >
    What is 'tbl_kpi'? That isn't defined anywhere. Your original post said this:
    >
    RETURN tbl_sums
    >
    We can't help you if you don't post what you are really using. Cut & Paste is ok but you have to paste the correct code.
    Your funtion is returning a TABLE but it is NOT PIPELINED. So if you query the function from DUAL you will get a DATASET as the result.
    If you query the function AS A TABLE you will get the 'contents' of the table.
    If you make your function a PIPELINED function then you use PIPE ROW to return each row but the function is still declared to return a TABLE. Maybe that is what is confusing you.
    Try the following sample code to see what the difference is.
    Here are two SQL types based on the EMP table in the scott schema.
    -- type to match emp record
    create or replace type emp_scalar_type as object
      (EMPNO NUMBER(4) ,
       ENAME VARCHAR2(10),
       JOB VARCHAR2(9),
       MGR NUMBER(4),
       HIREDATE DATE,
       SAL NUMBER(7, 2),
       COMM NUMBER(7, 2),
       DEPTNO NUMBER(2)
    -- table of emp records
    create or replace type emp_table_type as table of emp_scalar_type
    /Now - here is a function (similar to yours) that returns that EMP_TABLE_TYPE. NOTE: the function IS NOT PIPELINED
    CREATE OR REPLACE function SCOTT.get_emp1( p_deptno in number )
      return emp_table_type
      as
    tb emp_table_type;
    BEGIN
      select emp_scalar_type(empno, ename, job, mgr, hiredate, sal, comm, deptno)
        bulk collect into tb from emp where deptno = p_deptno;
      return tb;
    end;
    /If I just select the function itself from DUAL I get this:
    select get_emp1(20) from dual
    GET_EMP1(20)
    (DATASET)I can use TOAD or sql developer to examine that dataset and see the records.
    But I can actually query the records by using the TABLE function:
    select * from table(get_emp1(20))
    EMPNO     ENAME     JOB     MGR     HIREDATE     SAL     COMM     DEPTNO
    7369     SMITH     CLERK     7902     12/17/1980     800          20
    7566     JONES     MANAGER     7839     4/2/1981     2975          20
    7788     SCOTT     ANALYST     7566     4/19/1987     3000          20
    7876     ADAMS     CLERK     7788     5/23/1987     1100          20
    7902     FORD     ANALYST     7566     12/3/1981     3000          20This is a similar function. It returns the same EMP_TABLE_TYPE but it is a PIPELINED function.
    -- pipelined function
    create or replace function get_emp( p_deptno in number )
      return emp_table_type
      PIPELINED
      as
       TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;
        emp_cv EmpCurTyp;
        l_rec  emp%rowtype;
      begin
        open emp_cv for select * from emp where deptno = p_deptno;
        loop
          fetch emp_cv into l_rec;
          exit when (emp_cv%notfound);
          pipe row( emp_scalar_type( l_rec.empno, LOWER(l_rec.ename),
              l_rec.job, l_rec.mgr, l_rec.hiredate, l_rec.sal, l_rec.comm, l_rec.deptno ) );
        end loop;
        return;
      end;
      /The ONLY way I can query this function is by using the TABLE function:
    select * from table(get_emp(20))
    EMPNO     ENAME     JOB     MGR     HIREDATE     SAL     COMM     DEPTNO
    7369     smith     CLERK     7902     12/17/1980     800          20
    7566     jones     MANAGER     7839     4/2/1981     2975          20
    7788     scott     ANALYST     7566     4/19/1987     3000          20
    7876     adams     CLERK     7788     5/23/1987     1100          20
    7902     ford     ANALYST     7566     12/3/1981     3000          20The query of the PIPELINED function is the same and the result set is the same.
    The difference is that the PIPELINED function returns ONE ROW at a time and does NOT need to accumulate a lot of data in a collection before returning it. That collection uses expensive PGA memory and the more data you have the more memory it uses.
    Your function (and my similar one) doesn't return ANY data until it has produced ALL of it. And it uses that expensive PGA memory. What is the point of creating your collection one row at a time and waiting until you have it all before you return it?
    You could easily modify your function and add PIPELINED to the declaration. Then use the PIPE ROW clause to return each row as it is produced. That will eliminate the need for the collection (and memory) within the function.
    You can also then chain the function calls together if you need to.
    See 'Using Pipelined and Parallel Table Functions' in the Data Cartridge Developer's Guide
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28425/pipe_paral_tbl.htm
    There is little use for your function that is not pipelined but returns a table type unless you were storing that table-type in an object column of a table.
    There are many uses for PIPELINED functions.

Maybe you are looking for

  • Mini displayPort to VGA wont detect DELL E228WFP

    i bought a brand new mini display to VGA adapter for my late 2008 macbook pro 2.53 connecting to dell e228wfp wont do a thing. just wont work, also not on a sharp prjector. i tried booting with the lid closed and i get the grey startup screen on my d

  • Why must I upgrade my os, just to install iTunes 10.7 when if I used a pc I could do it on windows xp!

    I have no idea what to do. Macs should be easy. I have never had any problems using iPods or iPhones on a pc without a super setup. I am using my dads old MacBook pro 2.33 ghz and I would like to use this for my new iPhone 5. I used a Sony vaio lapto

  • Xperia z1 problem

    Hi I bought Sony xperia z1 before more than one and its working correctly and after update phone to android 4.3 in the second day after updating suddenly shut down and I pressed on/off bottom it was booting until android page and shutting down and I

  • Multiple Checkbox Insert Handling

    Every so often, I need to refresh my knowledge regarding how to handle multiple check box selections, and how they get handled on an action page to insert correctly in a DB. In a helpdesk application, the admin assigns projects to technicians. He may

  • Countdown Help - further

    Ok, i want my code to countdown to a specific time within my date. What do i have to add to enable it to do this? Thanks