How to enforce md5 function to accept varchar2?

I am trying to use md5 function from dbms_obfuscation_toolkit package.
There are two functions called md5 in that package, the first one accepts one parameter as raw and returns raw whereas the second one accepts one parameter as varchar2 and returns varchar2.
I want to use the second one (varchar2) I tried this code:
declare
v_output varchar2(16);
v_checksum varchar2(16);
v_input varchar2(50) DEFAULT 'SAAD';
begin
v_checksum := dbms_obfuscation_toolkit.md5 (input_string => 'SAAD');
v_output := dbms_obfuscation_toolkit.md5(v_input);
if (v_output = v_checksum) then
dbms_output.put_line('TRUE');
else
dbms_output.put_line('FALSE');
end if;
end;
An eror message appeared:
PLS-00307:too many declarations of 'MD5' match this call
I tried to cast inout_string using cast('SAAD' as varchar2(16)) but it didn't change anything.
How can I enforce md5 function to accept varchar2 and return varchar2

I am getting inproper output if I pass HARBINDER,in uppercase, to md5 and respective put_line does not print the following any output of the line(val1). In word 'Harbinder', what is there which is stopping the interpreter to print. It's strange!
declare
val varchar2(25);
val1 varchar2(25);
input varchar2(15) := 'HARBINDER';
begin
val :=dbms_obfuscation_toolkit.md5(input_string=>input);
val1 :=dbms_obfuscation_toolkit.md5(input_string=>'Harbinder');
dbms_output.put_line('Input: '||input||',Val: '||val|| ',Val1: '|| val1);
end;
OUTPUT:
Input: HARBINDER,Val: ¨
False
What can be the reason?

