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

Similar Messages

  • JSP Servlet and convert the result set of an SQL Query To XML file

    Hi all
    I have a problem to export my SQL query is resulty into an XML file I had fixed my servlet and JSP so that i can display all the records into my database and that the goal .Now I want to get the result set into JSP so that i can create an XML file from that result set from the jsp code.
    thisis my servlet which will call the jsp page and the jsp just behind it.
    //this is the servlet
    import java.io.*;
    import java.lang.reflect.Array;
    import java.sql.*;
    import java.util.ArrayList;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.naming.*;
    import javax.sql.*;
    public *class *Campaign *extends *HttpServlet
    *private* *final* *static* Logger +log+ = Logger.+getLogger+(Campaign.*class*.getName());
    *private* *final* *static* String +DATASOURCE_NAME+ = "jdbc/SampleDB";
    *private* DataSource _dataSource;
    *public* *void* setDataSource(DataSource dataSource)
    _dataSource = dataSource;
    *public* DataSource getDataSource()
    *return* _dataSource;
    *public* *void* init()
    *throws* ServletException
    *if* (_dataSource == *null*) {
    *try* {
    Context env = (Context) *new* InitialContext().lookup("java:comp/env");
    _dataSource = (DataSource) env.lookup(+DATASOURCE_NAME+);
    *if* (_dataSource == *null*)
    *throw* *new* ServletException("`" + +DATASOURCE_NAME+ + "' is an unknown DataSource");
    } *catch* (NamingException e) {
    *throw* *new* ServletException(e);
    protected *void *doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
    Connection conn = *null*;
    *try* {
    conn = getDataSource().getConnection();
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("select post_id,comments,postname from app.posts");
    // out.println("Le r&eacute;sultat :<br>");
    ArrayList <String> Lescomments= *new* ArrayList<String>();
    ArrayList <String> Lesidentifiant = *new* ArrayList<String>();
    ArrayList <String> Lesnoms = *new* ArrayList <String>();
    *while* (rs.next()) {
    Lescomments.add(rs.getString("comments"));
    request.setAttribute("comments",Lescomments);
    Lesidentifiant.add(rs.getString("post_id"));
    request.setAttribute("id",Lesidentifiant);
    Lesnoms.add(rs.getString("postname"));
    request.setAttribute("nom",Lesnoms);
    rs.close();
    stmt.close();
    *catch* (SQLException e) {
    *finally* {
    *try* {
    *if* (conn != *null*)
    conn.close();
    *catch* (SQLException e) {
    // les param&egrave;tres sont corrects - on envoie la page r&eacute;ponse
    getServletContext().getRequestDispatcher("/Campaign.jsp").forward(request,response);
    }///end of servlet
    }///this is the jsp page called
    <%@ page import="java.util.ArrayList" %>
    <%
    // on r&eacute;cup&egrave;re les donn&eacute;es
    ArrayList nom=(ArrayList)request.getAttribute("nom");
    ArrayList id=(ArrayList)request.getAttribute("id");
    ArrayList comments=(ArrayList) request.getAttribute("comments");
    %>
    <html>
    <head>
    <title></title>
    </head>
    <body>
    Liste des campagnes here i will create the xml file the problem is to display all rows
    <hr>
    <table>
    <tr>
    </tr>
    <tr>
    <td>Comment</td>
    <td>
    <%
    for( int i=0;i<comments.size();i++){
    out.print("<li>" + (String) comments.get(i) + "</li>\n");
    }//for
    %>
    </tr>
    <tr>
    <td>nom</td>
    <td>
    <%
    for( int i=0;i<nom.size();i++){
    out.print("<li>" + (String) nom.get(i) + "</li>\n");
    }//for
    %>
    </tr>
    <tr>
    <td>id</td>
    <td>
    <%
    for( int i=0;i<id.size();i++){
    out.print("<li>" + (String) id.get(i) + "</li>\n");
    }//for
    %>
    </tr>
    </table>
    </body>
    </html>
    This is how i used to create an XML file in a JSP page only without JSP/SERVLET concept:
    <%@ page import="java.sql.*" %>
    <%@ page import="java.io.*" %>
    <%
    // Identify a carriage return character for each output line
    int iLf = 10;
    char cLf = (*char*)iLf;
    // Create a new empty binary file, which will content XML output
    File outputFile = *new* File("C:\\Users\\user\\workspace1\\demo\\WebContent\\YourFileName.xml");
    //outputFile.createNewFile();
    FileWriter outfile = *new* FileWriter(outputFile);
    // the header for XML file
    outfile.write("<?xml version='1.0' encoding='ISO-8859-1'?>"+cLf);
    try {
    // Define connection string and make a connection to database
    Connection conn = DriverManager.getConnection("jdbc:derby://localhost:1527/SAMPLE","app","app");
    Statement stat = conn.createStatement();
    // Create a recordset
    ResultSet rset = stat.executeQuery("Select * From posts");
    // Expecting at least one record
    *if*( !rset.next() ) {
    *throw* *new* IllegalArgumentException("No data found for the posts table");
    outfile.write("<Table>"+cLf);
    // Parse our recordset
    // Parse our recordset
    *while*(rset.next()) {
    outfile.write("<posts>"+cLf);
    outfile.write("<postname>" + rset.getString("postname") +"</postname>"+cLf);
    outfile.write("<comments>" + rset.getString("comments") +"</comments>"+cLf);
    outfile.write("</posts>"+cLf);
    outfile.write("</Table>"+cLf);
    // Everything must be closed
    rset.close();
    stat.close();
    conn.close();
    outfile.close();
    catch( Exception er ) {
    %>

    Please state your problem that you are having more clearly so we can help.
    I looked at your code I here are a few things you might consider:
    It looks like you are putting freely typed-in comments from end-users into an xml document.
    The problem with this is that the user may enter characters in his text that have special meaning
    to xml and will have to be escaped correctly. Some of these characters are less than character, greater than character and ampersand character.
    You may also have a similiar problem displaying them on your JSP page since there may be special characters that JSP has.
    You will have to read up on how to deal with these special characters (I dont remember what the rules are). I seem to recall
    if you use CDATA in your xml, you dont have to deal with those characters (I may be wrong).
    When you finish writing your code, test it by entering all keyboard characters to make sure they are processed, stored in the database,
    and re-displayed correctly.
    Also, it looks like you are putting business logic in your JSP page (creating an xml file).
    The JSP page is for displaying data ONLY and submitting back to a servlet. Put all your business logic in the servlet. Putting business logic in JSP is considered bad coding and will cause you many hours of headache trying to debug it. Also note: java scriptlets in a JSP page are only run when the JSP page is compiled into a servlet by java. It does not run after its compiled and therefore you cant call java functions after the JSP page is displayed to the client.

  • OBIEE Answers does not display the result set of a report query

    Hi,
    We have a pivot table type of report in Oracle Business Intelligence Enterprise Edition v.10.1.3.3.2 Answers that has the following characteristics:
         3 Pages
         3 Sections , 4 Columns
         18363 Rows in the result set
    As per the NQQuery.log, the query for this report executes successfully resulting in 18363 rows. However, nothing comes up in the display on Answers. Moreover, no error is reported. The instanceconfig.xml file has the following setting:
    <PivotView>
         <CubeMaxRecords>30000</CubeMaxRecords>
         <CubeMaxPopulatedCells>300000</CubeMaxPopulatedCells>
    </PivotView>
    Even with these settings, Answers just returns a blank page - nothing is displayed in the name of the result set of the report query. Has anyone encountered this problem scenario before?
    Any help is much appreciated.
    Thanks,
    Piyush

    Hi Fiston / Pradeep,
    Thanks for your inputs. A few points to note:
    -> I am actually not getting any error message in answers or the NQQuery log. Moreover I am not getting any errors related to "query governor limit exceeding in cube generation" also.
    -> I have other pivot table type of reports in the same repository that work fine. In fact the report which has this issue even works sometimes - what actually is happening is that if I alter the number of sections from 3 to 4, then the result set changes from 14755 Rows to 18363 Rows and as per the NQQuery.log in both cases the query completes successfully. However, when the result set has 14755 rows, I get to see the output in Answers; however when the result set is 18636 rows, the Answers screen just goes blank and does not show any output or error. This makes me believe that there is some parameter in instanceconfig or the NQSconfig file - I have tried a lot of changes but nothing works !
    Any help is much appreciated.
    Best Regards,
    Piyush

  • Virtual column in the result set of the query.

    Hi folks,
    I have table , let it be, EMP. It has columns ENAME,EMPNO,JOB etc.,
    My requirement is to add an extra column, not present in the table, having NULL value at the time of diplaying the results of a query. I hope you got it. So a column that does not exists in the table should get displayed in the resultant set when we query the results from that table. so my question is, how to write the SELECT statement using that virtual column.
    I'd thought of using X column in Dummy table but what if I don't have any dummy table in my particular schema.
    Please do revert back with the solution.
    Your effort'll be genuinely appreciated.
    Cheers
    PCZ

    Hi,
    If you just wany display null values you can write query like this :
    SELECT ENAME,EMPNO,JOB , NULL DUMMY_COLUMN FROM emp;
    Regrads
    Avinash

  • How to Colour the fields in the Result Set of the query

    Hi all,
    I am having a requirement wher the user want to view the queries results with some colour to the char in the result set.
    suppose customer is the row he want to view some customers with one color and some with different color.
    Is it possible in Bi.
    If so Plz let me know
    Regards

    Hi Priya,
    for the macro thing, you will have to create a workbook and store your query into it, because macros are attached to only workbooks and not queries.
    in the workbook screen (i.e. excel), go to tools --> Macro --> Visual Basic Editor. or simply press Alt + F11. this will take you to macro editor screen.
    you can use code that may look something like below to color the columns, you can also give constant column if they are fixed.
    sub ColorColumns(rngTarget As Range, _
        intColor As Integer)
    Dim c As Long
        With rngTarget
            .Interior.ColorIndex = intColour
            Next c
        End With
    End Sub
    You will find some easy and short snippets for this.
    Regards,
    Purvang

  • Is column visibility based on the first page of the result set or the entire result set?

    I have tried, in vain, to play with the column visibility expression in my report. So where my Business Unit is "MC" or "FM", then I want to display column "HCFA Number"...otherwise hide it. If I run strictly for "MC"
    it works! If I run simply for "CO" it works! And doesn't show! But if I combine "CO" and "MC", it is hidden and I would expect it to be visible since "MC" is part of my entire report.
    Here's the expression I came up with for Column Visibility...
    =IIf((Fields!BUSINESS_UNIT.Value = "MC") OR
    (Fields!BUSINESS_UNIT.Value = "FM"),FALSE,TRUE)
    Am I missing something here or just being dense late on a Friday???
    Thanks for your review and am hopeful for a reply.

    Hi ITBobbyP,
    It seems you have add parameter based on the "Business Unit" which is multiple values and when you select the "CO,MC" the entire column "HCFA Number" is hide, but what you want is to hide the CO related "HCFA Number"
    and show the MC related "HCFA Number", right?
    The expression you are using to show/hide the column visibility will based on the current filtered entire result set. That is mean the entire column "HCFA Number" will be show when the result set contains "MC" or "FM"
    or both, otherwise, it will always hide.
    In your scenario, you can set the row visibility using the expression and you will get the result like below:
    You can set the visibility of the textbox "[HCFANumber]", but the CO related "HCFANumber" will be blank:
    If I have some misunderstanding, please try to provide more details information about the expect result you want.
    Regards,
    Vicky Liu
    Vicky Liu
    TechNet Community Support

  • How to send email using pl/sql containing the result set as the msg body

    Hi.. im using Pl/SQL code to send emails to the users from a dataset that is obtained in a databse table. i have used utl_smtp commands to establish the connection with the smtp mail server. im stuck at the logic when i have to include the message body which is actually the result set of a table.. For instance
    IF (p_message = 0) THEN
    UTL_SMTP.write_data(l_mail_conn, 'There is no mismatch between the codes' || UTL_TCP.crlf);
    ELSE
    UTL_SMTP.write_data(l_mail_conn, 'The missing codes are ' || UTL_TCP.crlf);
    for s in (select * from temp)
    loop
    UTL_SMTP.write_data(l_mail_conn, ' ' ||s || UTL_TCP.crlf);
    end loop;
    END IF;
    UTL_SMTP.close_data(l_mail_conn);
    UTL_SMTP.quit(l_mail_conn);
    END;
    ***p_message is a prameter passed to this procedure..
    Can i obtain the result in the form i have it in my table. which has three columns. I want to display the three columns as it is with teh records. ?

    this is not related about this forum but you can use below,
    CREATE OR REPLACE PROCEDURE SEND_MAIL (subject varchar2,mail_from varchar2, mail_to varchar2,mail_msg varchar2)
    IS
    mail_host varchar2(30):='XXXXX';
    mail_conn utl_smtp.connection;
    tz_offset number:=0;
    str varchar2(32000);
    BEGIN
    begin
    select to_number(replace(dbtimezone,':00'))/24 into tz_offset from dual;
    exception
    when others then
    null;
    end;
    mail_conn:=utl_smtp.open_connection(mail_host, 25);
    utl_smtp.helo(mail_conn,mail_host);
    utl_smtp.mail(mail_conn,'[email protected]');
    utl_smtp.rcpt(mail_conn,mail_to);
    utl_smtp.open_data(mail_conn);
    utl_smtp.write_data(mail_conn,'Date: '||to_char(sysdate-tz_offset,'dd mon yy hh24:mi:ss')||utl_tcp.crlf);
    utl_smtp.write_data(mail_conn,'From: '|| mail_from ||utl_tcp.crlf);
    utl_smtp.write_data(mail_conn,'To: "'|| mail_to ||'" <'||mail_to||'>'||utl_tcp.crlf);
    utl_smtp.write_data(mail_conn,'Subject: '||subject||utl_tcp.crlf);
    utl_smtp.write_data(mail_conn,utl_tcp.crlf);
    utl_smtp.write_data(mail_conn,replace_turkish_chars(mail_msg)||utl_tcp.crlf);
    utl_smtp.write_data(mail_conn,utl_tcp.crlf);
    utl_smtp.close_data(mail_conn);
    utl_smtp.quit(mail_conn);
    END;
    Edited by: odilibrary.com on Jun 12, 2012 5:26 PM

  • Not able to access the result set from one member function to another

    Im new to jdbc
    I have declared a connection object , a result set object and statement object in one member function and i am not able to access these in another member function. But both are in the same class
    Kindly help
    Thanks
    Shasi

    Kindly refrain from double-posting:
    http://forum.java.sun.com/thread.jspa?threadID=700659&tstart=0
    - Saish

  • Don't get a result set from a query to mySql database

    Hello everyone,
    I am writing a program in which i refer to a mySql database.
    I encountered a problem using the executeQuery in which i don't get a resultSet at the end of the run,
    instead i get a null.
    gust for the record, the api says that it will never return null(se 6), also i queried the DB with a mySql client and the data is there
    and when i use execute("") everything works fine.
    I just can't get my wished result.
    the peace of code I am referring to is here, please feel free to say if you need more code...
    public static ResultSet getAccountResSet(int id) throws SQLException {
             //String query = "SELECT acctNum, acctOwnerId, acctOwnerName, balance, acctType, creditLimit, yearlyInterest, duration, creationDate, relatedCheckingAccoun FROM accounts WHERE acctNum="+id;
             String query = "select * from accounts where id="+id;
             ResultSet rs = statement.executeQuery(query);//this line falls, rs is null and i get null pointer exception
             return rs;
        }thanks for you help :)
    Edited by: gizmokaka on Mar 29, 2008 8:37 AM

    Maybe it's not the function executeQuery(query) that gives you the nullpointer. I think it may be that there is no connection to the DB, in which case the statement variable is null. Call to a method through this variable will trigger a nullpointer. Could you please post the exception text here? It may tell you where the NullPointerException occurs.
    //Chris

  • I have used a 'for loop' to create an array of output data, however I want the each of the data sets from the array to be placed into a 1-D array. How do I concatenate the output of the for loop into a 1-D array?

    I am using this to create a data set that will be passed as an anolog output therefore it needs to have the correct array dimensions to go into the analog write vi.

    I'm updating my request... I've figured out how to do this by copying an example that uses a simple FOR loop (as seen in the attached current version of my VI). My question now becomes this: Is there a way to save the Y values corresponding to those X values into two more arrays? That is, just for argument's sake, let's say I took the first 100 elements from the X array, and found them to be positive. Then I would like to take the first 100 elements of the Y array and put them into a 'Y Values for X > 0' array. ...And likewise with the negative X values, they should have a separate array of corresponding 'Y values for X < 0' array.
    I can see that I should somehow save the indices of the positive X values from the large arrray wh
    en I sort them out, and use those indices to pick out the elements from the main Y array with the same indices.
    I just can't seem to set up the code necessary to do this. ...Can anyone help, please?
    Attachments:
    Poling_Data_Reader_5i.vi ‏79 KB
    30BLEND.txt ‏3 KB

  • Minus and passing the result set

    I have a query in a procedure....let us say "test.prc":
    select A.VALUE from TABLE A
    where A.VALUE_ID = get_rec.VALUE_ID minus
    select B.VALUE from TABLE B
    In the above query, I am passing the "get_rec.VALUE_ID" from a cursor above the query.
    Now is there a way to capture the result set of the above minus operation and pass the result set to the calling sql program (called "call_test.sql")?
    Thanks,
    Chiru
    Message was edited by:
    Megastar_Chiru

    I got what I was trying to do...
    I have 1 more question though....I am printing out my output using dbms package from sql*plus...using the following command
    dbms_output.put_line(nvl('Flex Value set Id : '||get_rec.flex_value_set_id,0)||' values that have no corresponding alias : ' || nvl(v_flex_val,0));
    "get_rec.flex_value_set_id" gets passed in from my cursor above the dbms statement.
    and it looks like below:
    Flex Value set Id : 20118 values that have no corresponding alias : 00
    Flex Value set Id : 20118 values that have no corresponding alias : 10
    Flex Value set Id : 20118 values that have no corresponding alias : 11
    Flex Value set Id : 20118 values that have no corresponding alias : 20
    Flex Value set Id : 20118 values that have no corresponding alias : 30
    Flex Value set Id : 20124 values that have no corresponding alias : Standard
    Is there some way to neatly break when the value set id changes? ...ie., make it print output something like below:
    Flex Value set Id : 20118
    values that have no corresponding alias : 00
    values that have no corresponding alias : 10
    values that have no corresponding alias : 11
    values that have no corresponding alias : 20
    values that have no corresponding alias : 30
    Flex Value set Id : 20124
    values that have no corresponding alias : Standard
    Thanks,
    Chiru

  • Result Sets with the Microsoft ODBC Driver for Oracle

    Howdy all.
    I have an Oracle database that I have migrated from MSSQL2K. My front end is mostly VB, and I have many (hundreds) DLL's that use ADO to access the database and execute stored procedures in the database. I cannot seem to get result sets from the Oracle procedures. I have tried passing a SYS_REFCURSOR as an IN OUT parameter, and I have tried returning a SYS_REFCURSOR in a function. The Microsoft ODBC Driver for Oracle does not seem to handle the ref cursors. If I use the Oracle ODBC driver, then ref cursors are handled sort of magically. Just like the result sets are in MSSQL with the SQL Server ODBC Driver.
    The question that I would like to pose to anybody willing to answer is this: Is there any way to use the Microsoft ODBC Driver for Oracle without changing the way I do the database access (using ADO connection/command/recordset objects)? I need the same DLL's to work on top of both MSSQL and Oracle.
    I know that what I want to do is possible using the Oracle ODBC driver, but this will take some major changes to some of my DB components. I am trying to stay away from this, but it looks like I am going to have to go that route - that is unless somebody wows me with a good answer to this post.
    wally

    As you are using Microsoft driver which works in XP and does not on Win 2003 you should post this on microsoft forum.

  • Can i store the Result set values as a Session variable

    hai,
    I want the result set values of a query to be used many times and I want the same resultset between different page calls.
    I want all those records fetched from the database to be available in the next page with out refetching from the database.
    can any one help me out. its very urgent.....
    Thanks and regards,
    Ravikiran
    mail to me at : [email protected]

    "can i store the Result set values as a Session variable "
    Practically Yes u can
    but u want be able to accesses it in other pages
    u can try it and see
    the other thing u can do is store the values from the resultset in a object say vector and put vector in seesion and u can use this any where
    for e.g
    Vector v=new Vector();
    While(rs.next())
    v.addElement(rs.getString(1));
    v.addElement(rs.getString(2));
    session.putValue("myVector",v);
    now where u want to get it do this
    Vector myvec=(Vector)session.getValue("myVector");
    do do futher

  • 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

  • Fetching a partial range of selected result rows from the client side

    It has been a while since I started trying to solve this Oracle puzzle.
    Basically, what I need it is a way to fetch from the client side a run-time
    defined range of result rows of a arbitrary SELECT query.
    In low-end databases like MySQL I can do it simply by appending the LIMIT
    argument to the end of the SELECT query statment passing the number of
    the first row that I want to be returned from the server from the total
    result rows available in the result set and the maximum number of rows
    that it may return if available.
    In higher end databases I am supposed to use server side cursors to skip
    any initial rows before the first that I want to retrieve and fetch only
    the rows I want up to the given limit.
    I am able to achieve this with PostgreSQL and Microsoft SQL server, but I
    am having a hard time with Oracle. The main problem is how do I fetch
    result rows from a server side cursor and have their data returned to a
    client side in a result set like in a straight SELECT query?
    I was able to create a cursor and fecth a row into a server side record
    variable with the following PL/SQL code.
    DECLARE
    CURSOR c IS SELECT * FROM my_table;
    my_row c%ROWTYPE;
    BEGIN
    OPEN c;
    FETCH c INTO my_row;
    CLOSE c;
    END;
    I want to do this from PHP, so I don't have client side ESQL variables to
    store the result set data structure. Anyway, if I can do it just with
    SQLPlus I should be able to do it in PHP.
    If I do straight SELECT I can get the result set, but in a PL/SQL script
    like the one above I don't seem to be able to select the data in the
    fetched row record to have returned to the client. Does a straight SELECT
    query sends the result rows to a default client side variable?
    If anybody can help, I would appreciate if you could mail me at
    [email protected] because I am not able to access this forum all the time in
    the Web. BTW, is it possible to access this forum by e-mail?
    Thanks in advance,
    Manuel Lemos
    null

    Hello Jason,
    On 03-Feb-00 05:34:14, you wrote:
    I'm not sure I totally understand your problem, but I think you might be able
    to solve it by using the ROWNUM variable. ROWNUM returns the sequenc number
    in which a row was returned when first selected from a table. The first row
    has ROWNUM = 1, the second has ROWNUM = 2, etc. Just remember that the
    ROWNUM is assigned as soon as it's selected, even before an order by. So if
    you have an order by clause, it'll mess it up. Here's an example. I hope
    that helps.I though of that before but it doesn't help because if you use ORDER BY the
    first result row might not have ROWNUM=1 and so on. Another issue is that
    I want to be able to skip a given number of result rows before returning
    anything to the client.
    The only way I see to do it is to get the rows with server side cursor.
    But how do I return them to the client? Where does a normal select returns
    the rows? Isn't there a way to specify that the fetch or something else
    return the rows there?
    Regards,
    Manuel Lemos
    Web Programming Components using PHP Classes.
    Look at: http://phpclasses.UpperDesign.com/?user=[email protected]
    E-mail: [email protected]
    URL: http://www.mlemos.e-na.net/
    PGP key: http://www.mlemos.e-na.net/ManuelLemos.pgp
    null

Maybe you are looking for