How to call a function having OBJECT type as Return type

Hi,
I've the following function returning OBJECT type.
Pease advice me how to call this function
CREATE OR REPLACE TYPE GET_EMP_OBJ is object
   ( emp_name varchar2(50) ,
     mgr_id   number,
     dept_id  number
CREATE OR REPLACE FUNCTION get_emp(P_emp_no NUMBER )
  RETURN GET_EMP_OBJ  IS
  t_emp_info GET_EMP_OBJ ;
  v_ename  EMP.ename%TYPE;
  v_mgr    EMP.mgr%TYPE ;
  v_deptno EMP.deptno%TYPE;
  v_ename1  EMP.ename%TYPE;
  v_mgr1    EMP.mgr%TYPE ;
  v_deptno1 EMP.deptno%TYPE;
BEGIN
  FOR rec IN ( SELECT ename , mgr , deptno
                 FROM emp )
  LOOP
     v_ename := rec.ename ;
     v_ename1 := v_ename1||'|'||v_ename ;
     v_mgr   := rec.mgr   ;
     v_mgr1  := v_mgr1||'|'||v_mgr ;
     v_deptno:= rec.deptno;
     v_deptno1 := v_deptno1||'|'||v_deptno ;
  END LOOP ;
  t_emp_info  := GET_EMP_OBJ (v_ename,v_mgr,v_deptno ) ;
  RETURN t_emp_info ;
EXCEPTION WHEN OTHERS THEN
  DBMS_OUTPUT.put_line ('Error'||SQLCODE||','||SQLERRM ) ;
END;The above function got created successfully.
And i'm confused how to call this functions. I tried like below but didn't work
DECLARE
  t_emp_info_1  GET_EMP_OBJ ;
BEGIN
   t_emp_info_1 := get_emp(7566) ;
   for i in 1..t_emp_info_1.COUNT
      LOOP
         DBMS_OUTPUT.put_line ('Values are'||i.emp_name ) ;
     END LOOP;
END;  

SQL> CREATE OR REPLACE TYPE GET_EMP_OBJ is object
  2     ( emp_name varchar2(50) ,
  3       mgr_id   number,
  4       dept_id  number
  5     );
  6  /
Type created.
SQL> ed
Wrote file afiedt.buf
  1  CREATE OR REPLACE FUNCTION get_emp(empno NUMBER )
  2    RETURN GET_EMP_OBJ  IS
  3    t_emp_info GET_EMP_OBJ ;
  4  BEGIN
  5    begin
  6      select get_emp_obj(ename, mgr, deptno) into t_emp_info
  7      from emp
  8      where empno = get_emp.empno;
  9    exception
10      when no_data_found then
11        t_emp_info := new get_emp_obj(null,null,null);
12    end;
13    return t_emp_info;
14* END;
SQL> /
Function created.
SQL> set serverout on
SQL>
SQL> declare
  2    t_emp_info  GET_EMP_OBJ ;
  3  BEGIN
  4     t_emp_info := get_emp(7566);
  5     DBMS_OUTPUT.put_line ('Values are: '||t_emp_info.emp_name||', '||t_emp_info.mgr_id||', '||t_emp_info.dept_id);
  6  END;
  7  /
Values are: JONES, 7839, 20
PL/SQL procedure successfully completed.
SQL>

Similar Messages

  • How to call oracle function from ejb3

    i'm trying to call an oracle query-function from ejb3.
    The oracle function:
    create or replace FUNCTION getSecThreadCount(secId in NUMBER,avai in NUMBER)
    RETURN SYS_REFCURSOR is cur SYS_REFCURSOR;
    m_sql VARCHAR2(250);
    BEGIN
    m_sql:='select count(thrId) from thread where secId='|| secid||'
    and thrAvai='|| avai;
    open cur for m_sql;
    return cur;
    END;
    I'v tried several ways to call it,but all failed:
    1. the calling code:
    public Object getSectionThreadCount(int secId,int avai){
              Query query=manager.createNativeQuery("{call getSecThreadCount(?,?) }");     
              query.setParameter(1, secId);
              query.setParameter(2, avai);
              return query.getSingleResult();
    but i got the exception:
    Exception in thread "main" javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query; nested exception is: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
    javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
    Caused by: java.sql.SQLException: ORA-06550: row 1, col 7:
    PLS-00221: 'GETSECTHREADCOUNT' not procedure or not defined
    ORA-06550: row 1, col 7:
    PL/SQL: Statement ignored
    2. the calling code:
    @SqlResultSetMapping(name = "getSecThreadCount_Mapping")
    @NamedNativeQuery(name = "getSecThreadCount",
    query = "{?=call getSecThreadCount(:secId,:avai)}",
    resultSetMapping = "getSecThreadCount_Mapping",
    hints = {@QueryHint(name = "org.hibernate.callable", value = "true"),
              @QueryHint(name = "org.hibernate.readOnly", value = "true")})
    public Object getSectionThreadCount(int secId,int avai){
              Query query=manager.createNamedQuery("getSecThreadCount");     
              query.setParameter("secId", secId);
              query.setParameter("avai", avai);
              return query.getSingleResult();
    but i run into the exception:
    Exception in thread "main" javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query; nested exception is: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
    javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
    Caused by: java.sql.SQLException: lost in index IN or OUT parameter:: 3
    By the way, i have successfully called the function from hibernate. And i use oracle 11g, JBoss5 RC1.
    Could anyone tell me how to call the function from EJB3?
    Thanks.

    Here's a working model:
    package.procedure: (created in example schema scott)
    CREATE OR REPLACE package  body data_pkg as
      type c_refcursor is ref cursor;
      -- function that return all emps of a certain dept
      function getEmployees ( p_deptId in number
      return c_refcursor
      is
        l_refcursor c_refcursor;
      begin
         open l_refcursor
        for
              select e.empno as emp_id
              ,        e.ename as emp_name
              ,        e.job   as emp_job
              ,        e.hiredate as emp_hiredate
              from   emp e
              where  e.DEPTNO = p_deptId;
        return l_refcursor;
      end getEmployees;
    end data_pkg;
    /entity class:
    package net.app.entity;
    import java.io.Serializable;
    import java.util.Date;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.NamedNativeQuery;
    import javax.persistence.QueryHint;
    import javax.persistence.SequenceGenerator;
    import javax.persistence.Table;
    @SuppressWarnings("serial")
    @Entity
    @Table (name="emp")
    @SequenceGenerator(name = "EmployeeSequence", sequenceName = "emp_seq")
    @NamedNativeQuery( name = "getEmpsByDeptId"
                   , query = "{ ? = call data_pkg.getEmployees(?)}"
                   , resultClass = Employee.class
                   , hints = { @QueryHint(name = "org.hibernate.callable", value = "true")
                          , @QueryHint(name = "org.hibernate.readOnly", value = "true")
    public class Employee implements Serializable
        @Id
        @Column(name="emp_id")
        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "EmployeeSequence")
        private int id;
        @Column(name="emp_name")
        private String name;
        @Column(name="emp_job")
        private String job;
        @Column(name="emp_hiredate")
        private Date hiredate;
        // constructor
        public Employee (){}
        // getters and setters
        public int getId()
         return id;
    etc...session bean:
    package net.app.entity;
    import java.util.ArrayList;
    import java.util.List;
    import javax.ejb.Stateless;
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    import javax.persistence.Query;
    import net.app.entity.Employee;
    import net.app.iface.ScottAdmin;
    @Stateless
    public class ScottAdminImpl implements ScottAdmin
        @PersistenceContext
        private EntityManager entityManager;
        @SuppressWarnings("unchecked")
        public List<Employee> getEmployeesByDeptId(int deptId)
         ArrayList<Employee> empList;
         try
             Query query = entityManager.createNamedQuery("getEmpsByDeptId");
             query.setParameter(1, deptId);
             empList = (ArrayList<Employee>) query.getResultList();
             return empList;
         catch (Exception e)
             e.printStackTrace(System.out);
             return null;
    }client:
    package net.app.client;
    import java.util.List;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import net.app.entity.Employee;
    import net.app.iface.ScottAdmin;
    public class ScottClient
        public static void main(String[] args)
         try
             // create local interface
             InitialContext ctx = new InitialContext();
             ScottAdmin adminInterface = (ScottAdmin) ctx.lookup("ScottAdminImpl/remote");
             // select employees by deptno
             int deptno = 20;
             List<Employee> empList = adminInterface.getEmployeesByDeptId(deptno);
             // output
             System.out.println("Listing employees:");
             for (Employee emp : empList)
              System.out.println(emp.getId() + ": " + emp.getName() + ", " + emp.getJob() + ", " + emp.getHiredate());
         catch (NamingException e)
             e.printStackTrace(System.out);
    }Basically you just ignore the refcursor outbound parameter.
    This is a stored function, have yet to try outbound refcursor parameters in stored procedures...
    Edited by: _Locutus on Apr 2, 2009 2:37 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to call java method having array as argument from c++ ?

    Hello sir,
    how to call java method having array as arguments from c++;
    here is java code which is called from c++
    class PQR {
         public void xyz(int[] ia) {
         System.out.println("hi");
              for (int i = 0; i < ia.length; i++)
                   System.out.println(ia);
    suppose all jvm invocation is done...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    For someone well versed in java, C++ and JNI although tedious that should be obvious.
    For someone not well versed in all three it is going to be very difficult.
    Even for someone that does have knowledge in all of those areas coming up with a C++ interface that reflects that functionality in a dynamic way such that anyone is will to use it is going to be quite an adventure.
    At any rate to start building it you do exactly the same thing that you would in java.
    1. Extract everything in the jar via the zip package
    2. For each found instance extract all of the methods, return types, parameters, etc and build a description tree for each class.
    Doing all of that in C++ is going to take a LOT of code. If someone wanted an estimate from me it would take me 6 months to do it. And before I would even attempt it I would get them to explain to me in detail exactly how they thought they were going to use it when I was done because I can't see any reasonable way to do that.
    I left out the description tree itself. I suppose you could duplicate the entire reflection api in C++.
    Now perhaps if it was much, much more constrained, like to only those classes that implement a single interface then that would be more reasonable.

  • How to call javascript function from PL/SQL procedure

    Can anybody advice me how to call javascript function from PL/SQL procedure in APEX?

    Hi,
    I have a requirement to call Javascript function inside a After Submit Process.
    clear requirement below:
    1. User selects set of check boxes [ say user want to save 10 files and ticks 10 checkboxes]
    2. user clicks on "save files" button
    3. Inside a After submit process, in a loop, i want to call a javascript function for each of the file user want to save with the filename as a parameter.
    Hope this clarify U.
    Krishna.

  • How to call java function from PL/sql in oracle applications

    I am trying to call a java function from plsql procedure. Can any one explain how to call java function, and in which directory I have to store my java function in oracle applications. Do I need to register that java function from Application developer.
    Thanks
    Kranthi

    http://www.oracle.com/technology/tech/java/jsp/index.html
    Good Luck,
    Avi.

  • How to call stored function in my jsp

    how to call stored function in my jsp?
    please give me a example.

    Hi,
    think we need mor einformation, like JDeveloper release and the how you do access the database (JDBC, BC4J, EJB,ADF...)
    Frank

  • How can call a function module(RFC)in one server to another sever in my rep

    How can call a function module(RFC)in one server to another sever in my report program.
    What i am know whenever rfc enabled immediately radio button checks then only it will come.
    please justify.

    Syntax
    CALL FUNCTION func DESTINATION dest [EXPORTING p1 = a1 p2 = a2 ...]
    [IMPORTING p1 = a1 p2 = a2 ...]
    [CHANGING p1 = a1 p2 = a2 ...]
    [TABLES t1 = itab1 t2 = itab2 ...]
    [EXCEPTIONS [exc1 = n1 exc2 = n2 ...]
    [system_failure = ns [MESSAGE smess]]
    [communication_failure = nc [MESSAGE cmess]]
    [OTHERS = n_others]].
    http://help.sap.com/saphelp_47x200/helpdata/en/22/042537488911d189490000e829fbbd/frameset.htm

  • How to call java function in javascript

    Hello Everyone,
    Can anyone tell me solution that:
    How to call java function in javascript?
    Thanks,
    VIDs

    You can't since Java is running on the server and javascript is running in the browser long after the Java side of things has finished executing. Assuming you're not talking about an applet here.
    But you can make calls back to the server through Ajax. All you need is something like a servlet on the receiving end which you can invoke through Ajax; from that point you can execute any Java code you want.

  • How to call a function every 45 minutes?

    Hi..
    How to call a function after 45 minutes evry day..
    That function returns a value.
    Which is best? Thread or using timestamp?
    Regards

    Hello Joe,
    I heard of this website, gurgle something, that actually let's you put in words like "java" and "scheduling" and it will spit out other websites that mention these terms. Fascinating stuff, hopefully I'll find the time to test it someday soon..
    Lucky for you I have an article discussing solutions to your problem in my bookmarks:
    http://www.ibm.com/developerworks/web/library/j-schedule.html
    With kind regards
    Ben

  • How to call a function from asp

    Hi!, I'd like to know how to call a function from an asp page. I've written:
    set rs = server.createobject("Adodb.recordset")
    rs.open "call dbo.sf_Obt_Des_Producto ('0000161')",Conn
    if err.description <> "" then
    response.write ("No se pudo! :(")
    else
    response.write ("rs: " & rs(0))
    end if
    rs.close
    set rs = nothing
    but there is an error:
    ORA-06576: not a valid function or procedure name
    Please is very urgent!!!
    Thanks.
    Angie.

    You need to use the syntax "{call <procedure_name>}".
    The {call } syntax tells the OLE DB provider that it needs to translate the call into whatever the database's procedure calling syntax is. This means that even though different databases have different syntax for calling stored procedures, your OLE DB code can be run against any of them without changing.
    Justin

  • How to call java function with parameter from javascript in adf mobile?

    how to call java function with parameter from javascript in adf mobile?

    The ADF Mobile Container Utilities API may be used from JavaScript or Java.
    Application Container APIs - 11g Release 2 (11.1.2.4.0)

  • How to call javascript function?

    Hi,
    How to call javascript function for SAP button
    control onclick event?
    Thanks in advance.

    Hi Sundar,
      u can call java script  in design mode.
      Add this code in ur design part inside body and call the function as
    <sap:button id="a" onSelect="javascript:go();"
    Add inside body:
      <script language="javascript>
    function go(){
    alert("hai");
      </script>
    Regards,
    Vinoth.M

  • Cannot call member function on object type

    On 8.1.6 I cannot call a member function from SQL in the way described in the manual.
    The following example is almost copied from the manual:
    create or replace TYPE foo AS OBJECT (a1 NUMBER,
    MEMBER FUNCTION getbar RETURN NUMBER);
    create or replace type body foo is
    MEMBER FUNCTION getbar RETURN NUMBER is
    begin
    return 45;
    end;
    end;
    CREATE TABLE footab(col foo);
    SELECT col,foo.getbar(col) FROM footab; -- OK
    select col,col.getbar() from footab; -- ERROR
    The second select is the way it should be, but I get an error "invalid column name".
    Using the first select, I get the result. This is strange because this is more or less the 'static member' notation (filling in the implicit self parameter myself).
    Is this a known bug in 8.1.6, maybe fixed in later versions?

    Konstantin,
    Did you use loadjava to load the compiled class into the Oracle Database?
    Regards,
    Geoff
    Hello!
    I need to write a member function for object type with java.
    for example:
    create type test as object(
    id number,
    name varchar2(20),
    member function hallo return number);
    create type body test as
    member function hallo return number
    as language java
    name 'test.hallo() return int;
    create table test of test;
    My java-file is:
    public class test {
    public int hallo() {
    return 5;
    select t.hallo() from test t;
    It's does not run. Why?
    I get always an error back. Wrong types or numbers of parameters!!
    please help me.
    thanks in advance
    Konstantin

  • How to call a function/event after a Remote Object's data is loaded?

    I'm making a call to a remote object that is loading a good
    amount of data. I've set up a "please wait" label that is supposed
    to display while the data is being loaded and then clear the label
    when the data finishes loading.
    At the moment I've got it set up like so...
    label = 'Loading data, please wait..."
    remoteObj.read.send();
    label = ''
    The problem with this is that the 'please wait' label doesn't
    even display because the actual call to the remote object I'm
    making finishes so quickly even though the data load does not. So
    what I need is possibly an IF statement to check if the data has
    finished loading. If it hasn't finished loading, the label stays in
    the "please wait" status, or if the data does finish loading, then
    the label clears out.
    What would be ideal is...
    remoteObj.read.send(); // gets the data
    if(data is loaded){
    label = '';
    }else{
    label = 'Please wait'
    I just don't know how to form the statement for the data
    loading in the IF statement.

    You are seeing the difference between data loading and UI
    rendereing.
    Reasonable amounts of data load very fast, expecially with
    RemoteObject. Bur rendering the UI is almost always the bottleneck,
    event with AS3 FP8+, which is about 30 percent faster than AS2!
    I have not found a perfect solution for this myself, but i
    think you will want to look into the component data events, to find
    one that fires after the component is actually rendered.
    Tracy

  • How to call a function with pl/sql

    How does one call a function with pl/sql that uses a function?

    Hi,
    How does one call a function with pl/sql that uses a
    function?I'm not sure what you mean.
    In PL/SQL function can be used just about anywhere where an expression (with the same data type that the function returns). Arpit gave a very common example.
    Here's another example, where all the functions take a single NUMBER argument and return a NUMBER, so they can all be used in places where NUMBERs are used:
    IF  fun_a (fun_b (0)) < fun_c (1)
    THEN
        UPDATE  table_x
        SET     column_y = fun_d (2)
        WHERE   column_z = fun_e (ROUND ((fun_f (3), fun_g (4)));You call a function simply by using its name, followed by its argument list, if any.
    If the function is in a package, you must call it with the package name, like "pk_foo.bar (1, 2, 3)", unless the call comes from within the same package.
    If the function is owned by someone else, you must give the owner name, like "scott.bar (SYSDATE)" or "scott.pk_foo.bar (1, 2, 3)". You can create synonyms to avoid having to name the owner.

Maybe you are looking for

  • Snapshots not getting generated automatically

    Hi all, I want to generate an ADDM report. For that, I am running the addmrpt.sql script in $ORACLE_HOME/rdbms/admin While running, i am being asked for the begin_snap ID and end_snap ID. The problem is I have only one snap_id. The snapshots are not

  • Rapport is not visible in firefox 5, how do I resolve this?

    I change to firefox 5 this morning, it made me aware that google toolbar was not compatible but did not mention Trusteer Rapport. It was not working so I 'repaired' it, although it seems to be working it put up an error message about a mail package a

  • Connect 9 add-in for Folder redirection environment

    Is there a way to get this to work in the new Connect 9 system. We have a hosted account And ever since they moved us to connect 9 the connect add-in is not working. We know that there is a new connect add-in located \staff\Staff Profiles\Application

  • IN BACKGROUND TASK

    Hi all, howe can I do to use INSERT_COUNT ? R/3 (RFC) --> xi --> (JDBC - Insert) R/3 (RFC) <-- xi <-- (JDBC - Insert.response) I want to know how much registers was inserted in database. I know that must to be used element INSERT_COUNT in the message

  • Ipad 2 unable to update or restore 1671 error

    I have an IPAD2 32 GB with 4/5 GB of free space. Have had a very slow keyboard and had done a reset a few days ago with no problem/ Software was up to date as of this morning 8.3. Did a reboot because of the continuing slow and delay issues with the