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.

Similar Messages

  • 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

  • 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                                                                                                                                                                                                                                                                                               

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

  • Calling Stored Procedure which returns single or multiple value

    Hi All Experts,
    I have written one stored procedure which is returning different
    integer values according to condition.I am calling this
    stored procedure through prepareCall() method then executeUpdate() method ,but it is always returning 1,not my desired value.
    Pl also tell me,if my stored procedure returns more than one value
    then how will i get those values in my java program?
    Pl help by writing some sample code.
    Thanx in Advance.
    Pradipto

    1) Create CallableStatement
    2) For each of returning value you have to call RegisterOutParameter()
    3) For others user setXXX() method depending on type of parameter
    4) call
    5) use vars registered through RegisterOutParameter() - all your values should be there
    Pavel

  • 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

  • Procedure which returns value

    Well! Simply I want, to write procedure which will insert or updates (is dependent from ID if ID <=0 then there is an insert otherwise updating) the information of the Student, and returns it's ID....... how I can write procedure like this???
    is this procedure correct ???
    create or replace procedure sp_InsertUpdate_T_STUDENT
    nResID out NUMBER,
    nID in NUMBER,
    vchNAME in VARCHAR2,
    vchSURNAME in VARCHAR2,
    nAGE in NUMBER,
    nCNAUTHORID in NUMBER
    as
    begin
    if nID<=0 then
    insert into T_STUDENT (NAME,SURNAME,AGE,CNAUTHORID) values (vchNAME,vchSURNAME,nAGE,nCNAUTHORID );
    else
    update T_STUDENT set NAME=vchNAME,SURNAME=vchSURNAME,AGE=nAGE,CNAUTHORID=nCNAUTHORID
    where ID=nID;
    end if;
    select ID into nResID from T_STUDENT where NAME=vchNAME and
    SURNAME=vchSURNAME and AGE=nAGE and CNAUTHORID=nCNAUTHORID;
    end;

    is this procedure correct ???Does it work?
    You might change the insert logic so that it uses a RETURNING clause to set nResID as part of the insert, instead of doing it later.

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

  • Procedure which return multiple values

    Hi
    I want to create 1 procedure which will return multiple id's and sub id's for 1 emp id.
    like
    Emp ID Id Sub Id
    100 1 1
    100 1 3
    Now I want to create a procedure where i will pass 100 and it will return as out parameter 1,1 and 1,3.
    Pls help.
    Thanks
    Regards
    Anant

    Or if you prefer a function to a procedure, you can use a pipelined function...
    CREATE OR REPLACE TYPE myrec AS OBJECT
    ( col1   VARCHAR2(10),
      col2   VARCHAR2(10)
    CREATE OR REPLACE TYPE myrectable AS TABLE OF myrec
    CREATE OR REPLACE FUNCTION pipedata(p_str IN VARCHAR2) RETURN myrectable PIPELINED IS
      v_str VARCHAR2(4000) := REPLACE(REPLACE(p_str, '('),')');
      v_obj myrec := myrec(NULL,NULL);
    BEGIN
      LOOP
        EXIT WHEN v_str IS NULL;
        v_obj.col1 := SUBSTR(v_str,1,INSTR(v_str,',')-1);
        v_str := SUBSTR(v_str,INSTR(v_str,',')+1);
        IF INSTR(v_str,',')>0 THEN
          v_obj.col2 := SUBSTR(v_str,1,INSTR(v_str,',')-1);
          v_str := SUBSTR(v_str,INSTR(v_str,',')+1);
        ELSE
          v_obj.col2 := v_str;
          v_str := NULL;
        END IF;
        PIPE ROW (v_obj);
      END LOOP;
      RETURN;
    END;
    SQL> select *
      2  from table(pipedata('(1,2),(3,4),(5,6)'));
    COL1       COL2
    1          2
    3          4
    5          6

  • How to call a procedure which returns out parameter in form personalization

    Dear All,
    I have one procedure which is having 2 parameter in and one parameter out .
    The question is how to get the parameter out in from personalization in a local or global variable?
    Thanks

    Yes.
    You can use the "forms_ddl" builtin
    See the following examples. Make sure you include the single quotes as well as the = sign in the begining.
    See http://phenix.blog.163.com/blog/static/8397219320096213953151/
    http://oracle.anilpassi.com/forms-personalizations.html
    Sandeep Gandhi

  • How to execute an Oracle stored procedure which returns many records?

    I have two synchronous scenarios XI<->PI<->JDBC, where JDBC is receiver adapter.
    Each scenario runs a different stored procedure in Oracle database.
    The first stored procedure returns only one record, the second stored procedure returns many records, which come from a cursor.
    In the first scenario I executed the stored procedure following the directions of Help SAP page and works perfectly.
    Link: [http://help.sap.com/saphelp_nw70/helpdata/en/2e/96fd3f2d14e869e10000000a155106/content.htm]
    <root>
      <StatementName5>
        <storedProcedureName action=u201DEXECUTEu201D>
          <table>realStoredProcedureName</table>
          <param1 [isInput=u201Dtrueu201D] [isOutput=true] type=SQLDatatype>val1</param1>
        </storedProcedureName>
      </StatementName5>
    <root>
    I have sought in the forums of SDN and cannot find the way to run the second stored procedure, and receive the information it returns.
    Thank you for your help.
    Rafael Rojas.

    Think It doesnt matter either cursor or result set. Try to get the response back from JDBC and see what are the fields it exactly populating.
    In Procedure you can able to find the columns selecting in Cursors. Give those columns in the DT.
    File - JDBC (Execute-- Procedure)
    To get the response
    JDBC_respose -  File
    Correct me if im wrong.
    Regards
    Ramg

  • XI calling an Oracle Stored Procedure which returns an Object to XI

    I am currently trying to call an Oracle Packaged/Procedure from XI which accepts a couple of parameters as I/O and returns an Object as one of the parameters.
    I have created the Object within the Oracle Database CREATE OR REPLACE TYPE xy_jdbc AS OBJECT
    column_name type ...etc
    CREATE OR REPLACE TYPE xy_tab_jdbc AS TABLE OF xy_jdbc;
    One of the parameters for the stored procedure is set up as this type xy_tab_jdbc this will be populated based upon one of the parameters passed into the  Package/Procedure.
    Is this possible? If it is, how do I map the returned object within XI?

    Dear Hilary,
    the JDBC adapter does not support vendor-specific or non-scalar data types.
    Workaround: Change the stored proc's signature not to use an object, but the object's fields instead.
    Regards,
    Thilo

  • Unit test, how to test a function which returns a PL/SQL table.

    I've got the following type definition:
    create or replace type method_tbl as table of varchar2(255);
    /I've got the following function
    function abc(p_param1 in varchar2) return method_tbl;When I create a unit test for this I am not able to specify what the table should contain on return of the function, all I can see is an empty table. Which is off course one of the unit tests. But I also want to test where the table that is returned contains a number of rows.
    Is there something that I'm missing?
    Typically the function is called like this:
    select * from table(abc('a'));Thanks,
    Ronald

    >
    When I create a unit test for this I am not able to specify what the table should contain on return of the function, all I can see is an empty table. Which is off course one of the unit tests. But I also want to test where the table that is returned contains a number of rows.
    Is there something that I'm missing?
    >
    You will have to create a collection that represents the result set and then compare that to the actual result set.
    Assuming tables A and B you would typically have to do
    1. SELECT * FROM A MINUS SELECT * FROM B -- what is in A that is NOT in B
    2. SELECT * FROM B MINUS SELECT * FROM A -- what is in B that is NOT in A
    You could combine those two queries into one with a UNION ALL but since the results are tables and the comparison is more complex it is common to write a function to determine the comparison result.
    Here is sample code that shows how to create an expected result collection.
    DECLARE
    expectedItemList sys.OdciVarchar2List;
    functionItemList sys.OdciVarchar2List;
    newItemList sys.OdciVarchar2List;
    expectedCount INTEGER;
    countFunctionItemList INTEGER;
    BEGIN
    expectedItemList := sys.OdciVarchar2List('car','apple','orange','banana','kiwi');
    expectedCount := 5; -- or query to count them
    functionItemList := sys.OdciVarchar2List('car','apple','orange','peanut');
    -- use your function to get the records
    -- select * from myFunctino BULK COLLECT INTO functionItemList
    IF functionItemList.count != expectedCount THEN
      DBMS_OUTPUT.PUT_LINE('Count is ' || functionItemList.count || ' but should be ' || expectedCount);
    END IF;
    END;
    Count is 4 but should be 5If the collections are the same type you can use the MULTISET operators.
    See Solomon's reply in this thread for how to use the MULTISET operators on collections.
    PLS-00306: wrong number or type of argument in call to 'MULTISET_UNION_ALL'
    See MultisetOperators in the SQL Reference doc
    http://docs.oracle.com/cd/B13789_01/server.101/b10759/operators006.htm
    >
    Multiset operators combine the results of two nested tables into a single nested table.

  • Stored procedure which returns date error

    if have a function getGmtDate in the package pa which uses a date as parameter and returns a date
    conn.Connect()
    strSQL = "pa.getGmtDate"
    P_RETURN As New OracleParameter(":pRETURN", OracleDbType.Date, ParameterDirection.ReturnValue)
    Dim P_DATE As New OracleParameter(":pDATE", OracleDbType.Date, 0, ParameterDirection.Input)
    P_DATE.Value = Now 'current date
    Dim cmd As New OracleCommand(strSQL, conn.getConnection)
    cmd.CommandType = CommandType.StoredProcedure
    cmd.Parameters.Add(P_RETURN)
    cmd.Parameters.Add(P_DATE)
    cmd.ExecuteNonQuery()
    dim returnValue as Date = P_RETURN.Value
    and the date is retrieved correct from the db, but when I want to bind the resultdate to a variable then it throws an exception:
    Cast from type 'OracleDate' to type 'Date' is not valid
    can anyone help me?

    1) Create CallableStatement
    2) For each of returning value you have to call RegisterOutParameter()
    3) For others user setXXX() method depending on type of parameter
    4) call
    5) use vars registered through RegisterOutParameter() - all your values should be there
    Pavel

  • Calling a stored procedure which returns a UDT

    Hi devs,
    Recently I've come across this requirement where I need to get a Oracle UDT returned from a stored procedure. The stored procedure I've used is described below.
    CREATE OR REPLACE PROCEDURE test_proc(param_id IN NUMBER, cust OUT CUSTOMER)
    IS
    BEGIN
    SELECT customer INTO cust from CUS_T where id=param_id;
    END;
    the type CUSTOMER has the following structure.
    CREATE OR REPLACE TYPE CUSTOMER AS OBJECT(
    id NUMBER,
    name VARCHAR2(20)
    the table "CUS_T" is of the following structure.
    CREATE TABLE CUS_T(id NUMBER, customer CUSTOMER);
    The use case I'm trying to address is that I need to retrieve the CUSTOMER object corresponding to a particular ID through a java code snippet. Here's how I'm currently trying to get it done.
    *CallableStatement cs=connection.prapareCall("{test_proc(?,?)}");*
    *cs.setInt(1,some_int);*
    *cs.registerOutParameter(2,Types.STRUCT);*
    *cs.execute();*
    *Struct result=(Struct)cs.getObject(1);*
    Although Oracle returns UDTs as SQL Structs, I'm running into the following exception while executing the aforementioned code snippet.
    *java.sql.SQLException: ORA-03115: unsupported network datatype or representation*
    Any help on this matter would be greatly appreciated.
    Cheers,
    Prabath

    Hi,
    I've been able to find the solution for this problem. The following simple code snippet
    has the done trick.
    CallableStatement ocs = connection.prepareCall("{ call testProc(?)}");
    ocs.registerOutParameter(1, Types.STRUCT,"CUSTOMER");
    ocs.execute();
    What I did there was, simply adding the UDT_NAME (the name CUSTOMER in the
    previous example) while registering the OUT parameter.
    Cheers,
    Prabath
    Edited by: 829281 on Feb 2, 2011 5:56 PM

Maybe you are looking for

  • Canon iR 5055 error specify correct ID and Password

    We have a Canon iR5055 B/W copier on our network and 2 staff members can not print to it. When they try to print, I get an error message that says they have to specify a correct ID and Passwrd Error: 15513. I have uninstalled and reinstalled the driv

  • Mounting a VMware netapp backup to retrieve deleted files

    I've got a 2012 R2 server running a managed document suite (Laserfiche) on VMware vSphere Client 5.1 and some folders on the managed document software were deleted and need to be recovered.  Therefore I need to restore\mount a netapp backup of this V

  • Add rows with vLookup

    I have a spreedsheet which is used to give estimates.  One table with colums of items and their prices.  The second table is to lookup those prices and add them to the estimate. I have used vLookup which does the job.  The problem is that you do not

  • FF.5 - Error:  FV626

    Hi Guys, I am trying to execute FF.transaction for Bradesco Bank (Brazil) and I believe the formar should be Multicash, but I got the below error message: Message no. FV626: Incorrect input file: No ; separator exists in AUSZUG.TXT format Let me know

  • What is meant portal activity report

    HI Gurus, What is the need of portal activity report. and how to create it. Thanks in Advance, Dharani