To_date function in procedure which returns a cursor type

Hi All
When i execute the following query ,it runs fine and i get required result also
select *from a where adate>to_date('31-dec-2001')
But When i use the same query in a procedure which returns a cursor i get a error
"non numeric character was found where a numeric value was expected".
Then i changed the query to
select *from a where adate>to_date('31-dec-2001','dd-mon-yyyy') and it worked fine.
As i know default date format is 'dd-mon-yyyy' and no need to give the date format
explicitly in to_date function if the date(string) is in default format.
Can any body tell me the reason behind it?
Thanks
Satya

Given a comparison between a date and a string Oracle will convert the string to a date. This means that if you have an index on a string column and compare it to a date the index will not be available, but if you have an index ona date column and compare it to a string column the index will be available.
create table t (string varchar2(30), d  date);
insert into t values (to_char(sysdate), sysdate);
commit;
create index t_n1 on t(string);
create index t_n2 on t(d);
SQL> set autotrace traceonly
SQL> select /*+ index t_n1 */
  2         *
  3    from t
  4   where string = sysdate;
no rows selected
Execution Plan
   0      SELECT STATEMENT Optimizer=CHOOSE
   1    0   TABLE ACCESS (FULL) OF 'T'
SQL> select /*+ index t_n2 */
  2         *
  3    from t
  4   where d = to_char(sysdate);
no rows selected
Execution Plan
   0      SELECT STATEMENT Optimizer=CHOOSE
   1    0   TABLE ACCESS (BY INDEX ROWID) OF 'T'
   2    1     INDEX (RANGE SCAN) OF 'T_N2' (NON-UNIQUE)
SQL>