Similar Messages

  • How to enforce a function signature?

    Hi,
    I hava a class structure like this
    class B {
      var func:Function;
    class A {
       var b:B;
    class A1 extends A {
       function A1() {
           super();
           b.func = myfunc;
       function myfunc(var onoff:Boolean) {
    and somewhere an event handler like this
    function hndl(e:Event):void {
       if(e.target is A && A(e.target).b.func != null)
          A(e.target).b.func(something)
    So if one of the A variants wants to implement the function, it lives in its own namespace. Now, how could I ensure that the compiler checks the argument structure?

    Yes, method overloading (supplying the same function name with an optional number of arguments) is not supported.
    AS3 will get there but for now you're better off doing one of two things.
    1, including all possible methods with a default value possible
    e.g. private function methodName(a:int = 0; b:String = '', c:CustomClass = CustomClass(), yada...)
    2, changing the function name for the arguments you need
    e.g. private function methodThatAcceptsFourArguments(a:int = 1, b:int =2, c:int = 3, d:int = 4)
    There is nothing in between without method overloading.
    Note AS4 has namespaces, overloading, etc....

  • How can I make Function return varchar2 more than 4000

    I have a function
    FUNCTION testing (v_pk_application in number, v_inccharges in char)
    return varchar2(30000)
    --return number
    is
    v_net_sum varchar2(30000);
    v_net_sum2 varchar2(30000);
    v_datarow varchar2(3000);
    v_datarow2 varchar2(3000);
    begin
    return v_net_sum;
    end;
    I want to return varchar2 more than 4000, how can I do that.
    Thanks

    user10659388 wrote:
    I want to return varchar2 more than 4000, how can I do that.A function can return a string up to the maximum allowed for varchar2.
    Varchar2 can be up to 32767 characters...
    SQL> create or replace function ret_str return varchar2 is
      2    v_str varchar2(32767);
      3  begin
      4    v_str := lpad('*',32767,'*');
      5    return v_str;
      6  end;
      7  /
    Function created.
    SQL> declare
      2    v_retstr varchar2(32767);
      3  begin
      4    v_retstr := ret_str();
      5  end;
      6  /
    PL/SQL procedure successfully completed.However, SQL only supports varchar2 up to 4000 characters so the same function will cause SQL to error, even though the function is perfectly valid.
    SQL> select ret_str() from dual;
    select ret_str() from dual
    ERROR at line 1:
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    ORA-06512: at "SCOTT.RET_STR", line 5
    SQL>So, if you intend to use the function only in PL/SQL then you can use varchar2 up to 32767 characters, but if you intend to use it in SQL then you will be limited to returning 4000 characters. Alternatively you can return a CLOB which SQL supports but they are a little more tricky to work with than varchar2...
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace function ret_str return clob is
      2    v_str clob;
      3  begin
      4    v_str := lpad('*',32767,'*');
      5    return v_str;
      6* end;
    SQL> /
    Function created.
    SQL> select ret_str() from dual;
    RET_STR()
    SQL>

  • How to write a function with table name as parameter

    I created a function like this:
    create or replace function "GETNAME"
    (did in NUMBER, dtable in VARCHAR2)
    return VARCHAR2
    is
    dname varchar2(200);
    begin
    select lastname || ' ' || firstname
    into dname from dtable
    where id = did;
    return dname;
    end;
    i got an error: table or view does not exist.
    Could somebody tell me how to fix it?
    Thanks,
    Jen

    or by using a reference cursor:  create or replace function dynamic_cursor (pTab varchar2)
        return sys_refcursor as
        c sys_refcursor;
      begin
        open c for 'select * from '|| pTab;
        return c;
      end;
    SQL> exec :c := dnamic_cursor('emp');
    SQL> exec :c := dynamic_cursor('emp');
    PL/SQL procedure successfully completed.
    SQL> print c;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7566 JONES      MANAGER         7839 02-APR-81       2975       1000         20
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
          7839 KING       PRESIDENT            17-NOV-81       5000                    10
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
          7369 SMITH      CLERK           7902 17-DEC-80        800                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
          7788 SCOTT      ANALYST         7566 09-DEC-82       3000                    20
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7876 ADAMS      CLERK           7788 12-JAN-83       1100                    20
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
          7945 CINDY      SALESMAN        7698 16-JAN-83       1800                    30
          7950 TINA       SALESMAN        7698 18-JAN-83       1850                    30
    16 rows selected.
    SQL>

  • How to convert Oracle function in UDB

    Hi ,
    i am writing this function in oracle.Could you please convert this function in UDB because i am new in this and dont know how to use decode function in UDB
    Please following is the code for oracle.
    CREATE OR REPLACE function fun ( localex varchar2,titlex varchar2)
    return number
    as x number;
    begin
    select sum ( decode (count (username),max(prereq_count),1,0) ) x into x from
    SELECT
    prereq_count,
    username
    FROM
    table1
    group by username ;
    return x;
    end fun;
    Regards
    Vishal

    First, you posted in the wrong forum for UDB, this is DB2 on z/OS
    Secondly, your question is not SAP related (at least I can't see that).
    Thirdly, you posted the same question for SQL-Server:
    want to convert function in SQL Server 2000
    Markus

  • How to call c functions that expects c structs from java program?

    i need to call from my java program to c functions that get
    c structs as a parameters in their prototype.
    as you probablly know java is not working with structs (classes only), so my question is how can i do it , i mean call the c functions that gets structs as parameters form java????

    i believe your c function can accept a jobject and then inside your c function you have to translate that jobject into a c struct by using the jni methods.
    the only reason your c function cant accept structs from java is because java does not have such structures. your c function can accept any data type that has been defined and a jobject has been defined.
    if you have no control over the c functions that are being called, you need to write a wrapper function for those c function. the wrapper functions do the translation from jobject to a struct...then call the c other c functions.

  • How to Use this function

    I am not sure how to call this Function correctly and how to pass the IN parameter, I am still new and learning, please help!
    So far I have compiled it, and it compiled fine and saved it in my schema.
    It is supposed to be able to calculate the compression ratio for say TABLE_1234 to see how much space it would save if
    I used the COMPRESS option in 10G.
    CREATE OR REPLACE function Y775.compression_ratio (tabname varchar2)
    return number is
    pragma autonomous_transaction;
    -- sample percentage
    pct number := 0.000099;
    -- original block count (should be less than 10k)
    blkcnt number := 0;
    -- compressed block count
    blkcntc number;
    begin
    execute immediate ' create table TEMP_UNCOMPRESSED pctfree 0
    as select * from ' || tabname ||
    ' where rownum < 1';
    while ((pct < 100) and (blkcnt < 1000)) loop
    execute immediate 'truncate table TEMP_UNCOMPRESSED';
    execute immediate 'insert into TEMP_UNCOMPRESSED select * from ' ||
    tabname || ' sample block (' || pct || ',10)';
    execute immediate 'select
    count(distinct(dbms_rowid.rowid_block_number(rowid)))
    from TEMP_UNCOMPRESSED' into blkcnt;
    pct := pct * 10;
    end loop;
    execute immediate 'create table TEMP_COMPRESSED compress as
    select * from TEMP_UNCOMPRESSED';
    execute immediate 'select
    count(distinct(dbms_rowid.rowid_block_number(rowid)))
    from TEMP_COMPRESSED' into blkcntc;
    execute immediate 'drop table TEMP_COMPRESSED';
    execute immediate 'drop table TEMP_UNCOMPRESSED';
    return (blkcnt/blkcntc);
    end;
    /

    Ok, ok - so I have updated the function and it compiled, fine, but now nothing is returned, I thought that a number was returned ?
    CREATE OR REPLACE function Y775.compression_ratio (tabname varchar2)
    return number
    AUTHID CURRENT_USER
    is
    pragma autonomous_transaction;
    -- sample percentage
    pct number := 0.000099;
    -- original block count (should be less than 10k)
    blkcnt number := 0;
    -- compressed block count
    blkcntc number;
    begin
    execute immediate ' create table TEMP_UNCOMPRESSED pctfree 0
    as select * from ' || tabname ||
    ' where rownum < 1';
    while ((pct < 100) and (blkcnt < 1000)) loop
    execute immediate 'truncate table TEMP_UNCOMPRESSED';
    execute immediate 'insert into TEMP_UNCOMPRESSED select * from ' ||
    tabname || ' sample block (' || pct || ',10)';
    execute immediate 'select
    count(distinct(dbms_rowid.rowid_block_number(rowid)))
    from TEMP_UNCOMPRESSED' into blkcnt;
    pct := pct * 10;
    end loop;
    execute immediate 'create table TEMP_COMPRESSED compress as
    select * from TEMP_UNCOMPRESSED';
    execute immediate 'select
    count(distinct(dbms_rowid.rowid_block_number(rowid)))
    from TEMP_COMPRESSED' into blkcntc;
    execute immediate 'drop table TEMP_COMPRESSED';
    execute immediate 'drop table TEMP_UNCOMPRESSED';
    return (blkcnt/blkcntc);
    end;
    /

  • How to pipeline a function with a dynamic number of columns?

    Hi everyone,
    I'm trying to figure out how to write a piplined function that generates a dynamic SQL statement from its inputs, executes the query, and returns the results of the query in the pipeline. The number and names of the columns in the dynamic query is unknown number until the function is invoked.
    I suspect that DBMS_SQL is involved, but can't quite figure out how to construct a row using it that I can use PIPE ROW on. I also can't figure out what data type the function should return (ANYDATASET?)
    pseudo-PLSQL follows:
    create function myfunction ( param1 varchar2)
    return anydataset pipelined
    as
    query_string := <... do stuff with param1 ...>
    < -- >
    open a cursor for query_string
    determine the number of columns
    read a row
    PIPE ROW it
    <--->
    Can what I'm trying to do be done?
    Thanks,
    Keith

    The following works on 10R2
    create or replace type NColPipe as object
      l_parm varchar2(10),   -- The parameter given to the table function
      rows_requested number, -- The parameter given to the table function
      ret_type anytype,      -- The return type of the table function
      rows_returned number,  -- The number of rows currently returned by the table function
      static function ODCITableDescribe( rtype out anytype, p_parm in varchar2, p_rows_req in number := 2 )
      return number,
      static function ODCITablePrepare( sctx out NColPipe, ti in sys.ODCITabFuncInfo, p_parm in varchar2, p_rows_req in number := 2 )
      return number,
      static function ODCITableStart( sctx in out NColPipe, p_parm in varchar2, p_rows_req in number := 2 )
      return number,
      member function ODCITableFetch( self in out NColPipe, nrows in number, outset out anydataset )
      return number,
      member function ODCITableClose( self in NColPipe )
      return number,
      static function show( p_parm in varchar2, p_rows_req in number := 2 )
      return anydataset pipelined using NColPipe
    create or replace type body NColPipe as
      static function ODCITableDescribe( rtype out anytype, p_parm in varchar2, p_rows_req in number := 2 )
      return number
      is
        atyp anytype;
      begin
        anytype.begincreate( dbms_types.typecode_object, atyp );
        if p_parm = 'one'
        then
          atyp.addattr( 'one'
                      , dbms_types.typecode_varchar2
                      , null
                      , null
                      , 10
                      , null
                      , null
        elsif p_parm = 'two'
        then
          atyp.addattr( 'one'
                      , dbms_types.typecode_varchar2
                      , null
                      , null
                      , 10
                      , null
                      , null
          atyp.addattr( 'two'
                      , dbms_types.typecode_varchar2
                      , null
                      , null
                      , 10
                      , null
                      , null
        else
          atyp.addattr( p_parm || '1'
                      , dbms_types.typecode_varchar2
                      , null
                      , null
                      , 10
                      , null
                      , null
          atyp.addattr( p_parm || '2'
                      , dbms_types.typecode_varchar2
                      , null
                      , null
                      , 10
                      , null
                      , null
          atyp.addattr( p_parm || '3'
                      , dbms_types.typecode_number
                      , 10
                      , 0
                      , null
                      , null
                      , null
        end if;
        atyp.endcreate;
        anytype.begincreate( dbms_types.typecode_table, rtype );
        rtype.SetInfo( null, null, null, null, null, atyp, dbms_types.typecode_object, 0 );
        rtype.endcreate();
        return odciconst.success;
      exception
        when others then
          return odciconst.error;
      end;  
      static function ODCITablePrepare( sctx out NColPipe, ti in sys.ODCITabFuncInfo, p_parm in varchar2, p_rows_req in number := 2 )
      return number
      is
        elem_typ sys.anytype;
        prec pls_integer;
        scale pls_integer;
        len pls_integer;
        csid pls_integer;
        csfrm pls_integer;
        tc pls_integer;
        aname varchar2(30);
      begin
        tc := ti.RetType.GetAttrElemInfo( 1, prec, scale, len, csid, csfrm, elem_typ, aname );
        sctx := NColPipe( p_parm, p_rows_req, elem_typ, 0 );
        return odciconst.success;
      end;
      static function ODCITableStart( sctx in out NColPipe, p_parm in varchar2, p_rows_req in number := 2 )
      return number
      is
      begin
        return odciconst.success;
      end;
      member function ODCITableFetch( self in out NColPipe, nrows in number, outset out anydataset )
      return number
      is
      begin
        anydataset.begincreate( dbms_types.typecode_object, self.ret_type, outset );
        for i in self.rows_returned + 1 .. self.rows_requested
        loop
          outset.addinstance;
          outset.piecewise();
          if self.l_parm = 'one'
          then
            outset.setvarchar2( to_char( i ) );
          elsif self.l_parm = 'two'
          then
            outset.setvarchar2( to_char( i ) );
            outset.setvarchar2( 'row: ' || to_char( i ) );
          else
            outset.setvarchar2( 'row: ' || to_char( i ) );
            outset.setvarchar2( 'row: ' || to_char( i ) );
            outset.setnumber( i );
          end if;
          self.rows_returned := self.rows_returned + 1;
        end loop;
        outset.endcreate;
        return odciconst.success;
      end;
      member function ODCITableClose( self in NColPipe )
      return number
      is
      begin
        return odciconst.success;
      end;
    end;
    /And to use it
    SQL> select * from table( NColPipe.show( 'test', 3 ) );
    test1      test2           test3
    row: 1     row: 1              1
    row: 2     row: 2              2
    row: 3     row: 3              3
    SQL>  select * from table( NColPipe.show( 'two', 5 ) );
    one        two
    1          row: 1
    2          row: 2
    3          row: 3
    4          row: 4
    5          row: 5
    SQL> select * from table( NColPipe.show( 'one' ) );
    one
    1
    2
    SQL> Anton

  • How to make a function return number(10,0) data type (ORACLE 10g)?

    With 10g, how to make a function return number(10,0) data type?
    here is the function, it returns a number type :
    create or replace FUNCTION Get_portfolio_Id3 (p_HistObjTable In Varchar2,p_LHISTOBJID IN NUMBER) RETURN view_cpu_STD_Asset.LPORTFOLIOITEMID%Type IS
    v_Id view_cpu_STD_Asset.LPORTFOLIOITEMID%Type;
    BEGIN
    If p_HistObjTable ='amPortfolio'
    then v_Id:=p_LHISTOBJID ;
    elsIf p_HistObjTable = 'amComputer' then
    select litemid into v_Id from smcdba.amComputer c where c.LCOMPUTERID=p_LHISTOBJID ;
    else v_Id:=-99;
    End If;
    RETURN v_Id;
    END Get_portfolio_Id3;
    Thanks.
    Message was edited by:
    user631701

    create or replace FUNCTION Get_portfolio_Id3 (p_HistObjTable In Varchar2,p_LHISTOBJID IN NUMBER) RETURN view_cpu_STD_Asset.LPORTFOLIOITEMID%Type IS
    v_Id view_cpu_STD_Asset.LPORTFOLIOITEMID%Type;
    BEGIN
    If p_HistObjTable ='amPortfolio'
    then v_Id:=p_LHISTOBJID ;
    elsIf p_HistObjTable = 'amComputer' then
    select litemid into v_Id from smcdba.amComputer c where c.LCOMPUTERID=p_LHISTOBJID ;
    else v_Id:=-99;
    End If;
    RETURN round(v_Id);
    END Get_portfolio_Id3;

  • How to write a function to find weekday

    my code as follow:
    create or replace function getweekday(arg_day_IN VARCHAR2)
    RETURN varchar2
    IS
    arg_day VARCHAR2(8) := arg_day_IN;
    ls_week VARCHAR2(1);
    ls_week_name VARCHAR2(4);
    ls_date_1 date;
    BEGIN
    ls_date_1 := to_char(SUBSTR(arg_day, 5, 2) || '-' || SUBSTR(arg_day, 7, 2) )|| '-' ||SUBSTR(arg_day, 1, 4));
    ls_week := OMWB_emulation.utilities.WEEKDAY(ls_date_1);
    RETURN ls_week;
    END getweekday;
    There is a problem that when i execute this function it returns a error code ora-01843, it shows that it is not a valid month.
    How can I know what is a valid month format? How to find the correct month format?
    Which one is the valid date format- 02-01-2004 or 02-Jan-2004 or 02-January-2004.
    Please help me to solve this problem. Thanks a lot.

    If the input parameter format is 'yyyymmdd' you can do:
    create or replace function getweekday(arg_day_IN VARCHAR2)
    RETURN varchar2
    IS
    ls_week VARCHAR2(1);
    BEGIN
    ls_week := to_char(to_date(agr_day_IN,'yyyymmdd'),'D');
    RETURN ls_week;
    END getweekday;

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

  • How to run a function

    Hi,
    can anyone tell me how to run this functions while generating reports for labels.
    please i need some guidance.
    create or replace function get_label_nextval(p_label varchar2) return integer
    is
    l_last_num integer;
    cursor c_label is
    select last_num from label_id where label = upper(trim(p_label)) for update wait 10;
    pragma autonomous_transaction;
    begin
    open c_label;
    fetch c_label into l_last_num;
    if l_last_num is not null then
    l_last_num := l_last_num + 1;
    update label_id set last_num = l_last_num where current of c_label;
    commit;
    end if;
    close c_label;
    return l_last_num;
    end;
    Thanks and Regards

    ORA-06519: active autonomous transaction detected and rolled back
    Cause: Before returning from an autonomous PL/SQL block, all autonomous transactions started within the block must be completed (either committed or rolled back). If not, the active autonomous transaction is implicitly rolled back and this error is raised.
    Action: Ensure that before returning from an autonomous PL/SQL block, any active autonomous transactions are explicitly committed or rolled back.
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10880/e4100.htm#sthref2110
    I think your COMMIT should be moved outside your IF.
    Commit just before your RETURN, after your CLOSE CURSOR statement.
    Edited by: hoek on Jan 4, 2010 1:28 PM typo

  • How to call LabView function with nested structs and arrays from C#

    Hi,
    I've got the following functions defined in a LabView-dll:
    uint32_t __stdcall VOSC04_General(uint32_t Command, TD18Hdl *Messages);
    uint32_t __stdcall CheckDiameter(uint32_t Command, TD6 *Parameter);
    typedef struct {
     double SP_Diameter;
     double SP_Tolerantie;
     double PV_Diameter;
     } TD6;
    typedef struct {
     int32_t dimSize;
     int32_t Numeric[1];
     } TD18;
    typedef TD18 **TD18Hdl;
    I've got some C#-code (generated by PInvoke-wizard) to call these functions:
    [DllImport("vosc04.dll")]
    public static extern uint32_t VOSC04_General (uint32_t Command, ref TD18Hdl Messages);
    [DllImport("vosc04.dll")]
    public static extern uint32_t CheckDiameter(uint32_t Command, ref TD6 Parameter);
    [StructLayout(LayoutKind.Sequential,Pack=4)]
    public struct TD18
       public int32_t dimSize;
       [ MarshalAs( UnmanagedType.ByValArray, SizeConst=1)]
       public int32_t [] Numeric;
    [StructLayout(LayoutKind.Sequential,Pack=4)]
    public struct TD6
       public Double SP_Diameter;
       public Double SP_Tolerantie;
       public Double PV_Diameter;
    The problem now is that when I try to read the Messages-output-parameter, I get wrong values (pointers?). I think that the problem lies in the fact that LabView generated a TD18 AND an TD18Hdl struct.
    How can I correct this problem?
    Can anyone give me some advise to correct this problem? I'm not an expert in C, only in C#.

    I think the problematic line is this:
    public struct TD18
       public int32_t dimSize;
       [ MarshalAs( UnmanagedType.ByValArray, SizeConst=1)]
       public int32_t [] Numeric;
    It looks like C# is forcing the array to be of size 1. The thing is, LabVIEW stores arrays as handles which are double pointers to a structure which contains a size element followed by the elements of the array. For your example, int32 arrays are stored in memory as:
    handle -> location -> |size|element 1|element 2| .... |element size-1|
    Because C does not do runtime array bounds checking, you can get away by declaring the structure as:
    typedef struct {
     int32_t dimSize;
     int32_t Numeric[1];
     } TD18;
    The correct declaration would've been:
    typedef struct {
     int32_t dimSize;
     int32_t Numeric[size];
     } TD18;
    But size is not a constant, so C/C++ won't let you do that. So, even though the array is declared to be of size 1, it can (and usually does) have more than 1 element. This does not cause a problem because LabVIEW allocates memory based on the actual size of the array.
    If I were you, I'd try to change the prototype of the LabVIEW DLL function to accept a pointer to array data, rather than an array handle, pre-allocate memory for the array in C# and pass a pointer to the allocated memory into LabVIEW so that LabVIEW can "fill it up".
    Let me know if you need more information.
    Pramod

  • How to call a function which has a cursor

    hey folks I have a function which has a cursor,,like this
    CREATE OR REPLACE FUNCTION EMPCU RETURN VARCHAR
    AS
    CURSOR EMPC IS
    SELECT LNAME,SALARY,SSN
    FROM EMPLOYEE
    WHERE DNO IN(4,5);
    EMPV EMPC%ROWTYPE;
    BEGIN
    OPEN EMPC;
    LOOP
    FETCH EMPC INTO EMPV;
    EXIT WHEN EMPC%NOTFOUND;
    /*DBMS_OUTPUT.PUT_LINE(EMPV.LNAME||' '||EMPV.SALARY||' '||EMPV.SSN);*/
    RETURN EMPV. LNAME ||' '|| EMPV.SALARY||' '||EMPV.SSN;
    END LOOP;
    CLOSE EMPC;
    END EMPCU;
    Above function created successfully. I called above function like this
    DECLARE
    ENAMESAL VARCHAR2(70);
    BEGIN
    ENAMESAL:=EMPCU();
    DBMS_OUTPUT.PUT_LINE(ENAMESAL);
    END;
    Function is called and function is returning only one row instead of 7 rows. Actually cursor is supposed to return 7 rows but it is returning only one row. Is there any snytax to call a function which has a cursor. So experts please tell me where I have to make changes. I would be very thankful to you

    Well, you've told the function to RETURN within the loop, so after the first record in the loop, the function returns as you've instructed it.
    You would need to change your function to accept a specific input from the EMP table and then do a look up for that specific record and return the values you wanted, and wrap the function call in a loop in your anonymous block.
    Or you could just have the anonymous block like this....
    BEGIN
       FOR X IN
          SELECT EMPV. LNAME ||' '|| EMPV.SALARY||' '||EMPV.SSN AS Line_Data
          FROM EMPLOYEE
          WHERE DNO IN(4,5)
       LOOP 
          DBMS_OUTPUT.PUT_LINE(x.Line_Data);
       END LOOP;     
    END;
    /

Maybe you are looking for

  • Addon not loading - B1 Usability Package for all users in SAP Business One

    Hello, I am a new admin to SAP B1 and am about to go live in a few weeks. We are running SAP Business One v. 8.80.227. Envirorment details: Dedicated server for SAP database, and Terminal Server for remote connections. I have a demo group of users in

  • Error while adding users to a group created in shared services

    Hi All, I am using EPM 11.1.1.1.0.. When i log into SHared services as admin and create a group i get the following error when i try to add the user members to the group. "Servlet error: An exception occurred. The current application deployment descr

  • Logical Arrangement of Preloader Script

    Hi, I have created one swf which does following two things; 1. Once it gets loaded in HTML on server it will pass Flashvar to HTML. if flash var from swf and HTML both will match then only swf should play. 2. It will also have Preloader independently

  • Dell E228WFP 22" display - Problems connecting to Powerbook 1.67ghz

    Hi All I've seen this same issue mentioned in another post elsewhere in the Apple Discussions, but it seems to remain unresolved in that instance... I've just bought a 22" Dell E228WFP display to connect to my 1.67ghz Powerbook 17", running OS 10.4.9

  • Use of MDX in 7.x and higher

    Hi All,<BR>I am new to MDX. can someone tell me where exactly does MDX comes into function in Essbase. From the documentation i know that it is used for writing formulas in ASO database and extract data. I would like to know how can i extract data us