Procedure to take inpot data set and return result set

Hi all,
I have a situation where there will be one "standard" set of data (source_data below) and I will need to get information on results for certain groups of clients (client_data being an example). As straight SQL this would be very easy (see below) -- real world problem is a little more complicated. However, what I would like to do is set up a procedure so that I can pass it my variable client data and it will spit back out a data set the same as the output from the given SQL.
A pointer in the right direction would be appreciated. If I could "pass the client data" as a string containing a SQL query, that would be even better, e.g.
GetResults('select client_id,min(whatever_date) from some_client_data where .....',MyOutputRefCursor?)
create table source_data
(client_id integer,
tdate date,
amount number(6,2));
create table client_data
(client_id integer,
critical_date date);
insert into source_data values(1,to_date('20090104','yyyymmdd'),1000);
insert into source_data values(1,to_date('20100104','yyyymmdd'),2000);
insert into source_data values(1,to_date('20110104','yyyymmdd'),3000);
insert into source_data values(1,to_date('20120104','yyyymmdd'),4000);
insert into source_data values(2,to_date('20090104','yyyymmdd'),5000);
insert into source_data values(2,to_date('20090604','yyyymmdd'),1000);
insert into source_data values(2,to_date('20100104','yyyymmdd'),2000);
insert into source_data values(3,to_date('20091004','yyyymmdd'),3000);
insert into source_data values(3,to_date('20091104','yyyymmdd'),4000);
insert into source_data values(4,to_date('20090104','yyyymmdd'),5000);
insert into source_data values(4,to_date('20090604','yyyymmdd'),2000);
insert into client_data values(1,to_date('20110104','yyyymmdd'));
insert into client_data values(2,to_date('20090604','yyyymmdd'));
select c.client_id,
  sum(CASE WHEN tdate < critical_date then amount else null end) used_before,
  sum(CASE WHEN tdate >= critical_date then amount else null end) used_after
from source_data s
inner join client_data c on s.client_id = c.client_id
GROUP BY c.client_id;Thanks,
Jon

JonWat wrote:
I have a situation where there will be one "standard" set of data (source_data below) and I will need to get information on results for certain groups of clients > (client_data being an example). As straight SQL this would be very easy (see below) -- real world problem is a little more complicated. Can you give a more accurate representation of the real world problem?
A pointer in the right direction would be appreciated. If I could "pass the client data" as a string containing a SQL query, that would be even better, e.g.Passing a query as as string for execution is rarely the correct approach. This approach won't scale and most likely will result in maintenance and security problems.
If you can update your post to have a more accurate representation of the problem you are trying to solve you'll probably get an acceptable answer. Other than that all I can suggest is that you need to rethink the approach a bit. For example, if you know you need to filter out a set of data to join to your SOURCE_DATA table, why couldn't you do that inside the procedure?
SELECT c.client_id
     , SUM
       ( CASE
         WHEN tdate < critical_date
         THEN amount
         END
       ) AS used_before
    ,  SUM
       ( CASE
         WHEN tdate >= critical_date
         THEN amount
         END
       ) AS used_after
FROM   source_data s
JOIN   ( SELECT client_id
              , MIN(<date column>) AS critical_date
         FROM   client_data
         WHERE  <where clause>
         GROUP BY client_id
       ) c on s.client_id = c.client_id
GROUP BY c.client_id;

