How to give ref cursor in VB procedure call

This is my Oracle Sp
CREATE OR REPLACE PROCEDURE CRD_DMAN.infy_usp_trades_by_broker_bkr
** Procedure name: CRD_DMAN.USP_TRADES_BY_BROKER
** Author's name: Infosys
** Date written: 04/11/07
** Description: Compliance Trade by Borker
** Maintenance history:
** Date Chg req# Name Remarks
** 04/11/07 Infosys Created
p_ordercursor IN OUT infy_pkg_compliance_transact.cur_compliancetrade,
p_startdate IN VARCHAR,
p_enddate IN VARCHAR,
p_fundcode IN cs_fund_config.parent_acct_cd%TYPE,
p_clientcode IN ts_order_alloc.acct_cd%TYPE,
p_brokercode IN ts_order_alloc.exec_broker%TYPE,
p_reportname IN report_log.report_name%TYPE,
p_callingapplication IN report_log.calling_application%TYPE,
p_callinguser IN report_log.calling_user%TYPE
IS
--Declaring Local Variables
v_owner VARCHAR2 (30);
v_startdate VARCHAR2 (10);
v_enddate VARCHAR2 (10);
v_rowcount NUMBER:=0;
v_logrec base_util_pkg.crd_log_record;
exp_error EXCEPTION;
v_fundcodevalue NUMBER;
BEGIN
BEGIN
/*checking if the start date and end date are null and
assigning the sysdate accordingly*/
IF (TRIM(p_startdate) IS NULL )
THEN
v_startdate := TO_CHAR (SYSDATE, 'mm/dd/yy');
ELSE
v_startdate := p_startdate;
END IF;
IF (TRIM(p_enddate) IS NULL )
THEN
v_enddate := TO_CHAR (SYSDATE, 'mm/dd/yy');
ELSE
v_enddate := p_enddate;
END IF;
/*checking if fund code is null and assigning value accordingly*/
IF TRIM (p_fundcode) IS NULL
THEN
v_fundcodevalue := 0;
ELSE
v_fundcodevalue := 1;
END IF;
/*checking if the reportname or calling user or calling
application name*/
IF (p_reportname IS NULL OR p_callinguser IS NULL
OR p_callingapplication IS NULL)
THEN
RAISE exp_error;
END IF;
END;
--opening and fetching the data into cursor
v_logrec.start_time := SYSDATE;
BEGIN
OPEN p_ordercursor
FOR
SELECT
oa.exec_broker EXEC_BROKER_CODE,
b.bkr_name          EXEC_BROKER_NAME,
oa.acct_cd CLIENT_CODE,
f.acct_name               CLIENT_NAME,
CASE WHEN (Exists (SELECT 1
                                   FROM cs_fund_broker fb
WHERE rel_typ_cd IN('P','M')
AND oa.exec_broker=fb.BKR_CD
                                   AND oa.acct_cd =fb.acct_cd))
               THEN 'Y'
ELSE 'N' END          DIRECTED_BROKER,
COUNT ( distinct o.order_id) COUNT_TICKNUM,
MAX (o.trade_date) TRADE_DATE,
SUM (oa.exec_amt)               BASE_COST,
SUM (oa.commision_amt)          TOTAL_COMMISSION,
     (SELECT ab.bkr_typ_cd FROM au_broker ab
     WHERE ab.au_change_date =(SELECT TO_TIMESTAMP(MAX(ab.au_change_date))
     FROM au_broker ab WHERE b.bkr_typ_cd != ab.bkr_typ_cd AND b.bkr_cd = ab.bkr_cd))
                              BROKER_HISTORY
FROM
ts_order o
JOIN ts_order_alloc oa ON (o.order_id = oa.order_id)
JOIN cs_broker b ON(oa.exec_broker = b.bkr_cd)
JOIN cs_fund f ON(oa.acct_cd = f.acct_cd)
WHERE
o.status = 'ACCT'
AND oa.exec_broker = CASE WHEN TRIM (p_brokercode) IS NULL
          THEN oa.exec_broker
          ELSE TRIM(p_brokercode) END
AND oa.acct_cd = CASE WHEN TRIM(p_clientcode) IS NULL
THEN oa.acct_cd
ELSE TRIM(p_clientcode) END
     AND ((0 = v_fundcodevalue) OR EXISTS (SELECT 1 FROM crd.cs_fund_config cf
          WHERE cf.parent_acct_cd =TRIM (p_fundcode)
     AND oa.acct_cd = cf.child_acct_cd))
     AND o.trade_date BETWEEN TO_DATE (v_startdate, 'mm/dd/yy')
