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

Similar Messages

  • 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

  • RETURN RESULT SET FROM JAVA STORED PROCEDURE

    I'm calling a Oracle 8.1.5 java stored proc from PL/SQL and I
    would like to send a Java result set to the calling function.
    I havent found anyway to do this currently. Anyone else doing
    anything like this and have a work around or know when/if it has
    been fixed?
    Mark
    [email protected]
    null

    This is not possible in Oracle 8i, will have to wait till Oracle 9i

  • Retrive MultiRow Result Set From Procedure

    Hi,
    Can you please guide me, on ways to retrieve result set with more than one row from procedure. I got two ways...
    1. Using Ref Cursor &
    2. Using Collection
    Do we have any other ways also to do this.
    Thanks,
    Ashish
    Edited by: Ashish Thakre on May 28, 2013 10:32 PM

    Hi this is the Oracle Designer forum. You would be better off at the PL/SQL/SQL place

  • Performance to fetch result set from stored procedure.

    I read some of related threads, but couldn't find any good suggestions about the performance issue to fetch the result set from a stored procedure.
    Here is my case:
    I have a stored procedure which will return 2,030,000 rows. When I run the select part only in the dbartisan, it takes about 3 minutes, so I know it's not query problem. But when I call the stored procedure in DBArtisan in following way:
    declare cr SYS_REFCURSOR;
    firstname char(20);
    lastname char(20);
    street char(40);
    city char(20);
    STATE varchar2(2);
    begin DISPLAY_ADDRESS(cr);
    DBMS_OUTPUT.ENABLE(null);
    LOOP
    FETCH cr INTO firstname,lastname,street, city, state;
    EXIT WHEN cr%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE( firstname||','|| lastname||','|| street||',' ||city||',' ||STATE);
    END LOOP;
    CLOSE cr;
    end;
    It will take about 100 minutes. When I used DBI fetchrow_array in perl code, it took about same amount of time. However, same stored procedure in sybase without using cursor, and same perl code, it only takes 12 minutes to display all results. We assume oracle has better performance. So what could be the problem here?
    The perl code:
    my $dbh = DBI->connect($databaseserver, $dbuser, $dbpassword,
    { 'AutoCommit' => 0,'RaiseError' => 1, 'PrintError' => 0 })
    or die "couldn't connect to database: " . DBI->errstr;
    open OUTPUTFILE, ">$temp_output_path";
    my $rc;
    my $sql="BEGIN DISPLAY_ADDRESS(:rc); END;";
    my $sth = $dbh->prepare($sql) or die "Couldn't prepare statement: " . $dbh->errstr;
    $sth->bind_param_inout(':rc', \$rc, 0, { ora_type=> ORA_RSET });
    $sth->execute() or die "Couldn't execute statement: " . $sth->errstr;
    while($address_info=$rc->fetchrow_arrayref()){
    my ($firstname, $lastname, $street, $city, $STATE) = @$address_info;
    print OUTPUTFILE $firstname."|".$lastname."|".$street."|".$city."|".$STATE;
    $dbh->commit();
    $dbh->disconnect();
    close OUTPUTFILE;
    Thanks!
    rulin

    Thanks for you reply!
    1) The stored procedure has head
    CREATE OR REPLACE PROCEDURE X_OWNER.DISPLAY_ADDRESS
    cv_1 IN OUT SYS_REFCURSOR
    AS
    err_msg VARCHAR2(100);
    BEGIN
    --Adaptive Server has expanded all '*' elements in the following statement
    OPEN cv_1 FOR
    Select ...
    commit;
    EXCEPTION
    WHEN OTHERS THEN
    err_msg := SQLERRM;
    dbms_output.put_line (err_msg);
    ROLLBACK;
    END;
    If I only run select .. in DBArtisan, it display all 2030,000 rows in 3:44 minutes
    2) But when call stored procedure, it will take 80-100 minutes .
    3) The stored procedure is translated from sybase using migration tools, it's very simple, in sybase it just
    CREATE PROCEDURE X_OWNER.DISPLAY_ADDRESS
    AS
    BEGIN
    select ..
    The select part is exact same.
    4) The perl code is almost exact same, except the query sql:
    sybase verson: my $sql ="exec DISPLAY_ADDRESS";
    and no need bind the cursor parameter.
    This is batch job, we create a file with all information, and ftp to clients everynight.
    Thanks!
    Rulin

  • 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

  • How to pass a result set as an output parameter

    I have a function that will be used as a web service. It invokes a stored procedure - ideally I'd like to pass the result set from the SP out as a result set to the client consuming the web service. Is this do-able or am I in dreamland?

    What you typically do is iterate thru the RS, turning each row of data into a business object and adding all the business objects to a list or some other collection. Then close the result set. Return that collection of business objects to the client.

  • Advice Please: Adding Few Static Values to Stored Proc Returned Result Set

    Hello -
    The Stored Proc below returns about 1000 rows of result set when a date is passed to the query. In addition to that, there are about 5 rows of data (which is in my excel file) needs to be added to the result set. What is the best possible way?
    What I have done is I created a new table which has that 5 static rows. It has just the addresses and amount and customer number. There is no invoice date in that table. I tried UNION and the query did not like the fact that I had something like that in
    the first table:
    SELECT
    '0' as 'TYPE'
    ,'TBCCA' as 'Acc ID'
    ,'12882' as 'BEID'
    , '' as ' # OF UNITS'
    , Circuit_Total as 'AMT'
    ,'D' as 'D or C'
    , '' as ' FDOC yyyymmdd'
    , '' as ' LDOC yyyymmdd'
    , Address as 'Brief Comment'
    , city as 'Tax City'
    , State as 'Tax State'
    , Zip_Code as 'Tax Zip Code'
    , INV_DATE as 'Invoice Date'
    FROM [dbo].[TBC_MonthlyCircuitDetail]
    WHERE INV_DATE = '2014-07-01'
    AND [Circuit_Total] >0
    UNION
    SELECT 0
    '0' as 'TYPE' --DID NOT LIKE THIS <<
    ,'TBCCA' as 'Acc ID'
    ,'12882' as 'BEID'
    , '' as ' # OF UNITS'
    , Circuit_Total as 'AMT'
    ,'D' as 'D or C'
    , '' as ' FDOC yyyymmdd'
    , '' as ' LDOC yyyymmdd'
    , Address as 'Brief Comment'
    , city as 'Tax City'
    , State as 'Tax State'
    , Zip_Code as 'Tax Zip Code'
    , '' INV_DATE as 'Invoice Date'
    FROM [dbo].[TBC_MonthlyCircuitDetailStaticValues]
    WHERE INV_DATE = '2014-07-01'
    AND [Circuit_Total] >0
    Stored Proc below:
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE PROCEDURE [dbo].[SP_TBC_ORBIT Process Form]
    -- Add the parameters for the stored procedure here
    @INVOICE_DATE varchar(20)
    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    -- Insert statements for procedure here
    SELECT
    '0' as 'TYPE'
    ,'TBCCA' as 'Acc ID'
    ,'12882' as 'BEID'
    , '' as ' # OF UNITS'
    , Circuit_Total as 'AMT'
    ,'D' as 'D or C'
    , '' as ' FDOC yyyymmdd'
    , '' as ' LDOC yyyymmdd'
    , Address as 'Brief Comment'
    , city as 'Tax City'
    , State as 'Tax State'
    , Zip_Code as 'Tax Zip Code'
    , INV_DATE as 'Invoice Date'
    FROM [dbo].[TBC_MonthlyCircuitDetail]
    WHERE INV_DATE IN (@INVOICE_DATE)
    AND [Circuit_Total] >0
    END
    GO
    So, what do you suggest? As you can tell, I am quite a novice but I am learning by researching, asking questions and doing it. Thanks in advance!
    Sanjeev Jha

    Your second Select statement is as below:
    SELECT 0
      '0' as 'TYPE'
    --DID NOT LIKE THIS <<
    ,'TBCCA' as
    'Acc ID'
    ,'12882' as
    'BEID'
    , '' as
    ' # OF UNITS'
    , Circuit_Total as
    'AMT'
    ,'D' as 'D or C'
    , '' as
    ' FDOC yyyymmdd'
    , '' as
    ' LDOC yyyymmdd'
    , Address as
    'Brief Comment'
    , city as 'Tax City'
    , State as
    'Tax State'
    , Zip_Code as
    'Tax Zip Code'
    , ''INV_DATE
    as 'Invoice Date'  -- CHANGE HERE
    FROM [dbo].[TBC_MonthlyCircuitDetailStaticValues]
    WHERE INV_DATE = '2014-07-01'
    AND [Circuit_Total] >0
    You are receiving Invoice date from INV_DATE column from table or you want to set it as blank?
    Change it to either - ( '' as
    'Invoice Date' ) or  (INV_DATE as
    'Invoice Date'  )
    -Vaibhav Chaudhari

  • Need help in restricting a result set from a UNION in MERGE

    Hello,
    Would really appreciate if anybody could help me out with the issue I am facing with the below statements (I am new to Oracle ):
    merge into table_name_1 p
    using
      select p_key, value_1, value_2
      from some_tables
      UNION
      select p_key, value_1, value_2
      from some_tables
      UNION
    )t
    on (p.p_key = t.p_key)
    when matched then
      update table_name_1 with value_1 and value_2
    when not matched then
      insert table_name_1 with p_key, value_1, value_2;
    Now, the union of all those selects gives me distinct values and it works most of the times but when I get values like below, the merge fails:
    p_key-----value_1-----value_2
    100-----25-----50
    100-----NULL-----50
    I browsed the net and understood the reason behind this: the result set becomes ambiguous and merge doesn't know which row to insert first and which one to update.
    Now, my requirement is: I could have any of the below scenario/result sets from the union and I need only 1 row per p_key -
    result_set_1
    p_key-----value_1-----value_2
    100-----25-----50 ***************need this row
    100-----NULL-----50
    100-----NULL-----NULL
    result_set_2
    p_key-----value_1-----value_2
    100-----25-----NULL ***************need this row
    100-----NULL-----NULL
    result_set_3
    p_key-----value_1-----value_2
    100-----25-----NULL ***************need this row (p_key = 100)
    100-----NULL-----NULL
    200-----NULL-----75 ***************need this row (p_key = 200)
    200-----NULL-----NULL
    300-----90-----95 ***************need this row (p_key = 300)
    So, I basically need a way to restrict the values that I will get from the UNION of all those selects to fit the requirement above, hope I was able to explain the issue I am facing.
    Any help would be greatly appreciated.
    Thanks,
    Dpunk

    In all cases the goal is to find an order by value that will make the row you want be first.
    The query I gave is calculating a priority for each row by adding up values showing whether each column is null or not null. The case statements check whether each column is null and need to be added up to give a total priority value.
    Value_1   Value_2   Priority
    Not Null  Not Null  2 + 1 = 3
    Not Null  Null      2 + 0 = 2
    Null      Not Null  0 + 1 = 1
    Null      Null      0 + 0 = 0
    The priority value ends up being a bitmap showing whether each value is null or not null. I think that reflects my mathematics background.
    Another way of getting the same result (suggested to me by your asking why it needs the "+") would be to use two CASE expressions as separate order by items:
    select p_key, value_1, value_2 from
    (select p_key, value_1, value_2, row_number() over
              (partition by p_key
               order by case when value_1 is null then 0 else 1 end DESC,
                        case when value_2 is null then 0 else 1 end DESC
              ) as rn
      from (your UNION query here)
    where rn = 1
    A third way is to use a more complex case statement:
    select p_key, value_1, value_2 from
    (select p_key, value_1, value_2, row_number() over
              (partition by p_key
               order by case when value_1 is NOT null and value_2 is NOT null then 1
                             when value_1 is NOT null and value_2 is     null then 2
                             when value_1 is     null and value_2 is NOT null then 3
                             when value_1 is     null and value_2 is     null then 4
                         end  ASC
              ) as rn
      from (your UNION query here)
    where rn = 1

  • It is required to get the result set from the last query.

    I need this SP to return the result set from the last query.
    SET QUOTED_IDENTIFIER OFF
    GO
    SET ANSI_NULLS ON
    GO
    alter        proc spQ_GetASCBillingRateIDs2
    @ScheduleID CHAR(15),
    @startdate smalldatetime,
    @enddate smalldatetime
    as
    set nocount on
    truncate table tbltmpgroup
    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tbltmptbltest]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table [dbo].[tbltmptbltest]
    exec sp_CreateTblTmpGroup
    insert into tbltmpgroup
    SELECT DISTINCT
    case when pd.billparent = 'N' then org.eligibleorgid
    else isnull(af.parentid, org.eligibleorgid) end as billorgid,
    pd.individualbill , pd.cobrabill, pd.billparent,
    org.eligibleorgid, org.polid, org.orgpolicyid,
    pp.planid,  pp.rateid,
    ps.ascinvoicedate,
    case when ps.ascclaimfromdate > @startdate then ps.ascclaimfromdate
    else @startdate end as premiumrundayFrom,
    case when ps.ascclaimtodate < @enddate then ps.ascclaimtodate
    else @enddate end as premiumrundayTo,
    fts.effdate, fts.termdate,
    case when fts.effdate > @startdate then fts.EffDate
    else @startdate end as ascStartDate,
    case when fts.termdate < @enddate then fts.termdate
    else @enddate end as ascEndDate
    FROM premiumschedule ps (nolock)
    inner join orgpolicy org (nolock)
    on org.ascinvoicerungroup between ps.premiumrundayfrom and ps.premiumrundayto
    inner join FundingTypeStatus fts
    on fts.orgpolicyid = org.orgpolicyid
    and fts.fundtype = 'ASC'
    and ((fts.effdate between @startdate and @enddate)
    or (fts.termdate between @startdate and @enddate)
    or (fts.effdate < @startdate and fts.termdate > @enddate))
    inner join eligibilityorg o (nolock)
    on org.eligibleorgid = o.eligibleorgid
    inner join policydef pd (nolock)
    on pd.polid = org.polid
    inner join policyplans pp (nolock)
    on pp.polid = org.polid
    inner join program p (nolock)
    on pd.programid = p.programid
    left join orgaffiliation af with (nolock)
    on org.eligibleorgid = af.childid
    WHERE ps.premiumscheduleid = @ScheduleID
    AND org.orgpolicyid <> ''
    go
    SELECT DISTINCT z.rateid, e.enrollid, z.ascstartdate, z.ascenddate
    into tbltmptbltest FROM enrollment E (nolock)
    inner join tbltmpgroup z
    on e.rateid = z.rateid
    go
    CREATE UNIQUE CLUSTERED INDEX IDXTempTable  ON tbltmptbltest(enrollid)
    create index IDXTemptableDates on tbltmptbltest(ascstartdate,ascenddate)
    go
    select distinct t.*
    from tbltmpgroup t
    where rateid in (
    select distinct t.rateid from VW_ASC_Billing)
    order by billorgid
    set nocount off
    GO
    SET QUOTED_IDENTIFIER OFF
    GO
    SET ANSI_NULLS ON
    GO

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules (you have no idea).
    Temporal data should use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    What you did post is bad SQL. 
    The prefix “tbl-” is a design flaw called tibbling and we do not do it. We seldom use temp tables in RDBMS; it is how magnetic tape file programmers fake scratch tapes. 
    If the schema is correct, then SELECT DISTINCT is almost never used. 
    Your “bill_parent” looks like a assembly language bit flag; we never use those flags in SQL. 
    “Funding_Type_Status” is an absurd name for a table. A status is a state of being, not an entity. A type is an attribute property. So this table ought to be column that is either a “funding_type” or “funding_status” (with the time period for the state of being
    shown in other columns). But this hybrid is not possible in a valid data model. 
    Want to try again, with DDL and some specs? 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Getting a Clob Value from an OUT Parameter

    I am having trouble fetching the CLOB Value(an XML Document) from an Out parameter. I have been
    trying to fetch the value into a String, an OracleClob, etc.. no luck still get either an invalid
    cast or a DBNULL value. Is there an example out there for returning and manipulating CLOBS in either VB.NET or in C#.
    Thanks,
    Scott E. Hunley

    Scott,
    Hopefully, this will help:
    ========================== C# code begin ===========================
    using System;
    using System.Data;
    using Oracle.DataAccess.Client;
    using Oracle.DataAccess.Types;
    namespace Test
    class OutClob
    static OracleCommand cmd;
    static void Execute(string sql)
    try
    cmd.CommandText = sql;
    cmd.ExecuteNonQuery();
    catch (Exception e)
    Console.WriteLine(e.Message);
    static void Main(string[] args)
    // connect
    OracleConnection con = new OracleConnection();
    con.ConnectionString = "user id=scott;password=tiger;data source=ora92;";
    con.Open();
    // instantiate the command object
    cmd = new OracleCommand();
    cmd.Connection = con;
    // drop table
    Execute("drop table foo");
    // create table
    Execute("create table foo (num number, xml clob)");
    // insert a row with xml data in a CLOB column
    Execute("insert into foo values (1, '<foo>bar</foo>')");
    // bind and output parameter for an anonymous PL/SQL block
    OracleParameter p1 = cmd.Parameters.Add("p1", OracleDbType.Clob);
    p1.Direction = ParameterDirection.Output;
    // execute the anonymous PL/SQL block which returns a CLOB as an
    // output parameter of type OracleClob
    Execute("begin select xml into :1 from foo where num = 1; end;");
    // Obtain the clob with the proper cast
    OracleClob clob = (OracleClob)p1.Value;
    // print out the XML document
    Console.WriteLine(clob.Value);
    ========================== C# code end ===========================
    Output:
    <foo>bar</foo>

  • How to export result set from mysql query browser to .sql in oracle

    Hi folks:
    I was trying to export result set from MySql query browser to Oracle. I could able to do
    File->Export Result Set-> Excel format...
    What I am trying to get is .sql file so that I can run it as a script in my oracle db. Is there any way we can get .sql file with inserts and delimeters ....?
    Did you guys get my question.?
    Please throw some light on this....
    Could be very appreciable ....
    Thanks
    Sudhir Naidu

    Hi
    Create a sql statement which generates the insert statements.
    Something like this:
    select 'insert into table1 (column1, column2, column3) values (' ||
    column1 || ', ' || column2 || ', ' || column3 || ');' from table 1;
    The || sign is the string concatenation sign in Oracle, replace it the appropriate sign in MySql. Export the result set of this query into a file, and you can run it in a SqlPlus.
    Ott Karesz
    http://www.trendo-kft.hu

  • Dev procedure out put display in PDF form is it same wd java and wd abap?

    hi,
    dev procedure out put display in PDF form is it same wd java and wd abap?
    Thanks,
    Rama

    Hi,
    for Web Dynpro Java, see
    <a href="http://help.sap.com/saphelp_nw70/helpdata/en/60/6fc10c6748479392101e09c9e8d33a/frameset.htm">this</a> and
    for Web Dynpro ABAP, see <a href="http://help.sap.com/saphelp_nw70/helpdata/en/2c/241a427ff6db2ce10000000a1550b0/frameset.htm">this</a>
    Regards, Heidi

  • JDBC Result Set from Non-Database Source

    In Java, is it possible to create a result set from a non-database data source?, for example an XML file, text file, vectors, java beans
    We have a Swing application that currently makes direct JDBC calls to the DB2 database for creating result sets. We want to replace JDBC calls with calls to web service, but want to still create result sets on the client, so the replacement of the datasource from database to web service call is transparent to the rest of the code.

    In Java, is it possible to create a result set from a
    non-database data source?, Yes.
    for example an XML file,
    text file, vectors, java beans
    We have a Swing application that currently makes
    direct JDBC calls to the DB2 database for creating
    result sets. We want to replace JDBC calls with calls
    to web service, but want to still create result sets
    on the client, so the replacement of the datasource
    from database to web service call is transparent to
    the rest of the code.You might want to think carefully about what you are doing.
    It is fairly easy, although somewhat tedious (many methods,) to create a new type of ResultSet.
    But if the above application is doing SQL via statements and expecting the result via a ResultSet then you are not just creating a ResultSet but an entire driver and one that will have to deal with SQL as well. And if you have to handle the SQL itself that means you will probably need a parser and interpreter.

  • 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

Maybe you are looking for

  • DATA LINK

    I am using 6i reports. Need your help in developing a Group left report. I join 2 queries (Q1 master and Q2 detail) thru a data link. The report is showing the master information even if detail is not available. I want to print master record only if

  • Saving Ultrabeat Presets

    Hello all, I've been working in Ultrabeat, making a custom kit using sounds from various presets. Problem is that I saved the new preset, but it reverts to the original preset, before I made the changes. Is saving presets something of Logic Pro? I kn

  • Cant get the osx mavericks yet my mac meets all standards listed except model

    i have a macbook early 2007 black it has the 2 gb memory it has more than 8 gb data yet i cant get it...

  • Camera won't work in skype

    Upgraded to Lion and now Skype won't recognise the imac camera. "Built in isight" is listed in the video prefrences but the test screen is blank. The Skype calls show a video icon with a cross through it and when I click it it blinks, then stays cros

  • HELP HELP Sound distortion form DJ speakers

    Hello all I captured an event using open air mic from the camera. I had the volume levels set slightly lower but as I moved near the DJ floor speakers, vibration and distorts starts. Its not horrible but noticeable. I was wondering if there was a met