Similar Messages

  • Store procedure which get list of values separated by semicolon and return result set as a string semicolon separated string

    Hello,
    I am trying to make stored procedure in what i am getting i_group_id  as a list of groups seprated by semicoln like 1,2,14,17,23.
    And i want list of emails based on that group. And result set will be as a list of emails seprated by semicolon.
    If you know how to install that in stored procedure please help me. Appreciate your help.
    Thanks.
    PROCEDURE get_groups_email(i_group_id    IN VARCHAR2,
                               x_group_email_dtl_cur OUT resultcur)
    IS
    x_group_email VARCHAR2(4000):=NULL;
    BEGIN                           
       FOR i IN (SELECT   TRIM(emp.email) email
                   FROM   ems.employee emp,
                          ems.groups_employee egrp
                  WHERE   egrp.group_id IN (i_group_id)
                    AND   emp.person_id = egrp.person_id) LOOP
        x_group_email:= x_group_email || i.email ||';';
      END LOOP;
      x_group_email := RTRIM(x_group_email,';');
       OPEN x_group_email_dtl_cur FOR 
         SELECT   x_group_email
           FROM   DUAL; 
    DBMS_OUTPUT.PUT_LINE('x_group_email:' || x_group_email);                                       
    END get_groups_email;
    PROCEDURE get_groups_email(i_group_id    IN VARCHAR2,
                               x_group_email_dtl_cur OUT resultcur)
    IS
    x_group_email VARCHAR2(4000):=NULL;
    BEGIN                           
       FOR i IN (SELECT   TRIM(emp.email) email
                   FROM   ems.employee emp,
                          ems.groups_employee egrp
                  WHERE   egrp.group_id IN (i_group_id)
                    AND   emp.person_id = egrp.person_id) LOOP
        x_group_email:= x_group_email || i.email ||';';
      END LOOP;
      x_group_email := RTRIM(x_group_email,';');
       OPEN x_group_email_dtl_cur FOR 
         SELECT   x_group_email
           FROM   DUAL; 
    DBMS_OUTPUT.PUT_LINE('x_group_email:' || x_group_email);                                       
    END get_groups_email;

    1013527 wrote:
    I am using Oracle 9.7.2. Not 11g.
    No Database at hand to provide a working example.
    So use http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:73830657104020 to split your list into rows.
    Join that to your table of e-mail addresses
    then take a look at http://www.sqlsnippets.com/en/topic-11787.html maybe chosing http://www.sqlsnippets.com/en/topic-12087.html
    and you're done.
    Regards
    Etbin
    something to play with (still NOT TESTED!)
    with
    e_mails as
    (select 1 user_id,'alpha' || chr(64) || 'domain.eu' e_mail from dual union all
    select 2,'beta' || chr(64) || 'domain.eu' from dual union all
    select 3,'gamma' || chr(64) || 'domain.eu' from dual union all
    select 4,'delta' || chr(64) || 'domain.eu' from dual union all
    select 5,'epsilon' || chr(64) || 'domain.eu' from dual union all
    select 6,'zeta' || chr(64) || 'domain.eu' from dual union all
    select 7,'eta' || chr(64) || 'domain.eu' from dual union all
    select 8,'theta' || chr(64) || 'domain.eu' from dual union all
    select 9,'iota' || chr(64) || 'domain.eu' from dual union all
    select 10,'kappa' || chr(64) || 'domain.eu' from dual union all
    select 11,'lambda' || chr(64) || 'domain.eu' from dual union all
    select 12,'mu' || chr(64) || 'domain.eu' from dual union all
    select 13,'nu' || chr(64) || 'domain.eu' from dual union all
    select 14,'xi' || chr(64) || 'domain.eu' from dual union all
    select 15,'omicron' || chr(64) || 'domain.eu' from dual union all
    select 16,'pi' || chr(64) || 'domain.eu' from dual union all
    select 17,'rho' || chr(64) || 'domain.eu' from dual union all
    select 18,'sigma' || chr(64) || 'domain.eu' from dual union all
    select 19,'tau' || chr(64) || 'domain.eu' from dual union all
    select 20,'upsilon' || chr(64) || 'domain.eu' from dual union all
    select 21,'phi' || chr(64) || 'domain.eu' from dual union all
    select 22,'chi' || chr(64) || 'domain.eu' from dual union all
    select 23,'psi' || chr(64) || 'domain.eu' from dual union all
    select 24,'omega' || chr(64) || 'domain.eu' from dual
    groups as
    (select 1 g_id,'1,15,21,17' members from dual union all
    select 2,'23,10,3,20,7,23,15,9' from dual union all
    select 3,'3,4,5,6,7,8' from dual union all
    select 4,'23,24,15,16,7,18' from dual
    select g_id,
           substr(sys_connect_by_path(e_mail,';'),2) e_mail_list
      from (select g.g_id,
                   e.e_mail,
                   row_number() over (partition by g.g_id order by e.user_id) rn
              from e_mails e,
                   groups g
             where instr(','||g.members||',',','||to_char(e.user_id)||',') > 0
               and instr(','||:group_list||',',','||to_char(g.g_id)||',') > 0
    where connect_by_isleaf = 1
    start with rn = 1
    connect by rn = prior rn + 1
            and g_id = prior g_id
    Message was edited by: Etbin provided a small example

  • Store procedure which get list of values separated by semicolon and return result set as a string semicolon separated strin

    Hello,
    I am trying to make stored procedure in what i am getting i_group_id  as a list of groups seprated by semicoln like 1,2,14,17,23.
    And i want list of emails based on that group. And result set will be as a list of emails seprated by semicolon.
    Can anybody please help me for that. Thanks in advance.
    PROCEDURE get_groups_email(i_group_id    IN VARCHAR2,
                               x_group_email_dtl_cur OUT resultcur)
    IS
    x_group_email VARCHAR2(4000):=NULL;
    BEGIN                            
       FOR i IN (SELECT   TRIM(emp.email) email
                   FROM   ems.employee emp,
                          ems.groups_employee egrp
                  WHERE   egrp.group_id IN (i_group_id)
                    AND   emp.person_id = egrp.person_id) LOOP
        x_group_email:= x_group_email || i.email ||';';
      END LOOP;
      x_group_email := RTRIM(x_group_email,';');
       OPEN x_group_email_dtl_cur FOR  
         SELECT   x_group_email
           FROM   DUAL;  
    DBMS_OUTPUT.PUT_LINE('x_group_email:' || x_group_email);                                        
    END get_groups_email;
    PROCEDURE get_groups_email(i_group_id    IN VARCHAR2,
                               x_group_email_dtl_cur OUT resultcur)
    IS
    x_group_email VARCHAR2(4000):=NULL;
    BEGIN                            
       FOR i IN (SELECT   TRIM(emp.email) email
                   FROM   ems.employee emp,
                          ems.groups_employee egrp
                  WHERE   egrp.group_id IN (i_group_id)
                    AND   emp.person_id = egrp.person_id) LOOP
        x_group_email:= x_group_email || i.email ||';';
      END LOOP;
      x_group_email := RTRIM(x_group_email,';');
       OPEN x_group_email_dtl_cur FOR  
         SELECT   x_group_email
           FROM   DUAL;  
    DBMS_OUTPUT.PUT_LINE('x_group_email:' || x_group_email);                                        
    END get_groups_email;

    >
    Can anybody please help me for that
    >
    Not in this forum they can't. This forum, as the title says, is for SQL Developer questions only.
    Please mark this question ANSWERED and repost it in the SQL and PL/SQL forum
    https://forums.oracle.com/community/developer/english/oracle_database/sql_and_pl_sql

  • Query database and return result set to cells.

    hello all i have vsto solution im building im trying to put together a generic query text box for my end user the only problem is that it appears to be that with oracle data access when you do a query you must pass all the values to a variable.
    Sub Orcl()
            Dim oradb As String = "Data Source=(DESCRIPTION=(ADDRESS_LIST=" _
                       + "(ADDRESS=(PROTOCOL=TCP)(HOST=xxx)(PORT=1521)))" _
                       + "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=xxx)));" _
                       + "User Id=xx;Password=xx;"
             Dim conn As New Oracle.DataAccess.Client.OracleConnection(oradb) ' Visual Basic
            conn.Open()
            Query = select * from fabinvh
            Dim cmd As New Oracle.DataAccess.Client.OracleCommand
            cmd = conn.CreateCommand()
            cmd.Connection = conn
            cmd.CommandText = Query
            Dim dr As Oracle.DataAccess.Client.OracleDataReader = cmd.ExecuteReader()
            While dr.Read()
                Globals.ThisAddIn.Application.ActiveCell.Value = (dr.Item(1))''' HOW DO I CHANGE HERE TO JUST BRING IN ALL THE COLUMNS AND HEADERS?
                Globals.ThisAddIn.Application.ActiveCell.Offset(1, 0).Select()
            End While
            dr.Dispose()
            cmd.Dispose()
            conn.Dispose()
        End Subthanks in advance im able to do this with oo4o rather easily but I'm tryint go learn more of the odp.net oracle data access and learning is pretty slow right now.

    ok I think im getting closer to my answer i believe i need to use the
    GetValues. property. does anyone have an example on how to use this i keep getting errors when i try it.

  • 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

  • What is the difference between "create set" and "create dynamic set"?

    What is the difference between  "create set" and "create dynamic set"?
    we have a complete cube ready for production that was tested and working without any issues in non-r2. we found that some "create set" assignments don't work in R2. But when changed to from  "create set" to "create dynamic set"?
    they are working, However, not sure how it will impact other areas of the cube.

    Thanks YuliaKlimov, I can reproduce this issue, but I cannot explain the different behaviors between SSAS 2008 and 2008R2. As a workaround,
    could you try to use dynamic set or create statics set but with fixed member for example:
    CREATE 
    SET CURRENTCUBE.[Prior Month] AS
    [Date].[Date Key].&[20050723].PrevMember
    , DISPLAY_FOLDER = 'Relative Period Sets';
    Personally, I think your set is dynamic set, because the currentmember is changed base on current selection. You can also submit this issue
    on below official link to get confirmation from Product Group:
     https://connect.microsoft.com/SQLServer/
    Thanks,
    Raymond
    Raymond Li - MSFT

  • I have problem with my wifi in 4 S, i cant connect to any wifi itried resetting network setting and reset all setting but the result was the same, its only keeps searching for wifi and cant find any, itried to use OTHER but also didnt work.please help me

    i have problem with my wifi in 4 S, i cant connect to any wifi itried resetting network setting and reset all setting but the result was the same, its only keeps searching for wifi and cant find any, itried to use OTHER but also didnt work.please help me???

    If Join was on then your home wi-fi must be set to Non-Broadcast.  If you did not set this up (maybe your provider did) then you will need to find the Network Name they used, and any password they used.  The SSID is Security Set ID and to see more try http://en.wikipedia.org/wiki/SSID .  Basically it is the name used to identify your router/network.  A lot of times the installer will leave it set as LinkSys, or Broadcom or whatever the manufacturer set it as for default.  Your best bet is to get whoever installed it to walk you through how they set it up, giving you id's and passwords so you can get in.  HOWEVER, if you are not comfortable with this (if you set security wrong, etc.) you would be well ahead of the game to hire a local computer tech (networking) to get this working for you.  You can also contact the vendor of your router and get help (if it is still in warranty), or at least get copies of the manuals as pdf files.  Sorry I can't give you more help, I hope this gives you an idea where to go from here to find more.

  • Issue with the functions "add matching sets" and "modify matching sets"

    Hi,
    Though 'None' access permission is set for the functions 'Add Matching Sets' and 'Modify Matching Sets', they are accessible.
    Is this a bug with the tool? or am I missing something?
    Thanks in advance,
    Madan

    sorry, missed the version details.
    I'm using MDM 5.5 SP6.

  • UNION ALL / UNION in returning result set

    I cannot find an official Oracle doc states that
    select * from table_1
    UNION ALL
    select * from table_2;
    will list the result from table_1 first, like:
    <result set from table_1>
    <result set from table_2>
    But it seems this is the way. If remove "ALL", it will not quarentee the result set of table_1 will come before the result set of table_2 because of the sorting.
    Could someone offer an answer? Thanks.
    Zac

    two comments...
    1) Without the code (and a perfect understanding of it), it may be very difficult to create a case where the result is different from what you usually find. We can expect more powerful use of union all (with Parallel Query, because the optimizer does not examine all the different permutations or whatever) may behave differently from what you guess
    2) It can (and, of course, will) change in a future release because of new algorithms. There are well known (for example aggregate=sort) things that have changed with things like HASH based algorithms. Unless you want your code to provide wrong results because a patch has changed a "supposed" behaviour, this is probably a good practice to tell what you want in your SQL Query (and order by = sort)
    I think I read Thomas Kyte saying : "Whatever you can say about Oracle Database, it is probably true. What is difficult is finding in which version it is the case ! If it is not... wait for the next release" (I'm sorry if he didn't say that... he could have)
    I know I didn't answer your question but it is just a 2 cents comment. Best Regards,
    Gregory

  • [urgent] oracle character set and national character set !!(dictionary)

    Hi. everyone.
    What is the oracle dictionary that contains information of
    oracle character set and national character set?
    I checked v$database, but there was not the information.
    It seems that there are some differences between "nls_* " init parameters
    and the database character set.
    "Alter database backup controlfile to trace" gave me the character set of db,
    but I would like to know whether there are oracle dictionary regarding them.
    Thanks in advance. Have a nice day.
    Best Regards.

    I found the dictionary which contains the information of character set and
    natiional character set of database.
    select * from nls_database_parameters
    where parameter like '%CHARACTERSET';
    Thanks for reading.
    Have a good day.
    Best Regards.

  • Calling a Stored Procedure with a result set and returned parms

    I am calling a stored procedure from a Brio report. The stored procedure returns a result set, but also passes back some parameters. I am getting a message that states that the DBMS cannot find the SP with the same footprint. Besides the result set, the SP returns 3 out parameters: (Integer, char(60), char(40)). Is there something special I need to do in Brio to format the out parameters to be passed back from the SP.
    Thanks,
    Roland

    Did you try just declaring the vars?
    untested
    declare
      myCur SYS_REFCURSOR;
      myRaw RAW(4);
      BEGIN
        test (0, 0, myRaw, sysdate, myCur);
      END;

  • Returning result set from procedure out parameter, display with anon block

    I'm trying to do something pretty simple (I think it should be simple at least). I want to use a pl/sql procedure to return a result set in an OUT parameter. If I run this code by itself (in the given anonymous block at the end, without trying to display any results), toad says that the PL/SQL procedure successfully completed.
    How can I display the results from this procedure? I am assuming that the result set should be stored in the O_RETURN_REDEEM_DTL, but how can I get anything out of it?
    I have this package with the following procedure:
    /* FUNCTION - REDEEM_DTL_READ                          */
         PROCEDURE REDEEM_DTL_READ(
              ZL_DIVN_NBR_IN     IN     REDEEM_DTL.ZL_DIVN_NBR%TYPE,
              GREG_DATE_IN     IN     REDEEM_DTL.GREG_DATE%TYPE,
              ZL_STORE_NBR_IN     IN     REDEEM_DTL.ZL_STORE_NBR%TYPE,
              REGISTER_NBR_IN     IN     REDEEM_DTL.REGISTER_NBR%TYPE,
              TRANS_NBR_IN     IN     REDEEM_DTL.TRANS_NBR%TYPE,
              O_RETURN_REDEEM_DTL OUT REDEEM_DTL_TYPE,
              o_rtrn_cd       OUT NUMBER,
              o_err_cd        OUT NUMBER,
              o_err_msg       OUT VARCHAR2
         IS
         BEGIN
              o_rtrn_cd := 0;
              o_err_msg := ' ';
              o_err_cd := 0;
              --OPEN REDEEM_DTL_READ_CUR(ZL_DIVN_NBR_IN, GREG_DATE_IN, ZL_STORE_NBR_IN, REGISTER_NBR_IN, TRANS_NBR_IN);
              OPEN O_RETURN_REDEEM_DTL FOR SELECT * FROM REDEEM_DTL;
    --           LOOP
    --                FETCH REDEEM_DTL_READ_CUR INTO O_RETURN_REDEEM_DTL;
    --                EXIT WHEN REDEEM_DTL_READ_CUR%NOTFOUND;
    --           END LOOP;
    --           CLOSE REDEEM_DTL_READ_CUR;
         EXCEPTION
          WHEN OTHERS
          THEN
               o_rtrn_cd := 7;
                 o_err_msg := SUBSTR (SQLERRM, 1, 100);
                 o_err_cd  := SQLCODE;
         END REDEEM_DTL_READ;and call it in an anonymous block with:
    DECLARE
      ZL_DIVN_NBR_IN NUMBER;
      GREG_DATE_IN DATE;
      ZL_STORE_NBR_IN NUMBER;
      REGISTER_NBR_IN NUMBER;
      TRANS_NBR_IN NUMBER;
      O_RETURN_REDEEM_DTL PSAPP.CY_SALESPOSTING.REDEEM_DTL_TYPE;
      O_RETURN_REDEEM_DTL_OUT PSAPP.CY_SALESPOSTING.REDEEM_DTL_READ_CUR%rowtype;
      O_RTRN_CD NUMBER;
      O_ERR_CD NUMBER;
      O_ERR_MSG VARCHAR2(200);
    BEGIN
      ZL_DIVN_NBR_IN := 71;
      GREG_DATE_IN := TO_DATE('07/21/2008', 'MM/DD/YYYY');
      ZL_STORE_NBR_IN := 39;
      REGISTER_NBR_IN := 1;
      TRANS_NBR_IN := 129;
      -- O_RETURN_REDEEM_DTL := NULL;  Modify the code to initialize this parameter
      O_RTRN_CD := NULL;
      O_ERR_CD := NULL;
      O_ERR_MSG := NULL;
      PSAPP.CY_SALESPOSTING.REDEEM_DTL_READ ( ZL_DIVN_NBR_IN, GREG_DATE_IN, ZL_STORE_NBR_IN,
    REGISTER_NBR_IN, TRANS_NBR_IN, O_RETURN_REDEEM_DTL, O_RTRN_CD, O_ERR_CD, O_ERR_MSG );
      FOR item IN O_RETURN_REDEEM_DTL
      LOOP
        DBMS_OUTPUT.PUT_LINE('ZL_DIVN_NBR = ' || item.ZL_DIVN_NBR);
      END LOOP;
    END; And end up with an error:
    ORA-06550: line 25, column 15:
    PLS-00221: 'O_RETURN_REDEEM_DTL' is not a procedure or is undefined
    ORA-06550: line 25, column 3:
    PL/SQL: Statement ignoredMessage was edited by:
    user607908

    Aha, I knew I forgot something!
    I actually had it defined as a REF CURSOR in PSAPP.CY_SALESPOSTING package spec:
    TYPE REDEEM_DTL_TYPE IS REF CURSOR;since I wasn't sure what to make it.
    Cursor used in procedure:
    CURSOR REDEEM_DTL_READ_CUR (
      zl_divn_nbr_in IN NUMBER,
      greg_date_in IN DATE,
      zl_store_nbr_in IN NUMBER,
      register_nbr_in IN NUMBER,
      trans_nbr_in IN NUMBER)
    IS
    SELECT ZL_DIVN_NBR, GREG_DATE, ZL_STORE_NBR, REGISTER_NBR, TRANS_NBR, PAYMENT_TYP_NBR
    FROM REDEEM_DTL
    WHERE ZL_DIVN_NBR = zl_divn_nbr_in AND GREG_DATE = greg_date_in AND
       ZL_STORE_NBR = zl_store_nbr_in AND REGISTER_NBR = register_nbr_in AND
       TRANS_NBR = trans_nbr_in;Updated code:
    /* PROCEDURE - REDEEM_DTL_READ                          */
         PROCEDURE REDEEM_DTL_READ(
              ZL_DIVN_NBR_IN     IN     REDEEM_DTL.ZL_DIVN_NBR%TYPE,
              GREG_DATE_IN     IN     REDEEM_DTL.GREG_DATE%TYPE,
              ZL_STORE_NBR_IN     IN     REDEEM_DTL.ZL_STORE_NBR%TYPE,
              REGISTER_NBR_IN     IN     REDEEM_DTL.REGISTER_NBR%TYPE,
              TRANS_NBR_IN     IN     REDEEM_DTL.TRANS_NBR%TYPE,
              O_RETURN_REDEEM_DTL OUT REDEEM_DTL_TYPE,
              o_rtrn_cd       OUT NUMBER,
              o_err_cd        OUT NUMBER,
              o_err_msg       OUT VARCHAR2
         IS
         BEGIN
              o_rtrn_cd := 0;
              o_err_msg := ' ';
              o_err_cd := 0;
              OPEN REDEEM_DTL_READ_CUR(ZL_DIVN_NBR_IN, GREG_DATE_IN, ZL_STORE_NBR_IN,
                   REGISTER_NBR_IN, TRANS_NBR_IN);
              --OPEN O_RETURN_REDEEM_DTL FOR SELECT * FROM REDEEM_DTL;
              LOOP
                  FETCH REDEEM_DTL_READ_CUR INTO O_RETURN_REDEEM_DTL;
                   EXIT WHEN REDEEM_DTL_READ_CUR%NOTFOUND;
                   DBMS_OUTPUT.PUT_LINE('ZL_DIVN_NBR = ' || O_RETURN_REDEEM_DTL.ZL_DIVN_NBR);
                END LOOP;
               CLOSE REDEEM_DTL_READ_CUR;
    --           LOOP
    --                FETCH REDEEM_DTL_READ_CUR INTO O_RETURN_REDEEM_DTL;
    --                EXIT WHEN REDEEM_DTL_READ_CUR%NOTFOUND;
    --           END LOOP;
    --           CLOSE REDEEM_DTL_READ_CUR;
         EXCEPTION
          WHEN OTHERS
          THEN
               o_rtrn_cd := 7;
                 o_err_msg := SUBSTR (SQLERRM, 1, 100);
                 o_err_cd  := SQLCODE;
         END REDEEM_DTL_READ;the updated anon block:
    DECLARE
      ZL_DIVN_NBR_IN NUMBER;
      GREG_DATE_IN DATE;
      ZL_STORE_NBR_IN NUMBER;
      REGISTER_NBR_IN NUMBER;
      TRANS_NBR_IN NUMBER;
      O_RETURN_REDEEM_DTL PSAPP.CY_SALESPOSTING.REDEEM_DTL_TYPE;
      O_RTRN_CD NUMBER;
      O_ERR_CD NUMBER;
      O_ERR_MSG VARCHAR2(200);
    BEGIN
      ZL_DIVN_NBR_IN := 71;
      GREG_DATE_IN := TO_DATE('07/21/2008', 'MM/DD/YYYY');
      ZL_STORE_NBR_IN := 39;
      REGISTER_NBR_IN := 1;
      TRANS_NBR_IN := 129;
      -- O_RETURN_REDEEM_DTL := NULL;  Modify the code to initialize this parameter
      O_RTRN_CD := NULL;
      O_ERR_CD := NULL;
      O_ERR_MSG := NULL;
      PSAPP.CY_SALESPOSTING.REDEEM_DTL_READ ( ZL_DIVN_NBR_IN, GREG_DATE_IN, ZL_STORE_NBR_IN,
         REGISTER_NBR_IN, TRANS_NBR_IN, O_RETURN_REDEEM_DTL, O_RTRN_CD, O_ERR_CD, O_ERR_MSG );
      FOR item IN 1..O_RETURN_REDEEM_DTL.COUNT
      LOOP
        DBMS_OUTPUT.PUT_LINE('ZL_DIVN_NBR = ' || O_RETURN_REDEEM_DTL(item).ZL_DIVN_NBR);
      END LOOP;
    END;and the new error:
    ORA-06550: line 25, column 38:
    PLS-00487: Invalid reference to variable 'O_RETURN_REDEEM_DTL'
    ORA-06550: line 25, column 3:
    PL/SQL: Statement ignoredAlso, it would be nice if the forums would put a box around code so that it would be easy to
    distinguish between what is supposed to be code and what should be regular text...
    Message was edited by:
    user607908

  • Returning result sets from PL/SQL procedure to client app.

    I was wondering if its possible in Oracle PL/SQL to DECLARE, OPEN a cursor and exit
    the procedure without closing the cursor
    and then retrieve the resultset from
    the client.
    Pl let me know..
    null

    Yes, you need to use one OUT parameter in your PL/SQL procedure
    to pass the cursor variable to
    Java code. You can also return that as a return variable of
    PL/SQL function. Get the cursor variable from the resultset using
    Types.CURSOR data type and then proceed as usual.
    Enrique (guest) wrote:
    : Thank you Rajib for your prompt reply. I have been programming
    a
    : lot in Transact SQL( MSSQL ), but I am new to Oracle and I need
    : to migrate MSSQL procedures to Oracle. I will try to use the
    : refCursors. One more question, how do I pass the cursors back?
    : With OUT parameters? In MSSQL you do not need to specify OUT
    : parameters if you are returning a result set.
    : Once Again,
    : Thank you
    : Rajib (guest) wrote:
    : : You can return a variable of refcursor type from your PL/SQL
    : : procedure (PL/SQL 2.3 or higher) to Java code. Oracle JDBC
    has
    : a
    : : refcursor data type. Now you can use this cursor as a
    : resultset.
    : : Enrique (guest) wrote:
    : : : Hi All,
    : : : I am trying to write some store procedures( PL/SQL )
    : : that
    : : : will select rows from my tables, and then pass then back to
    : my
    : : : JDBC application as result sets....Does anyone know how can
    I
    : : do
    : : : that? Do I need to use output parameters? Or Return
    : functions?
    : : : Any help or hint wourl be be gladly appreciate it.
    : : : Enrique
    : : : Thank you.
    null

  • CR XI Pass parameters to stored procedure but don't filter returned result set

    I have created a stored procedure that takes a begin date and an end date. The returned resultset is what I want in the report, but CR (as it should) filters the results so that the report shows only those records between the begin and end dates.
    In short, I don't want the parameters to be used to filter the data returned from the stored proc. Is that possible?

    Huh??? You only return data that has been filtered by the SP to CR but you want all of the records?
    Filtering is done Server side with SP's, if CR doesn't get the unfiltered data then you have to change it server side.
    So first suggestion is to remove the parameters from the SP, then CR can filter or not later on but could potentially return a lot of data. Applying filtering client side in CRD coudl take a while to do, depending on what is in the report....
    Don

  • JDBC SQL Server Channel Calling Stored Procedure Won't Return Result Set

    Good afternoon, Experts
    We're calling a stored procedure in a sender communcation channel.  I can perform any SQL SELECT statement here, but for some reason when I execute the SP (EXECUTE StoredProcedureName) The Adapter Engine returns the following:
    Database-level error reported by JDBC driver while executing statement 'DECLARE @UpdateRecords bit SET @UpdateRecords = 0 EXECUTE ExportToSAP @UpdateRecords'. The JDBC driver returned the following error message: 'com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.'. For details, contact your database server vendor.
    Even stranger yet is is that this works just fine on our PI-DEV system.  I created an identical communication channel connecting to the same database with the same UID and PWD and it won't work in PI-QAS.
    Any help/ideas you could share would be greatly appreciated!!!
    Thanks,
    Chad

    Hi Chad.
    Normally, itu2019s a problem with your procedure. The Store Procedure is wrong and something is different between your DEV environment and QAS environment.
    Try to ask to DB team check it.
    Regards,
    Bruno

Maybe you are looking for