Similar Messages

  • Function calling stored procedure that returns a cursor into a LOV

    Hello,
    Is it possible in HTML DB to implement a process that has a function that calls a stored procedure that returns a cursor, used to then populate a select list?
    Or can I do a function call to a stored procedure in the 'List of values definition' box for the item itself that returns a cursor to populate the item's select list?

    Hi Vikas,
    Actually, I just found another posting that shows how to do what I'm looking for:
    Re: Filling a LOV with a cursor
    Check it out. I posted another question in response to that discussion...maybe you could answer that? Thanks!
    Laura

  • Stored PL/SQL function that returns REF CURSOR type

    Hello everyone,
    I've come through the following problem:
    1.- I created an PL/SQL stored procedure which returns a REF CURSOR element, definition looks like this:
    PACKAGE PKG_LISTADOS AS
    TYPE tuplas IS REF CURSOR;
    /* Procedimientos exportados por el paquete */
    PROCEDURE inicializarModuloListados;
    FUNCTION recaudacionUltimoMes(medioPago DEF_MEDIO_PAGO.MEDIO_PAGO%TYPE)
    RETURN tuplas;
    2.- Now I would like to call the stored procedure and retrieve the PL/SQL cursor as a ResultSet Java Object. The code I wrote is this:
    Connection conn;
    XmlDocument paramDef;
    conn=poolMgr.getConnection str_poolDBConnection);
    try
    CallableStatement cstmt=conn.prepareCall("{?=call PKG_LISTADOS.recaudacionUltimoMes(?)}");
    cstmt.registerOutParameter(1, java.sql.Types.OTHER);
    cstmt.setString(2, "MONEDA");
    cstmt.executeQuery();
    ResultSet rs=(ResultSet)cstmt.getObject(1);
    catch(SQLException sqlE)
    3.- However, I can't make it OK, all the time I get the following error:
    SQL Error(17004), java.sql.SQLException: Non valid column type
    May anyone help me with this, thanks in advance:
    Miguel-Angel

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by angelrip:
    Hello everyone,
    I've come through the following problem:
    1.- I created an PL/SQL stored procedure which returns a REF CURSOR element, definition looks like this:
    PACKAGE PKG_LISTADOS AS
    TYPE tuplas IS REF CURSOR;
    /* Procedimientos exportados por el paquete */
    PROCEDURE inicializarModuloListados;
    FUNCTION recaudacionUltimoMes(medioPago DEF_MEDIO_PAGO.MEDIO_PAGO%TYPE)
    RETURN tuplas;
    2.- Now I would like to call the stored procedure and retrieve the PL/SQL cursor as a ResultSet Java Object. The code I wrote is this:
    Connection conn;
    XmlDocument paramDef;
    conn=poolMgr.getConnection str_poolDBConnection);
    try
    CallableStatement cstmt=conn.prepareCall("{?=call PKG_LISTADOS.recaudacionUltimoMes(?)}");
    cstmt.registerOutParameter(1, java.sql.Types.OTHER);
    cstmt.setString(2, "MONEDA");
    cstmt.executeQuery();
    ResultSet rs=(ResultSet)cstmt.getObject(1);
    catch(SQLException sqlE)
    3.- However, I can't make it OK, all the time I get the following error:
    SQL Error(17004), java.sql.SQLException: Non valid column type
    May anyone help me with this, thanks in advance:
    Miguel-Angel<HR></BLOCKQUOTE>
    Do something like the following:
    cstmt = conn.prepareCall("{call customer_proc(?, ?)}");
    //Set the first parameter
    cstmt.setInt(1, 40);
    //Register to get the Cursor parameter back from the procedure
    cstmt.registerOutParameter(2, OracleTypes.CURSOR);
    cstmt.execute();
    ResultSet cursor = ((OracleCallableStatement)cstmt).getCursor(2);
    while(cursor.next())
    System.out.println("CUSTOMER NAME: " + cursor.getString(1));
    System.out.println("CUSTOMER AGE: " + cursor.getInt(2));
    cursor.close();
    null

  • How to test a procedure which returns a recordset from pl/sql

    hello,
    Is it possible to test a procedure which returns a recordset from pl/sql?
    Everything I try results in errors like PLS-00382: expression is of wrong type, when I try to open the result cursor
    or PLS-00221: tc is not a procedure or is undefined.
    I created the following procedure:
    CREATE OR REPLACE PACKAGE test AS
    TYPE cursorType is REF CURSOR;
    PROCEDURE test_cursor( tc IN OUT cursorType,
    v_err OUT varchar2,
    v_msg OUT varchar2);
    END;
    CREATE OR REPLACE
    PACKAGE BODY test AS
    PROCEDURE test_cursor
    (tc IN OUT cursorType,
    v_err OUT varchar2,
    v_msg OUT varchar2)
    AS
    BEGIN
    open tc for
    SELECT '1' "number" FROM dual
    union
    select '2' "number" from dual;
    v_msg := 'no errors';
    v_err := 0;
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    v_msg := 'no data found';
    v_err := SQLCODE;
    WHEN OTHERS
    THEN
    v_msg := SQLERRM;
    v_err := SQLCODE;
    END;
    END;
    I try to get the output from pl/sql with something like this:
    DECLARE
    TC PROVGRON.TEST.cursorType;
    V_ERR VARCHAR2(200);
    V_MSG VARCHAR2(200);
    BEGIN
    V_ERR := NULL;
    V_MSG := NULL;
    PROVGRON.TEST.TEST_CURSOR ( TC, V_ERR, V_MSG );
    DBMS_OUTPUT.Put_Line('V_ERR = ' || V_ERR);
    DBMS_OUTPUT.Put_Line('V_MSG = ' || V_MSG);
    -- in tc I was hoping to hava a cursor??
    FOR i IN tc
    LOOP
    DBMS_OUTPUT.PUT_LINE (i.number);
    END LOOP;
    END;
    Without the for loop (or open tc) the pl/sql will output:
    V_ERR = 0
    V_MSG = no errors
    PL/SQL procedure successfully completed.
    With anything I try with the cursor I get errors?
    What am I doing wrong?

    http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch5.htm#sthref1122

  • Stored procedure that returns a cursor (result set)

    Hi,
    We have a stored procedure that returns a cursor (result set) but when I compliled it and catalouged (introspected) it in the OBPM I got all the primitive type parameters (either IN or OUT) in the proc call except the cursor type (the result set) which is the out param of the stored proc.
    Any pointers please?
    Thanks

    Result set is of RowType and is not supported as a Stored Procedure as far as I know.
    HTH
    Sharma

  • Test a procedure which returns a sys_refcursor

    Hi all,
    Oracle 9i
    Got a simple stand alone procedure which has an input param and an output param, the second of which
    is a ref cursor.
    Can anyone tell me how I can go about testing this from within Pl/SQL (Command line)?
    CREATE OR REPLACE PROCEDURE "LOGMNR"."LM"
    (p_filename in varchar2, p_recordset OUT SYS_REFCURSOR)
    as
    begin
    begin
    dbms_output.put_line('Hello World');
    OPEN p_recordset FOR
    SELECT *
    FROM test_table;
    end;
    end LM;
    Also, and I know this is a huge long-shot. I'm going to be calling this procedure from VB6 (yes I know!), via ADODB, but I'm not
    sure what type to add for the second parameter. Anyone called an Oracle procedure with ADODB which returns a refcursor/result set?
    cmd.Parameters.Append cmd.CreateParameter("p_filename", adVarChar, adParamInput, 255, "c:\test.dat")
    cmd.Parameters.Append cmd.CreateParameter("p_recordset", *???*, adParamOutput, 6000, "")
    Regards
    Dave

    Why don't you just use sqlplus as already suggested
    Re: Test a procedure which returns a sys_refcursor
    SQL> var c refcursor
    SQL> begin
      2      open :c for
      3          select * from
      4              (
      5              select * from all_tab_comments
      6              where owner = 'SYS'
      7              order by (length(comments)) desc nulls last
      8              )
      9          where rownum <= 3;
    10  end;
    11  /
    PL/SQL procedure successfully completed.
    SQL> print c
    OWNER                          TABLE_NAME                     TABLE_TYPE  COMMENTS
    SYS                            USER_AUDIT_OBJECT              VIEW        Audit trail records for statements concerning objects, specificall
    y: table, cluster, view, index, sequence,  [public] database link, [public] synonym, procedure, trigger, rollback segment, tablespace, role,
    user
    SYS                            ALL_JAVA_DERIVATIONS           VIEW        this view maps java source objects and their derived java class ob
    jects and java resource objects  for the java class accessible to user
    SYS                            USER_JAVA_DERIVATIONS          VIEW        this view maps java source objects and their derived java class ob
    jects and java resource objects  for the java class owned by user
    SQL>* Interesting how two out of three of the wordiest comments relate to java.

  • Using XI - RFC table and an Oracle stored procedure that returns a cursor.

    I need to create an interface using XI between an RFC table and an Oracle stored procedure that returns a cursor.  We are on oarcle 9.2 and  SP12.
    My stored procedure looks something like this:
    CREATE OR REPLACE
    PROCEDURE testproc_xi2 (p_recordset1 OUT SYS_REFCURSOR,
                                             in_quoteid IN varchar2 )
    AS
    BEGIN
      OPEN p_recordset1 FOR
       SELECT  q.quote_id,
                     q.modified_by,
                     q.quote_status,
                     q.total_cost
                FROM quote q
               WHERE q.quote_id = in_quoteid
                 AND q.total_cost > 0 ; 
    END testproc_xi2 ;
    My RFC has table and  one import parameter .
    I wanted to know how to create the data type for the ref cursor? and also for the table type in the RFC?
    CAN XI handle multi rows coming from a Stored procedure? Are there any other alternative methods if this is not supported?Any pointers to this would be helpful.
    I have called a Oracle SP from an RFC before, but that interface had one input parameter going to the stored procedure from the RFC and about 6 o/p parameters coming from the Stored procedure. This works fine.
    Thanks for the help.
    Mala

    Mala,
    i dont think there is anything called an rfc table...RFC stands for remote function call. That in essence would imply you need a rfc to jdbc connection.
    yes XI can handle multiple rows cooming from the the stored procedure if you have them mapped appropriately.
    Now as to how to create the data type within xi , you need to know what fields are going to be returned and whether they are nested and then just create them as you would for an xml
    for ex
    <Details>
      <FirstName>
    <LastName>
    </Details>
    that in xi would be smthing like
    Details  type of data occurence
    FirstName type of data occurence
    LastName type of data occurence.
    Hope that helps.
    If it does dont forget the points..:-)

  • Calling a stored procedure which returns a value

    Hi Friends,
    I want to call a stored procedure which returns a value.
    Eg
    create or replace procedure xyz(a1 in varchar2, a2 in varchar2, z1 out number)
    thanks

    Hi,
    use this.
    declare
    retval number;
    begin
    abc('aaa','bbb',retval);
    dbms_output.put_line('retval is ' ||retval);
    end;
    --Basava.S                                                                                                                                                                                                                                                                                               

  • How to execute stored procedure that returns a cursor?

    How to execute a stored procedure that returns a cursor?
    Follow the code:
    CREATE OR REPLACE PROCEDURE stp_cashin_grupo
    (p_func IN VARCHAR
    ,p_cod_grup IN Integer
    ,p_des_grup IN VARCHAR
    ,p_logi IN VARCHAR
    ,p_curs_rset OUT infoc.pck_cashin_grupo.curs_rset
    IS
    BEGIN
    if p_func = '1' then
    OPEN p_curs_rset FOR
    select
    cod_grup
    ,des_grup
    ,dat_manu_grup
    ,des_logi_manu
    from infoc.tbl_cashin_grupo
    order by des_grup;
    end if;
    END stp_cashin_grupo;
    and the package:
    CREATE OR REPLACE PACKAGE pck_cashin_grupo
    AS
    TYPE curs_rset IS REF CURSOR;
    END pck_cashin_grupo;
    My question is how to execute in sql plus?
    EXEC stp_cashin_grupo('1',0,'','465990', my doubt is how to pass the cursor as return
    Thanks

    my doubt is how to pass the cursor as returnExample :
    TEST@db102 > var c1 refcursor;
    TEST@db102 > create or replace procedure ref1 (
      2     v1 in varchar2,
      3     cur1 out sys_refcursor)
      4  is
      5  begin
      6     open cur1 for 'select * from '||v1;
      7  end;
      8  /
    Procedure created.
    TEST@db102 > exec ref1('dept',:c1);
    PL/SQL procedure successfully completed.
    TEST@db102 > print c1
        DEPTNO DNAME          LOC
            10 ACCOUNTING     NEW YORK
            20 RESEARCH       DALLAS
            30 SALES          CHICAGO
            40 OPERATIONS     BOSTON
    TEST@db102 >

  • DB  Adapter Calling DB Procedure that returns a Record Type

    I am trying to call a PL/SQL procedure that returns a Record Type and a VARCHAR2 and I'm getting this error:
    <Faulthttp://schemas.xmlsoap.org/soap/envelope/>
    <faultcode>env:Server</faultcode>
    <faultstring>java.sql.SQLException: ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'MY_PROC.GET_ID' ORA-06550: line 1, column 7: PL/SQL: Statement ignored </faultstring> </Fault>
    Is there something different I need to do to handle the Record Type OUT parameter?
    Thanks.

    The adapter configuration wizard should take care of the Record Type for you. It should invoke JPublisher to create an equivalent Object type and a package containing a wrapper that will be called by the adapter runtime. The package also contains conversion functions for converting between your Record Type and the generated Object type. Maybe it would help if you posted the signature of your stored procedure (not the body).

  • Defining enum with abstract method which returns a generic type

    Is it possible to define an abstract method which returns an geneic type like below? Thanks
    public enum Type{
         A{
              public List<Integer> getData(){}
         B{
              public Set<String> getData{}
         abstract<T> T getData();
    }

    vulee wrote:
    Why not?
    List<Integer> lst = Type.A.getData();Wonder, which compiler you use. Can't be Java6:
    # javac Enums.java
    Enums.java:23: incompatible types
    found   : java.util.Collection<capture#376 of ?>
    required: java.util.List<java.lang.Integer>
                    List<Integer> data = Type.A.getData();
                                                       ^
    1 errorEdit: Unless you do it the generic way as you proposed, which actually is a phoney. Because of the T being a generic method parameter, the compiler will infer it from the type of the variable it gets assigned to. Hence, both of the following will compile:
    List<Integer> lst = Type.A.getData();
    Set<String> lst2 = Type.A.getData(); // Runtime exceptionActually, javac is telling you that giving warnings on the enum constants redefined method return types.
    Edited by: stefan.schulz on Sep 10, 2008 11:38 PM

  • Design a procedure which returns a result set of a select Query

    Hi...
    Can some one help me out with a brief design or work around for creating a stored procedure which runs a select Query and Returns a result set...
    If not a stored procedure, at least a function which makes the job simple....
    Awaiting help in this regard ........

    Hi...
    I am sorry for providing insufficient Info...
    Actually I am using Oracle 10G DB...
    I have a select Query..
    Since I am a part of team which is building a Complete Data Driven site, Even an SQL Query and a PL/SQL function body was stored in the Table itself to bring in some kind of Dynamism in the site.... But the master table was loaded with a lot of data and hence Now we decided to Store everythin in a generic package..
    I used REF CURSORS to store a result set of a simple SELECT Query.... and declaring it as an out parameter in my Procedure body so that the JAVA team can directly access the Procedure from the JAVA layer....
    Now I want to know can I do anything more efficient to carry out the above operation....

  • Calling a procedure that returns a cursor inside a procedure

    Hi,
    I have two stored procedures. They both return a cursor as output variables. On the other hand I have another stored procedure that calls these procedures and return their results again an output variable. I know that this seems quite odd to be wanting to do something like this but how can I do that?

    You can make the hack generic. Make it execute any SQL as that schema that creates the ref cursor. E.g.
    // as schema BILLY, open a huge security hole and grant access to USER1
    SQL> create or replace procedure GetTableData( tableName varchar2, refCur out sys_refcursor ) authid definer is
      2          dynamicSQL      varchar2(32767);
      3  begin
      4          dynamicSQL := 'select * from '||tableName;
      5          open refCur for dynamicSQL;
      6  end;
      7  /
    Procedure created.
    SQL>
    SQL>
    SQL> grant execute on GetTableData to USER1;
    Grant succeeded.As USER1, you can now execute SQL (and even PL/SQL) as BILLY:
    SQL> create or replace type TStrings is table of varchar2(4000);
      2  /
    Type created.
    SQL> grant execute on TStrings to BILLY;
    Grant succeeded.
    SQL> --// execute this as the caller (which will be BILLY.GetTableData)
    SQL> create or replace procedure ExecSQL( hackSQL varchar2 ) authid current_user is
      2          pragma autonomous_transaction;
      3  begin
      4          execute immediate hackSQL;
      5          commit;
      6  end;
      7  /
    Procedure created.
    SQL> --// wrap the above into something that BILLY.GetData can execute as a ref cursor
    SQL> --// and return a meaningful message as to how successful the hack was
    SQL> create or replace function PipeLineHack( hackSQL varchar2 ) return TStrings authid current_user pipelined is
      2  begin
      3          ExecSQL(  hackSQL );
      4          pipe row( 'SQL hack successful' );
      5  exception when OTHERS then
      6          pipe row( 'SQL hack faled with '||SQLERRM(SQLCODE) );
      7  end;
      8  /
    Function created.
    SQL>
    SQL> grant execute on PipeLineHack to BILLY;
    Grant succeeded.
    SQL>
    SQL> var c refcursor
    SQL> --// expected used of the GetTableData() interface
    SQL> --// we select from table BILLY.EMP
    SQL> exec BILLY.GetTableData( 'EMP', :c );
    PL/SQL procedure successfully completed.
    SQL> print c
         EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 1980/12/17 00:00:00        800          0         20
          7499 ALLEN      SALESMAN        7698 1981/02/20 00:00:00       1600        300         30
          7521 WARD       SALESMAN        7698 1981/02/22 00:00:00       1250        500         30
          7566 JONES      MANAGER         7839 1981/04/02 00:00:00       2975                    20
          7654 MARTIN     SALESMAN        7698 1981/09/28 00:00:00       1250       1400         30
          7698 BLAKE      MANAGER         7839 1981/05/01 00:00:00       2850                    30
          7782 CLARK      MANAGER         7839 1981/06/09 00:00:00       2450                    10
          7788 SCOTT      ANALYST         7566 1987/04/19 00:00:00       3000                    20
          7839 KING       PRESIDENT            1981/11/17 00:00:00       5000                    10
          7844 TURNER     SALESMAN        7698 1981/09/08 00:00:00       1500          0         30
          7876 ADAMS      CLERK           7788 1987/05/23 00:00:00       1100                    20
          7900 JAMES      CLERK           7698 1981/12/03 00:00:00        950                    30
          7902 FORD       ANALYST         7566 1981/12/03 00:00:00       3000                    20
          7934 MILLER     CLERK           7782 1982/01/23 00:00:00       1300                    10
    14 rows selected.
    SQL>
    SQL> --// getting that interface to run unexpected code - we
    SQL> --// rename BILLY.EMP table to something else
    SQL> exec BILLY.GetTableData( 'TABLE(USER1.PipeLineHack( ''alter table emp rename to emp_has_been_hacked''))', :c );
    PL/SQL procedure successfully completed.
    SQL> print c
    COLUMN_VALUE
    SQL hack successful
    SQL>

  • How to use stored procedure which returns result set in OBIEE

    Hi,
    I hav one stored procedure (one parameter) which returns a result set. Can we use this stored procedure in OBIEE? If so, how we hav to use.
    I know we hav the Evaluate function but not sure whether I can use for my SP which returns result set. Is there any other way where I can use my SP?
    Pls help me in solving this.
    Thanks

    Hi Radha,
    If you want to cache the results in the Oracle BI Server, you should check that option. When you run a query the Oracle BI Server will get its results from the cache, based on the persistence time you define. If the cache is expired, the Oracle BI Server will go to the database to get the results.
    If you want to use caching, you should enable caching in the nqsconfig.ini file.
    Cheers,
    Daan Bakboord

  • Exceedingly long time for a Procedure to return a Cursor

    Hi All,
    I have a Package with a procedure that returns a REF CURSOR. The cursor is defined with dynamic SQL. I recently changed the SQL to be bound to improve perf. When I debug, the Open runs quick, and the cursor var looks fine, but when the "End" statement for the proc is reached, it waits for a good 30 secs before terminating execution. If I specify not to load the results in a grid (Using TOAD), it terminates quickly. However, my .Net app using an OracleDataAdapter takes 30-40 secs to get the data also? There's some delay in transferring the cursor var back to the calling thread for some reason.
    Main difference in the previous proc to now:
    Old call: OPEN shoppingBagContents FOR v_sql;
    New call OPEN shoppingBagContents FOR v_sql using a, b; (a,b are bound in sql :a, :b).
    shoppingBagContents is defined as OUT ref cursor.
    Any help / ideas is greatly appreciated.
    Thanks
    Running oracle 10g
    App .Net 2.0 on XP

    Opening a cursor does just that, it opens the cursor. The query (cursor) is not processed until you attempt to fetch it. That's where the processing time comes in.
    Are you saying that the processing of the cursor (fetching it) takes longer after your changes than before?
    Can you post an example of the code you changed?
    For example, if you had dynamic SQL where your predicate never changes, you'd actually want to keep the literal (say ProcessFlag = 'Y' which will ALWAYS be part of the query).
    The only things you want to replace / bind are things that will change (or be included / not included) with repeated executions.

Maybe you are looking for