AND TO_DATE (v_enddate, 'mm/dd/yy')
GROUP BY oa.exec_broker, b.bkr_name ,oa.acct_cd ,f.acct_name,oa.directed_broker,b.bkr_typ_cd,b.bkr_cd;
END;
BEGIN
SELECT
owner
INTO
v_owner
FROM
all_objects
WHERE
object_name = 'INFY_USP_TRADES_BY_BROKER_BKR';
v_logrec.end_time := SYSDATE;
v_logrec.user_code := v_owner;
v_logrec.input_param_values := 'INFY_USP_TRADES_BY_BROKER_BKR,'
|| v_startdate
|| ','
|| v_enddate
|| ','
|| p_fundcode
|| ','
|| p_clientcode
|| ','
|| p_brokercode;
v_logrec.report_name := p_reportname;
v_logrec.object_name := 'INFY_USP_TRADES_BY_BROKER_BKR';
v_logrec.rows_returned := v_rowcount;
v_logrec.calling_application := p_callingapplication;
v_logrec.calling_user := p_callinguser;
END;
BEGIN
--calling the procedure to insert values into the report_log table
COMMIT;
SET TRANSACTION READ WRITE;
base_util_pkg.crd_base_util_proc (v_logrec);
SET TRANSACTION READ ONLY;
END;
EXCEPTION
WHEN exp_error
THEN
DBMS_OUTPUT.put_line ('ERROR');
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('ERROR OCCURED' || SQLCODE);
DBMS_OUTPUT.put_line (SQLERRM);
END infy_usp_trades_by_broker_bkr;
END OF CRD_DMAN.USP_TRADES_BY_BROKER
This is my Pakage from where i am using ref cursor
CREATE OR REPLACE PACKAGE CRD_DMAN.infy_pkg_compliance_transact
AS
** Package name : CRD.INFY_PKG_COMPLIANCE_TRANSACTIONS
** Author's name : Infosys
** Date written : 06/11/07
** Project/System : CRD
** Description : Compliance Trades By Borker Package
** Maintenance history:
** Date Chg req# Name Remarks
** 06/11/07 CRD Infosys Created
--Defining The ComplianceTrade Record DataType
TYPE rec_compliancetrade IS RECORD (
exec_broker_code crd.ts_order_alloc.exec_broker%TYPE,
exec_broker_name crd.cs_broker.bkr_name%TYPE,
client_code crd.ts_order_alloc.acct_cd%TYPE,
client_name crd.cs_fund.acct_name%TYPE,
directed_broker crd.ts_order_alloc.directed_broker%TYPE,
count_ticknum crd.ts_order.order_id%TYPE,
trade_date crd.ts_order.trade_date%TYPE,
base_cost crd.ts_order_alloc.cur_base_mkt_val%TYPE,
total_commission crd.ts_order_alloc.commision_amt%TYPE,
broker_history     crd.au_broker.bkr_typ_cd%TYPE
--Declaring a variable of rec_auditdata data type
TYPE cur_compliancetrade IS REF CURSOR
RETURN rec_compliancetrade;
END infy_pkg_compliance_transact;
END OF CRD.INFY_PKG_COMPLIANCE_TRANSACTIONS
How to call this SP from VB code with ref cursor parameter?

I'm fairly sure that's not possible, since there's nothing in the ODBC spec to allow for ref cursors. The driver has built in support to check for ref cursors that are returned via a stored procedure call, but there's nothing built into the driver to pass one IN. Since a ref cursor can't be constructed on the client side, you'd have to have some sort of structure that allowed you to reference the ref cursor directly in order to be able to pass one back to the database.
Since you're using VB.NET anyway, the better solution is probably just to use ODP.NET instead, which DOES allow you to reference a ref cursor directly, and there are samples that install with ODP.NET that show you how to do that.
Greg

Similar Messages

  • Ref cursors for stored procedure

    Hi every body,
    I am new one,I am in learning stage.
    My java developer was ask me give set of results.
    i am using in my code sys_refcursor, my questions are.
    SQL> create or replace procedure sysref(p_out out sys_refcursor) is
    2 begin
    3 open p_out for select empno,ename from employee;
    4 end;
    5 /
    I am using the procedure like above procedure.
    1) How to use ref cursors in procedure. what is the main use.
    2) How to close ref cursors in procedure.If it is need.
    3) How to use exceptions in procedures for ref cursors.
    Give me one example with complete structure.
    Please help me
    new one
    Edited by: subba on Aug 19, 2010 12:08 AM
    Edited by: subba on Aug 19, 2010 12:09 AM

    subba wrote:
    1) How to use ref cursors in procedure. what is the main use.All SQL in Oracle are parsed as cursors in the Shared Pool. The client code (be that PL/SQL or Visual Basic or Java) gets a handle or reference to this SQL cursor on the server.
    Using this handle, the client can fetch rows using the cursor (the cursor is like a program - the executable binary version of the source SQL code).
    Clients implement their interfaces with this SQL cursor handle in different ways. PL/SQL alone supports:
    - implicit cursor handles
    - explicit cursor handles
    - DBMS_SQL cursor handles
    - reference cursor handles
    Why so many? Different tools for different jobs. Each has its pros and cons and each is suited for specific (and different) types of problems.
    A ref cursor is special in that PL/SQL can pass this SQL cursor reference handle to an external client to use - like Java.
    Why?
    The basic concept is that of abstraction. Removing the complexities of SQL and the database design and SQL optimisation from the Java code. Instead, Java calls a PL/SQL proc. This proc creates the SQL cursor, and uses a reference cursor variable to store the SQL cursor handle. It can then pass this to Java. This means that the entire SQL is encapsulated in the PL/SQL proc. We can now modify it, optimise it, support data models changes in the database via the PL/SQL proc... all without even having to recompile the Java code that makes the call and consumes the ref cursor the PL/SQL proc gives it.
    2) How to close ref cursors in procedure.If it is need.Yes. A very important factor - well spotted.
    As PL/SQL can pass ref cursors to external clients. it does not automatically close these cursors. It does not know when the client has consumed the cursor. It will only close it when the cursor is still open, when the Oracle server session is terminated.
    So it is important that the client (Java in this case) closes the cursor when done. If not, the cursor will remain open, will continue to occupy server resources... and if the client opens more and more of these cursors, the server process will run out of resources.
    Cursor leakage by Java developers are common - and can simply be avoided by closing the cursor once the Java code has consumed it.
    3) How to use exceptions in procedures for ref cursors.No. Why? Why would you want to deal with the exception in a PL/SQL proc? The Java code wants to open that cursor. It knows why. It knows what to do when that cursor fails or is empty. It interacts with the user. How is the PL./SQL proc, whose only function is to construct the SQL and pass the cursor handle to Java, to know any of this?
    Exceptions in this regard should typically be handled in Java. Not in PL/SQL.
    Of course, if that PL/SQL proc has parameters, it also needs to validate these and it needs to raise application exceptions to inform the Java caller when these parameters are invalid.
    But actually catching exception in this case... does not make much sense. As what can the PL/SQL do about the error when it is a "server" and Java is the "client"?
    It is like saying that the Oracle Server should handle all exceptions when TOAD is used and incorrect SQL is passed to it. How does it make sense for Oracle to process SQL errors and the TOAD client not getting any results from a wrong SQL and not knowing that there was even an error with that SQL?

  • How to get values from a ref cursor in a procedure

    I have a procedure that returns a cursor type of values, but I cannot get the values.
    I got error when on how to define the output cursor. Could someone please look at the code and tell me how to correct it?
    Thanks in advance.
    ******************************8
    --This is the package
    CREATE OR REPLACE PACKAGE Test_SECURITY2 as
    type T_RoleTest is ref cursor;
    Procedure P_GetUserRole(userID in number, p_cur out T_RoleTest);
    end;
    CREATE OR REPLACE PACKAGE BODY Test_SECURITY2 as
    Procedure P_GetUserRole(userID in number, p_cur out T_RoleTest) as
    begin
         open p_cur for
         select PREO_Role.ROLE_ID,PREO_Role.ROLE_NAME
         from preorder.PREO_Role, preorder.PREO_User_Role
         where PREO_Role.Role_id = PREO_User_Role.Role_id
         and PREO_User_Role.user_id = userid;
    end;
    end;
    --This is the testing code. I got error here
    SQL> set serveroutput on;
    SQL> execute dbms_output.enable;
    PL/SQL procedure successfully completed.
    SQL> declare
    2 type T_RoleTest is ref cursor;
    3 V_UserRole is ref cursor; --how to define the output cursor
    4 v_userId number := 42;
    5 V_Role_Id number;
    6 v_Role_name varchar2(20);
    7 begin
    8 Test_SECURITY2.P_GetUserRole(v_userId, V_UserRole);
    9
    10 open V_UserRole;
    11 loop
    12 fetch V_UserRole into V_Role_Id, v_Role_name;
    13
    14 EXIT WHEN V_UserRole%NOTFOUND;
    15 dbms_output.put_line('RoleID'||v_Role_ID);
    16 dbms_output.put_line('Rolename'||v_Role_name);
    17
    18 end loop;
    19
    20 end;
    21 /
    V_UserRole is ref cursor;
    ERROR at line 3:
    ORA-06550: line 3, column 13:
    PLS-00103: Encountered the symbol "IS" when expecting one of the following:
    constant exception <an identifier>

    declare
      type T_RoleTest is ref cursor;
      v_UserRole T_RoleTest;or just:
    declare
      v_UserRole  Test_Security2.T_RoleTest;And, if you are on 9i or later, you can just use the built-in sys_refcursor type.

  • How return parameter ref Cursor from procedure using dynamic SQL?

    I sorry, but i very need help.
    I using Oracle 8.0.6
    I need to return parameter of type ref Cursor from procedure.
    create or replace package PlanExp is
    type cursortype is ref cursor;
    procedure ShowPlan (cursorparam out
    cursortype.............);
    end PlanExp;
    create or replace package body PlanExp is
    procedure ShowPlan (cursorparam out cursortype,
    .............) Is
    sql_str varchar2(1000);
    sql_str_select varchar2(100);
    sql_str_from varchar2(100);
    sql_str_where varchar2(500);
    Return_Code integer;
    Num_Rows integer;
    cur_id_sel integer;
    tSum_Plan DBMS_SQL.NUMBER_TABLE;
    tSum_Plan_Ch DBMS_SQL.NUMBER_TABLE;
    tSum_Plan_Day DBMS_SQL.NUMBER_TABLE;
    begin
    /* calculating string variables ........... /*
    sql_str := 'select ' || sql_str_select ||
    'from ' || sql_str_from ||
    'where ' || sql_str_where ||
    'group by ' || sql_str_select;
    cur_id_sel := dbms_sql.open_cursor;
    dbms_sql.parse(cur_id_sel, sql_str, dbms_sql.native);
    dbms_sql.define_array(cur_id_sel, 1, tSum_Plan, 20, 1);
    dbms_sql.define_array(cur_id_sel, 2, tSum_Plan_Ch, 20, 1);
    dbms_sql.define_array(cur_id_sel, 3, tSum_Plan_Day, 20, 1);
    Return_Code := dbms_sql.execute(cur_id_sel);
    delete from TEMP_SHOWPLAN;
    Loop
    Num_Rows := dbms_sql.Fetch_Rows(cur_id_sel);
    dbms_sql.column_value(cur_id_sel, 1, tSum_Plan);
    dbms_sql.column_value(cur_id_sel, 2, tSum_Plan_Ch);
    dbms_sql.column_value(cur_id_sel, 3, tSum_Plan_Day);
    if Num_Rows = 0 then
    exit;
    end if;
    Exit When Num_Rows < 20;
    End Loop;
    dbms_sql.close_cursor(cur_id_sel);
    end;
    end PlanExp;
    How return cursor (cursorparam) from 3 dbms_sql.column_value-s ?

    I am using Oracle 8.1.7, so I don't know if this will work in
    8.0.6 or not:
    SQL> CREATE TABLE test
      2    (col1                    NUMBER,
      3     col2                    NUMBER,
      4     col3                    NUMBER)
      5  /
    Table created.
    SQL> INSERT INTO test
      2  VALUES (1,1,1)
      3  /
    1 row created.
    SQL> INSERT INTO test
      2  VALUES (2,2,2)
      3  /
    1 row created.
    SQL> INSERT INTO test
      2  VALUES (3,3,3)
      3  /
    1 row created.
    SQL> CREATE TABLE temp_showplan
      2    (tSum_Plan               NUMBER,
      3     tSum_Plan_Ch            NUMBER,
      4     tSum_Plan_Day           NUMBER)
      5  /
    Table created.
    SQL> EDIT planexp
    CREATE OR REPLACE PACKAGE PlanExp
    IS
      TYPE CursorType IS REF CURSOR;
      PROCEDURE ShowPlan
        (cursorparam    IN OUT CursorType,
         sql_str_select IN     VARCHAR2,
         sql_str_from   IN     VARCHAR2,
         sql_str_where  IN     VARCHAR2);
    END PlanExp;
    CREATE OR REPLACE PACKAGE BODY PlanExp
    IS
      PROCEDURE ShowPlan
        (cursorparam    IN OUT CursorType,
         sql_str_select IN     VARCHAR2,
         sql_str_from   IN     VARCHAR2,
         sql_str_where  IN     VARCHAR2)
      IS
        sql_str                VARCHAR2 (1000);
        cur_id_sel             INTEGER;
        return_code            INTEGER;
      BEGIN
        DELETE FROM temp_showplan;
        sql_str := 'INSERT INTO   temp_showplan '
               || ' SELECT '   || sql_str_select
               || ' FROM '     || sql_str_from
               || ' WHERE '    || sql_str_where;
        cur_id_sel := DBMS_SQL.OPEN_CURSOR;
        DBMS_SQL.PARSE (cur_id_sel, sql_str, DBMS_SQL.NATIVE);
        return_code := DBMS_SQL.EXECUTE (cur_id_sel);
        DBMS_SQL.CLOSE_CURSOR (cur_id_sel);
        OPEN cursorparam FOR SELECT * FROM temp_showplan;
      END ShowPlan;
    END PlanExp;
    SQL> START planexp
    Package created.
    Package body created.
    SQL> VARIABLE g_ref REFCURSOR
    SQL> EXEC PlanExp.ShowPlan (:g_ref, 'col1, col2,
    col3', 'test', ' 1 = 1 ')
    PL/SQL procedure successfully completed.
    SQL> PRINT g_ref
    TSUM_PLAN TSUM_PLAN_CH TSUM_PLAN_DAY
             1            1             1
             2            2             2
             3            3             3

  • Open ref cursor in a procedure

    Hi
    I have a procedure which has 3 input parameters and 1 REF CURSOR type OUT parameter.
      In the body of the procedure a select query is dynamically being created, and just before the end of the procedure the REF CURSOR is opened for SELECT(dynamic) query
    For Ex: Create or replace procedure proc_name(a in number,b in number,c in number,RETVAL OUT REF CURSOR) as
    decalre
      strQry varchar2(3000);
    begin
       -- strQry is select query built dynamically
    OPEN RETVAL for strQry;
    end proc_name;
    This procedure is being called by a java application. My question is what the open cursor statement is doing in the procedure?
    Any ideas? Thanks!
    greddy

    Hi,
    As i know, for example if we want to generate a report for some particular records in our project.consider we are using java as front end and oracle as backend. ok. In that case we need to bring the data from backend to front end ,for that in backend (oracle) we can write procedure to perform this task using ref cursors.
    Note: ref cursor will provide the most efficient way in bringing the records from back end to front end.
    Create or replace procedure proc_name(a in number,b in number,c in number,RETVAL OUT REF CURSOR) as
    decalre
    strQry varchar2(3000);
    begin
    -- strQry is select query built dynamically
    --if we are using dynamic query, we can filter out the records using id or name or date
    once we did, we need to pass the values to calling enviroment, since we declared the ref cursor as out parameter, we can use the ref cursor to pass the values to calling enviroment. Since we are using ref cursor we need to open the cursor for that dynamic query.
    OPEN RETVAL for strQry;
    end proc_name;
    hope this information is some what helpful. if you got any details regarding this please post it..
    thanks.

  • Importing function with multiple ref cursors in Stored Procedure of Oracle 12c database Using EF6

    Hi Good day!
    I can able to import function for stored procedure of oracle db and able to add the complex type and get the output but i tried to import the procedure which having two ref cursors and unable to retrieve the column information. Only able to retrieve the
    columns of first ref cursor.  Please help me to get the result of two ref cursors which acting as out parameters.

    Having to ref cursors return mutiple recordsets in an Oracle package is like haveng two resultsets return from a MS SQL Server sparc.
    The link may point you in the right direction.
    http://www.codeproject.com/Articles/675933/Returning-Multiple-Result-Sets-from-an-Entity-Fram

  • UPDATE via REF CURSORS in STORED PROCEDURE

    Hello,
    Can I Get REF CURSOR as INPUT in STORED PROCEDURE and make an UPDATE according the input data ?
    Thanks

    Having to ref cursors return mutiple recordsets in an Oracle package is like haveng two resultsets return from a MS SQL Server sparc.
    The link may point you in the right direction.
    http://www.codeproject.com/Articles/675933/Returning-Multiple-Result-Sets-from-an-Entity-Fram

  • How to use REF cursor with toplink

    Hi,
    I have a stored proc has a out variable which is a REF CURSOR.
    How to read my cursor with toplink?

    I have got it. Here is the solution.
              UnitOfWork uow= dbSession.acquireUnitOfWork();
              StoredProcedureCall call = new StoredProcedureCall();
              call.setProcedureName("smart.getCompanyStruct");
              call.addNamedArgument("xnrid");
              call.useNamedCursorOutputAsResultSet("cpy");
              DataReadQuery query = new DataReadQuery();
              query.setCall(call);
              Vector parameters = new Vector();
              query.addArgument("xnrid");
              parameters.add(new Long(5009L));
              Vector obj = (Vector) uow.executeQuery(query, parameters);     
    Vector contains result ser of the cursor
    Gurcan

  • How to write REF-CURSOR Query in Oracle Reports

    Hello Guys!!
    I have a form in which you can select regions/divisions/locations etc by the use of check boxes. And the selected values will be inserted into a table, and based on the selected values of the table the report is run.
    The issue I have is with the query inside the Oracle reports(attached to this file).
    The query works fine until the last two EXISTS conditions.
    IF a region exists In the table report_param then it works fine but if there are no divisions in it , then the query returns no values, which is not correct.
    Someone has advised me to use a ref-cursor query inside reports tool, which I am not aware off. So, anykind of suggestions or advises are welcome. Please let me know about it as it is very urgent issue for me. Anykind of help would be greatly
    appreciated.
    Thanks,
    Vishal
    -------------------------------------------------------Query in Oracle Reports---------------------------------------------------------
    select c.key_segment, p.supplier_id,
    decode(:in_col_nm, 'BRAND',nvl(p.product_brand,'<Unknown Brand>'), 'PLN',nvl(p.product_legal_name,'<Unknown Legal Name>')) COL_NM,
    sum(a.ext_price) sales_dols,
    sum(comp_allow_pkg.get_comp_allow_stddiv(a.control_loc_id, a.product_id, a.sold_to_customer_id,
    a.doc_dt, a.ext_price, a.units)) cust_reb_dols,
    sum(a.units) units,
    sum(a.ext_cost) cost_dols
    from sales a, key_segment_plns c, product p, rep_wrtr_dw_cust h
    where a.doc_dt between :in_start_dt and :in_end_dt
    and a.customer_oc = h.control_loc_id
    and a.sold_to_customer_id = h.sold_to_cust_id
    and a.ship_to_customer_id = h.ship_to_cust_id
    and ((:in_dg_cd = 'B' and h.dealer_grower_cd in ('D','G')) or h.dealer_grower_cd = :in_dg_cd)
    and a.product_id = p.product_id
    and p.product_gl_class_cd = 'CHEM'
    and p.product_legal_name = c.product_legal_name
    and c.key_segment in ('GLYPHOSATE','PLANT HEALTH/RUST FUNGICIDES','PYRETHROIDS','STROBI FUNGICIDES')--&IN_KEY_SEGMENTS
    -- and (:in_oc = 'ALL' or (a.control_loc_id in (select control_loc from control_loc_comb_ocs where control_loc_comb = :in_oc)))
    -- SALES DATA FILTERS TO MATCH ACCUM_SALES_DG_MV
    and a.sale_type_cd in ('02','08')
    and a.document_type_cd in ('I','C','D')
    and (substr(a.product_id,-1) in ('0','1') OR nvl(upper(trim(p.product_brand)),'X') = 'TECH FEE')
    and a.units <> 0
    and a.unit_cost <> 0
    and a.unit_price <> 0
    -- NEW FILTERS ADDED 9/11/07: LOCATION(BRANCH), BUSINESS TYPE, RSM/ASM/REP
    and ((:in_loc = 'ALL') or (nvl(a.warehouse_id,'<blank>') in (SELECT param_value
    FROM report_param
    WHERE report_id = :IN_REPORT_ID
    AND session_id= :IN_SESSION_ID
    AND USER_ID = :IN_USER_ID
    AND param_name='LOCATION_TYPE')))
    and ((:in_uhs_ag = 'ALL') or (:in_uhs_ag = 'NA' and p.product_uhs_ag != 'A') or (p.product_uhs_ag = :in_uhs_ag))
    and ((:in_sales_rep = 'ALL') or (nvl(a.territory_id,'<blank>') in (SELECT param_value
    FROM report_param
    WHERE report_id = :IN_REPORT_ID
    AND session_id= :IN_SESSION_ID
    AND USER_ID = :IN_USER_ID
    AND param_name='SALES_REP_TYPE')))
    and EXISTS
    (SELECT '1'
    FROM locations l, report_param rp
    WHERE rp.report_id = :IN_REPORT_ID
    AND rp.session_id= :IN_SESSION_ID
    AND rp.user_id = :IN_USER_ID
    AND rp.param_value = l.region
    AND rp.param_name = 'REGION_TYPE'
    AND a.warehouse_id = L.ARS_LOCATION)
    and EXISTS
    (SELECT '1'
    FROM locations l, report_param rp
    WHERE rp.report_id = :IN_REPORT_ID
    AND rp.session_id= :IN_SESSION_ID
    AND rp.user_id = :IN_USER_ID
    AND rp.param_value = l.region
    AND rp.param_name = 'DIVISION_TYPE'
    AND a.warehouse_id = L.ARS_LOCATION)
    group by c.key_segment, P.supplier_id,
    decode(:in_col_nm, 'BRAND',nvl(p.product_brand,'<Unknown Brand>'), 'PLN',nvl(p.product_legal_name,'<Unknown Legal Name>'))

    Hi,
    I need your help to create a report using Ref-Cursor. please see the below thread
    Report using ref cursor or dynamic Sql

  • Reports 3.0, Ref Cursor from stored procedure

    I have a problem trying to use Ref Cursor as datasource (i.e.
    Ref Cursor Query) in Reports 3.0
    I have created a stored package with a function which returns
    Ref Cursor.
    That function just opens the cursor and returns it to the
    calling module.
    Reports recognizes returned cursor - it creates a group for that
    query, with all columns, than I built
    a layout model - everything is OK on that stage.
    During the execution of that report (from previewer or using
    Reports Runtime) I got an error message like that:
    REP-0065 Virtual Memory System Error
    REP-0200 Cannot allocate enough memory cavaa22
    Error's description does not correspond the reality :) - there
    is enough virtual & physical memory according to
    Task Manager information.
    So, that does not work when this package is stored one.
    When I create the package on the client side - in Reports -
    everything works just fine.
    Cursor is opened with a very simple query, selecting records
    from the very simple table having only one record.
    There is no code written which closes that cursor or fetches the
    records.
    Client platform: WinNT 4.0 SP3
    Oracle Reports: 3.0.5.8.0
    Oracle Server: Oracle8 8.0.5.0.0 (and I tried also on Oracle7
    7.3.4.3.0)
    Thanx.
    null

    Sara,
    GTT (Global Temporary Tables) in Oracle work a different way compared to SQL Server and Informix. There you can create temporary tables on the fly and drop them on the fly.
    Here you should (note, you don't have to, but, best practice says that you should) create the table using the syntax...
    create global temporary table.....
    Once you create it, even though it looks like persistent table, it's not. It will have it's own individual data PER SESSION . You have two types of GTTs:
    ON COMMIT PRESERVE ROWS and ON COMMIT DELETE ROWS (they work in slightly different way).
    Look up GTTs here:
    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14231/tables.htm#sthref2213
    HTH,
    Rahul

  • REF CURSOR problem .. function call from select

    Hello,
    I am still on the search for a way to call a function from with in a select statement.
    I've done it in SQL*Plus like this and it works.
    SELECT name, f_format(name) FROM user WHERE id = 12;
    This returns first the unformatted (raw) version of the stored value for name and then the formmtted version of the stored value of name.
    Since multiple names will be returned I need to user a REF CURSOR (cursor variable). The above select statement does not work from within the OPEN . .FOR clause necessary for a REF CURSOR.
    What can I do instead? My goal is to return multiple records of formatted names.
    null

    I have declared the reference cursor as a weak one. Thank you for clarifying that though. I was wondering if it made a difference. Here is a simple package that shows you what I am trying to do. I will include the errors at the bottom. Please have a look and let me know what you think is wrong.
    /*--------- PL/SQL ------------*/
    CREATE OR REPLACE PACKAGE test_refcur AS
    PROCEDURE decrypt (
    i_string IN VARCHAR2
    ,o_string OUT VARCHAR2
    TYPE PwdCurTyp IS REF CURSOR;
    PROCEDURE get_pwd_info (
    i_user_id IN NUMBER
    ,io_pwd_cv IN OUT PwdCurTyp
    END test_refcur;
    CREATE OR REPLACE PACKAGE BODY test_refcur AS
    FUNCTION f_decrypt (
    i_string IN VARCHAR2
    ) RETURN VARCHAR2 IS
    l_string VARCHAR2(64);
    l_string_dec VARCHAR2(32);
    BEGIN
    l_string := i_string;
    dbms_obfuscation_toolkit.DESDecrypt(
    input_string => l_string
    ,key_string =>'12345678'
    ,decrypted_string=> l_string_dec );
    RETURN l_string_dec;
    END f_decrypt;
    PROCEDURE decrypt (
    i_string IN VARCHAR2
    ,o_string OUT VARCHAR2
    ) IS
    BEGIN
    o_string := f_decrypt(i_string);
    END decrypt;
    PROCEDURE get_pwd_info (
    i_user_id IN NUMBER
    ,io_pwd_cv IN OUT PwdCurTyp
    ) IS
    BEGIN
    OPEN io_pwd_cv FOR
    SELECT
    label
    ,f_decrypt(user_name_text) AS dec_user_name
    ,f_decrypt(text) AS dec_pwd
    FROM
    code_pwd
    WHERE
    id = i_user_id;
    END get_pwd_info;
    END test_refcur;
    /*--------- SQL*Plus -----------*/
    Warning: Package Body created with compilation errors.
    SHOW ERRORSErrors for PACKAGE BODY TEST_REFCUR:
    LINE/COL ERROR
    28/13 PL/SQL: SQL Statement ignored
    30/18 PLS-00231: function 'F_DECRYPT' may not be used in SQL
    Then I made the SELECT statement dynamic.
    OPEN io_pwd_cv FOR
    'SELECT label, f_decrypt(user_name_text) AS dec_user_name, f_decrypt(text) AS dec_pwd FROM code_pwd WHERE id = i_user_id';
    It compiled fine.
    Package body created.
    So then I tried to do the following. .
    SET AUTOPRINT ON
    SET SERVEROUTPUT ON
    VARIABLE cv REFCURSOR
    EXECUTE test_refcur.get_pwd_info(18, :cv)begin test_refcur.get_pwd_info(18, :cv); end;
    ERROR at line 1:
    ORA-00904: invalid column name
    ORA-06512: at "K.TEST_REFCUR", line 27
    ORA-06512: at line 1
    If I change the SELECT statement to the following, this is what I get. .
    OPEN io_pwd_cv FOR
    SELECT label
    -- ,f_decrypt(user_name_text) AS dec_user_name
    -- ,f_decrypt(text) AS dec_pwd
    FROM code_pwd
    WHERE id = i_user_id;
    SET AUTOPRINT ON
    SET SERVEROUTPUT ON
    VARIABLE cv REFCURSOR
    EXECUTE test_refcur.get_pwd_info(18, :cv)PL/SQL procedure successfully completed.
    LABEL
    Development Server
    That tells me that at least something is working. How can I get everything else to work?

  • Need Help: Using Ref Cursor in ProC to call a function within a Package

    I'm calling a function within a package that is returning a REF CURSOR.
    As per the Oracle Pro*C Programmer's Guide, I did the following:
    1) declared my cursor with a: EXEC SQL BEGIN DECLARE SECTION and declared the cursor as: SQL_CURSOR my_cursor;
    2) I allocated the cursor as: EXEC SQL ALLOCATE :my_cursor;
    3) Via a EXEC SQL.....END-EXEC begin block
    I called the package function and assign the return value to my cursor
    e.g. my_cursor := package.function(:host1, :host2);
    Now, the only difference between my code and the example given in the Pro*C Programmer's Guide is that the example calls a PROCEDURE within a package that passes back the REF CURSOR as an OUT host variable.
    Whereas, since I am calling a function, the function ASSIGNS the return REF CURSOR in the return value.
    If I say my_cursor := package.function(:host1, :host2); I get a message stating, "PLS-00201: identifier MY_CURSOR" must be declared"
    If I say :my_cursor := package.function(:host1, :host2); I get a message stating, "ORA-01480: trailing null missing from STR bind value"
    I just want to call a package function and assign the return value to a REF CURSOR variable. There must be a way of doing this. I can do this easily in standard PL/SQL. How can this be done in Pro*C ???
    Thanks for any help.

    Folks, I figured it out. For those who may face this problem in the future you may want to take note for future reference.
    Oracle does not allow you to assign the return value of a REF CURSOR from a FUNCTION ( not Procedure - - there is a difference) directly to a host variable. This is the case even if that host variable is declared a CURSOR variable.
    The trick is as follows: Declare the REF CURSOR within the PL/SQL BEGIN Block, using the TYPE statement, that will contain the call to the package function. On the call, you then assign the return REF CURSOR value that the function is returning to your REF CURSOR variable declared in the DECLARE section of the EXEC SQL .... END-EXEC PL/SQL Block.
    THEN, assign the REF CURSOR variable that was populated from the function call to your HOST cursor varaible. Then fetch this HOST Cursor variable into your Host record structure variable. Then you can deference individual fields as need be within your C or C++ code.
    I hope this will help someone facing a deadline crunch. Happy computing !

  • How to give grant permission on packaged procedure

    Hi ,
    This is Ramesh  what is my requirement is i want give permission packaged procedure that means i given permission  only procedure not entire package it is possible or  not? if yes then why
    given example

    Hi,
    You  can't  give grant to package.function or procedure.
    You  can do that following way.
    SQL> create or replace package p is function f return number; end p;
      2  /
    Package created.
    SQL> create or replace function f return number is begin return p.f; end;
      2  /
    Function created.
    SQL> grant execute on f to scott;
    Grant succeeded.
    Regards
    Mahir M. Quluzade

  • Ora-01001 in procedures with ref cursor parameter after upgrade to 11.1.0.7

    Hi,
    after upgrading from 11.1.0.6.0 to 11.1.0.7.0, I get ora-01001 in procedure calls which have a ref cursor as an out parameter.
    Even a new 11.1.0.7 instance throws this error. My OS is Linux SLES10SP2.
    Please see atched sample code:
    CREATE OR REPLACE PACKAGE test1_pck
    IS
    PROCEDURE run1; -- OK on 11.1.0.6; fails on 11.1.0.7
    PROCEDURE run2; -- OK on 11.1.0.6; OK on 11.1.0.7
    END test1_pck;
    CREATE OR REPLACE PACKAGE BODY test1_pck
    IS
    TYPE t_rec IS RECORD(col dual.dummy%TYPE);
    TYPE t_cur IS REF CURSOR RETURN t_rec;
    PROCEDURE foo1(p_cur OUT t_cur)
    IS
    v_sql VARCHAR2(255) := 'BEGIN OPEN :1 FOR SELECT dummy FROM dual; END;';
    BEGIN
    EXECUTE IMMEDIATE v_sql USING p_cur;
    END foo1;
    PROCEDURE foo2
    IS
    v_sql VARCHAR2(255) := 'BEGIN OPEN :1 FOR SELECT dummy FROM dual; END;';
    v_cur t_cur;
    v_rec t_rec;
    BEGIN
    EXECUTE IMMEDIATE v_sql USING v_cur;
    LOOP
    FETCH v_cur INTO v_rec;
    EXIT WHEN v_cur%NOTFOUND;
    CASE v_rec.col
    WHEN 'X' THEN dbms_output.put_line('success');
    ELSE dbms_output.put_line('error');
    END CASE;
    END LOOP;
    END foo2;
    PROCEDURE run1
    IS
    v_cur t_cur;
    v_rec t_rec;
    BEGIN
    foo1(v_cur);
    LOOP
    FETCH v_cur INTO v_rec;
    EXIT WHEN v_cur%NOTFOUND;
    CASE v_rec.col
    WHEN 'X' THEN dbms_output.put_line('success');
    ELSE dbms_output.put_line('error');
    END CASE;
    END LOOP;
    END run1;
    PROCEDURE run2
    IS
    BEGIN
    foo2;
    END run2;
    END test1_pck;
    Thanks for any hints.
    Regards Frank

    Hi Max,
    the referenced thread discusses a .Net problem. A lot of layers are involved their. My problem is a very basic problem. You get this error even if you run the test in a sql session on the server.
    It would be a great help for me
    a) if someone could test this package on a 11.1.0.7 database
    b) if someone could test this package on a 11.2 database (is it fixed in Release2?)
    c) if someone could give me hints how I could modify the procedure to make it usable for 11.1.0.7
    (I already tried a lot e.g. EXECUTE IMMEDIATE v_sql USING OUT p_cur;
    Thank you
    Frank

  • How to return a table to ref cursor?

    My client has created a package stored procedure that takes in 2 parameters of VarChar2 and an out parameter which is a table
    Following is the package header
    CREATE OR REPLACE PACKAGE "PKG_TRAVEL_NEW_SUND" IS
    ---RECORD TYPE DELARATION
    TYPE DIRECT_ALT_REC IS RECORD (SERVICE_NO CBG_DISTANCE_FARE.SERVICE_NO%TYPE,
    DISTANCE CBG_DISTANCE_FARE.DISTANCE%TYPE,
    CASH_FARE_AC CBG_DISTANCE_FARE.CASH_FARE_AC%TYPE,
    CASH_FARE_NON_AC CBG_DISTANCE_FARE.CASH_FARE_NON_AC%TYPE,
    CARD_FARE_AC CBG_DISTANCE_FARE.CARD_FARE_AC%TYPE,
    CARD_FARE_NON_AC CBG_DISTANCE_FARE.CARD_FARE_NON_AC%TYPE,
    EZLINK_FARE_AC CBG_DISTANCE_FARE.EZLINK_FARE_AC%TYPE,
    EZLINK_FARE_NON_AC CBG_DISTANCE_FARE.EZLINK_FARE_NON_AC%TYPE,
    AVG_RUNTIME CBG_DISTANCE_FARE.AVG_RUNTIME%TYPE,
    ALTERNATIVE_NO CBG_DIRECT_ALT.ALTERNATIVE_NO%TYPE,
    MAX_FREQ_AM CBG_SVC.MAX_FREQ_AM%TYPE,
    MIN_FREQ_AM CBG_SVC.MIN_FREQ_AM%TYPE,
    ADVANTAGE_CODE CBG_DIRECT_ALT.ADVANTAGE_CODE%TYPE,
    DIST_FARE_CODE_1 CBG_DISTANCE_FARE.DIST_FARE_CODE%TYPE,
    DIST_FARE_CODE_2 CBG_DISTANCE_FARE.DIST_FARE_CODE%TYPE,
    DIST_FARE_CODE_3 CBG_DISTANCE_FARE.DIST_FARE_CODE%TYPE,
    FROM_STOP_CODE CBG_DISTANCE_FARE.FROM_STOP_CODE%TYPE,
    TO_STOP_CODE CBG_DISTANCE_FARE.TO_STOP_CODE%TYPE,
    MIN_TIME CBG_DIRECT_ALT.MIN_TIME%TYPE,
    MIN_FARE CBG_DIRECT_ALT.MIN_FARE%TYPE,
                                            ACT_FARE CBG_DIRECT_ALT.MIN_FARE%TYPE,
    TRAVEL_TYPE VARCHAR2(4),
    TRANSFER_INFO VARCHAR2(1),
    END_TRANSFER_INFO VARCHAR2(1));
    --TABLE  TYPE DECLARATION
    TYPE BUS_INFO_TAB IS TABLE OF DIRECT_ALT_REC INDEX BY BINARY_INTEGER;
    -- CURSOR TYPE DECLARATION
    TYPE TEMP_REC_STRUCT1 IS RECORD (
    RECORD_POSITION BINARY_INTEGER,
    DIST_FARE_CODE1 CBG_DISTANCE_FARE.DIST_FARE_CODE%TYPE,
    DIST_FARE_CODE2 CBG_DISTANCE_FARE.DIST_FARE_CODE%TYPE,
    DIST_FARE_CODE3 CBG_DISTANCE_FARE.DIST_FARE_CODE%TYPE,
    ADVANTAGE_CODE CBG_DIRECT_ALT.ADVANTAGE_CODE%TYPE,
    MINIMUM_FARE CBG_DIRECT_ALT.MIN_FARE%TYPE,
    MINIMUM_TIME CBG_DIRECT_ALT.MIN_TIME%TYPE,
    TRAVEL_TYPE VARCHAR2(4) );
    TYPE TEMP_TAB_STRUCT1 IS TABLE OF TEMP_REC_STRUCT1 INDEX BY BINARY_INTEGER;
    TEMP_TABLE1 BUS_INFO_TAB;
    G_RESULTSET_INDEX BINARY_INTEGER := 0 ;
    G_TOT_RECS_IN_TAB1 BINARY_INTEGER := 0 ;
    TYPE BUS_INFO_CUR IS REF CURSOR RETURN DIRECT_ALT_REC;
    ---PROCEDURE INSIDE THE PACKAGE
    --- PROCEDURE TO SELECT THE RECORDS
    PROCEDURE SEL_DIRECT_ALT(P_FROM_STOP_CODE IN VARCHAR2,
    P_TO_STOP_CODE IN VARCHAR2,
    RESULTSET IN OUT BUS_INFO_TAB);
    I'm using ODP.net and here is my code
    string storedprocedure = "PKG_TRAVEL_NEW_SUND.SEL_DIRECT_ALT";
    //PKG_TRAVEL_NEW_SUND
    //CBG003_XP_SP_TEST1
    ArrayList retlist = new ArrayList();
    OracleConnection curr_conn = this.GetOpenConnection();
    OracleCommand cmd = curr_conn.CreateCommand();
    cmd = new OracleCommand(storedprocedure, curr_conn);
    cmd.CommandType = CommandType.StoredProcedure;
    // input parameter
    OracleParameter param1 = new OracleParameter();
    OracleParameter param2 = new OracleParameter();
    param1.ParameterName = "start_code";
    param2.ParameterName = "end_code";
    param1.OracleDbType = OracleDbType.Varchar2;
    param2.OracleDbType = OracleDbType.Varchar2;
    param1.Direction = ParameterDirection.Input;
    param2.Direction = ParameterDirection.Input;
    param1.Size = 5;
    param2.Size = 5;
    param1.Value = start_codes;
    param2.Value = end_codes;     
    cmd.Parameters.Add(param1);
    cmd.Parameters.Add(param2);
    OracleParameter outputparam3 = new OracleParameter();
    outputparam3.Direction = ParameterDirection.InputOutput;
    outputparam3.ParameterName = "output";
    outputparam3.OracleDbType = OracleDbType.RefCursor;
    // output type
    cmd.Parameters.Add(outputparam3);
    cmd.ExecuteNonQuery();
    At this point, when i execute Query, i get the message telling me that i could have the wrong number or type arguments for the procedure.
    I've looked thru countless examples saying i should use a RefCursor, but what else could i miss out?

    Hi,
    This is from Metalink NOTE.219191.1 How to return the values in a PL/SQL table to a ref cursor
    Hope it helps,
    Greg
    This document gives details with an example on how to pass the values
    in a PL/SQL table to a ref cursor.
    SCOPE & APPLICATION
    This document is useful for developers who are familiar with SQL & PL/SQL
    How to return the values in a PL/SQL table to a ref cursor
    This can be done by using a SQL Object type instead of a PL/SQL table.
    Here is an example.
    SQL> create or replace type ObjectType as object
    2 ( x int,
    3 y date,
    4 z varchar2(25)
    5 );
    6 /
    Type created.
    SQL> create or replace type TabType as table of ObjectType;
    2 /
    Type created.
    SQL> create or replace
    2 function demo_function( p_start_row in number,
    3 p_end_row in number )
    4 return TabType
    5 as
    6 l_data TabType := TabType();
    7 l_cnt number default 0;
    8 begin
    9 for x in ( select * from emp order by sal desc )
    10 loop
    11 l_cnt := l_cnt + 1;
    12 if ( l_cnt >= p_start_row )
    13 then
    14 l_data.extend;
    15 l_data(l_data.count) :=
    16 objectType( x.empno,
    17 x.hiredate,
    18 x.ename );
    19 end if;
    20 exit when l_cnt = p_end_row;
    21 end loop;
    22
    23 return l_data;
    24 end;
    25 /
    Function created.
    SQL> select *
    2 from the ( select cast( demo_function(3,7) as TabType )
    3 from dual ) a;
    X Y Z
    7902 03-DEC-81 FORD
    7566 02-APR-81 JONES
    7698 01-MAY-81 BLAKE
    7782 09-JUN-81 CLARK
    7844 08-SEP-81 TURNER
    By using a SQL object type, the table can be selected easily.
    SQL> create or replace package demo_pkg
    2 as
    3 type rc is ref cursor;
    4
    5 procedure p( p_cursor in out rc );
    6 end;
    7 /
    Package created.
    SQL> create or replace package body demo_pkg
    2 as
    3
    4 procedure p( P_cursor in out rc )
    5 is
    6 l_data TabType := TabType();
    7 begin
    8 for i in 1 .. 3 loop
    9 l_data.extend;
    10 l_data(i) :=
    11 ObjectType( i, sysdate+i, i || ' data');
    12 end loop;
    13
    14 open p_cursor for
    15 select *
    16 from TABLE ( cast ( l_data as TabType) );
    17 end;
    18
    19 end;
    20 /
    Package body created.
    SQL> set autoprint on
    SQL> variable x refcursor
    SQL> exec demo_pkg.p(:x)
    PL/SQL procedure successfully completed.
    X Y Z
    1 15-NOV-02 1 data
    2 16-NOV-02 2 data
    3 17-NOV-02 3 data

Maybe you are looking for

  • Can position be created with out creating Job..

    Hi Experts, A simple question but quite complicated. Can position be created with out creating the job. ( yes it will give the warning and create). Here my actual question comes, what is the need of creating the Job. when we can create position witho

  • IPhone 6 plus - screen not rotating when waking up from sleep

    I just got a 6 Plus and I'm having issues with the screen rotation. It seems to be reproducible and I have the view set to standard and I have tried a factory reset. If I have the phone in portrait mode and put it to sleep. That mode seems to stick.

  • How to get the workitem at runtime

    Hi I have a web dynpro application from where a workflow will be started based on an event. I want to retrieve the workitem ID. How to retrive it? As per the Forums answers, I am currently using SAP_WAPI_WORKITEMS_TO_OBJECT function module to get the

  • Why are my floats not working?

    Hi! Once again, I'm puzzled! Here I have two examples: http://www.doktorwear.com/test/tuotteet.htm http://www.doktorwear.com/test/tavalliset.htm On the first one, the floats for the divs that contain the images are working great. But on the second on

  • Cnet will not load properly

    I'm running FFox 4.0 I have adblock and script blocker installed Whenever I try to open Cnet.com the page loads without frames, its broken down into paragraph form and I have no images displayed. I have allowed the entire page with the script blocker