Odd results from SQL statement in JSP

Hi.
Getting very strange results from my SQL statement housed in my JSP.
the last part of it is like so:
"SELECT DISTINCT AID, ACTIVE, REQUESTOR_NAME, ..." +
"REQUESTOR_EMAIL" +
" FROM CHANGE_CONTROL_ADMIN a INNER JOIN CHANGE_CONTROL_USER b " +
"ON a.CHANGE_CTRL_ID = b.CHANGE_CTRL_ID " +
  " WHERE UPPER(REQUESTOR_NAME) LIKE ? ";   I've set the following variables and statements:
String reqName = request.getParameter("requestor_name");
PreparedStatement prepstmt = connection.prepareStatement(preparedQuery);
prepstmt.setString(1, "%" + reqName.trim().toUpperCase() + "%");
ResultSet rslts = prepstmt.executeQuery();
rslts.next();
int aidn = rslts.getInt(1);          
int actbox = rslts.getInt(2);     String reqname = rslts.getString(3).toUpperCase();
String reqemails = rslts.getString(4);
String bizct = rslts.getString(5);
String dept = rslts.getString(6);
String loc = rslts.getString(7);
Date datereq = rslts.getDate(8);
String busvp = rslts.getString(9);
AND SO ONSo then I loop it, or try to with the following:
<%
  try {
  while ((rslts).next()) { %>
  <tr class="style17">
    <td><%=reqname%></td><td><%=reqemails %></td><td><%=bizct %></td>td><%=dept %></td>
   <td><%=aidn %></td>
  </tr>
  <%
rslts.close();
selstmt.close();
catch(Exception ex){
     ex.printStackTrace();
     log("Exception", ex);
%>AND so on, setting 13 getXXX methods of the 16 cols in the SQL statement.
Trouble is I'm getting wildly inconsistent results.
For example, typing 'H' (w/o quotes) will spit out 20 duplicate records of a guy named Herman, with the rest of his corresponding info correct, just repeated for some reason.
Typing in 'He' will bring back the record twice (2 rows of the complete result set being queried).
However, typing in 'Her' returns nothing. I could type in 'ell' (last 3 letters of his name, Winchell) and it will again return two duplicate records, but typing in 'hell' would return nothing.
Am I omitting something crucial from the while statement that's needed to accurately print out the results set without duplicating it and that will ensure returning it?
There's also records in the DB that I know are there but aren't being returned. Different names (i.e. Jennifer, Jesse, Jeremy) won't be returned by typing in partial name strings like Je.
Any insight would be largely appreciated.
One sidenote: I can go to SQL Plus and accurately return a results set through the above query. Having said that, is it possible the JDBC driver has some kind of issue?
Message was edited by:
bpropes20
Message was edited by:
bpropes20

Am I omitting something crucial from the while
statement that's needed to accurately print out the
results set without duplicating it and that will
ensure returning it?Yes.
In this code, nothing ever changes the value of reqname or any of the other variables.
  while ((rslts).next()) { %>
  <tr class="style17">
    <td><%=reqname%></td><td><%=reqemails %></td><td><%=bizct %></td>td><%=dept %></td>
   <td><%=aidn %></td>
  </tr>
  <%
} You code needs to be like this:while (rslts.next()) {
  reqname = rslts.getString(3).toUpperCase();
  reqemails = rslts.getString(4);
  bizct = rslts.getString(5);
  dept = rslts.getString(6);
  loc = rslts.getString(7);
  datereq = rslts.getDate(8);
  busvp = rslts.getString(9);
%>
  <tr class="style17">
    <td><%=reqname%></td><td><%=reqemails %></td><td><%=bizct %></td>td><%=dept %></td>
   <td><%=aidn %></td>
  </tr>
  <%
There's also records in the DB that I know are there
but aren't being returned. Different names (i.e.
Jennifer, Jesse, Jeremy) won't be returned by typing
in partial name strings like Je.Well, you're half-right, your loop won't display all the rows in the result set, because you call rslts.next(); once immediately after executing the query. That advance the result set to the first row; when the loop is entered, it starts displaying at the 2nd row (or later if there are more next() calls in the code you omitted).

Similar Messages

  • How to compare result from sql query with data writen in html input tag?

    how to compare result
    from sql query with data
    writen in html input tag?
    I need to compare
    user and password in html form
    with all user and password in database
    how to do this?
    or put the resulr from sql query
    in array
    please help me?

    Hi dejani
    first get the user name and password enter by the user
    using
    String sUsername=request.getParameter("name of the textfield");
    String sPassword=request.getParameter("name of the textfield");
    after executeQuery() statement
    int exist=0;
    while(rs.next())
    String sUserId= rs.getString("username");
    String sPass_wd= rs.getString("password");
    if(sUserId.equals(sUsername) && sPass_wd.equals(sPassword))
    exist=1;
    if(exist==1)
    out.println("user exist");
    else
    out.println("not exist");

  • Inserting your own sql-statements in JSP

    How do I use my own sql-statements in JSP combined with the ones
    generated by JDeveloper?
    It seems to me that the following sentences are the ones
    generating the sql for inserting in a database:
    <jbo:DataSource id="ds" appid="MimPKG.MimPKGModule"
    viewobject="BidragView"/>
    <jbo:Row id="newRow" datasource="ds" action="Create">
    <jbo:SetAttribute dataitem="*"/>
    </jbo:Row>
    I would like to have more control and therefore I need to make
    my own sql-statements.
    Is that possible?
    Thanks
    Leise

    You can use ExecuteSQL data tag to do so. It allows you to
    include your own query like insert, update etc.

  • Creating a DataTable from the results of SQL statement

    I am relatively new to VB 2005, ADO and Oracle db. I have perfected an SQL statement that joins 6 tables in an Oracle 10i database and the resulting set retunrs the correct data. I am having difficulty creating and inserting this resulting set into a datatable that could be used in my application. Could someone detail the steps needed to create and fill this table

    http://download.oracle.com/docs/cd/A91202_01/901_doc/appdev.901/a89856/06_ora.htm#1604
    The link above points to Oracle's documentation on using cursor variables. In a nutshell, you want to create a package that defines the cursor type and contains the procedure to open the cursor.
    create package my_package as
    type my_cursor_type is ref cursor;
    procedure my_procedure (out_cursor out my_cursor_type);
    end;
    create package body my_package as
    procedure my_procedure (out_cursor out my_cursor_type) is
    begin
         open my_cursor for
              select ...;
    end;
    end;Now you need to set up your .NET application to read the data.
    OracleConnection con = new OracleConnection("User Id=myuser;Password=mypassword;Data Source=mydatabase");
    OracleParameter[] parms = new OracleParameter[1];
    parms[0] = new OracleParameter("table1_cursor", OracleDbType.RefCursor, ParameterDirection.Output);
    OracleCommand cmd = new OracleCommand("my_package.my_procedure", con);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddRange(parms);
    DataTable myTable = new DataTable();
    OracleDataAdapter da = new OracleDataAdapter(cmd);
    da.Fill(myTable);

  • Populating JTable table from sql statement.

    Trying to teach myself a combanation of things. Since Oracle is my background java to oracle is only a natural. Now this code I'm trying to select some rows and then display those rows in a table. Simple concept as a teaching aid to me. I won't go into what I went through to get this far, just say there have been quite a few fall starts. Now this code works; however it returns ten rows (one for each tablespace) and displays row 1 ten times. Not quite what I had in mind.
    I have got a simple select statment in my code:
    select tablespace_name,initial_extent,next_extent,pct_increase, status
    from dba_tablespaces order by tablespace_name
    package TableTest;
    // java imports
    import java.util.Vector;
    import java.awt.event.*;
    import java.awt.Toolkit;
    import java.awt.*;
    import javax.swing.*;
    // sql imports
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.sql.PreparedStatement;
    import java.sql.Connection;
    import java.sql.DriverManager;
    public class TableTest extends JFrame
      Connection conn;  // database connection object
      Statement stmt;   // statement object
      ResultSet rslt;   // result set object
      //private vars
      private String userName         = "bubbalouie";
      private String password         = "helpmeimsinking";
      private String sid              = "rob";
      private String port             = "1521";
      private String server           = "w2sd001";
      private String connectString    = "jdbc:oracle:thin:@"+server+":"+port+":"+sid;
      private int numCols             = 5;
      private String sqlStmt          = null;
      private String status           = null;
      public TableTest()
        // Get content pane
        Container contentPane = getContentPane();
        // set layout manager
        contentPane.setLayout(new BorderLayout());
        // create some places to put dat
        Vector data    = new Vector();
        Vector columns = new Vector();
        Vector colHeads = new Vector();
        colHeads.addElement("tablespace name");  // this is ugly fix later
        colHeads.addElement("initial extent");
        colHeads.addElement("next extent");
        colHeads.addElement("pct increase");
        colHeads.addElement("status");
        // construct a simple sql statement
        sqlStmt = "select  tablespace_name, initial_extent, next_extent, pct_increase, status";
        sqlStmt = sqlStmt+" from dba_tablespaces order by tablespace_name";
        try
          // connect to database
          DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
          Connection conn = DriverManager.getConnection(connectString, userName, password);
          // select data into object
          stmt = conn.createStatement();
          rslt = stmt.executeQuery(sqlStmt);
          while (rslt.next())
            for ( int i=0; i<numCols; i++ )
              columns.addElement(rslt.getObject(i+1));  // get the i+1 object
            }  // end for
            data.addElement(columns);
          }    // end while
          // create the table
          JTable table = new JTable(data,colHeads);
          // add table to scroll pane
          int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
          int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
          JScrollPane jsp = new JScrollPane(table,v,h);
          // Add scroll pane to content pane
          contentPane.add(jsp, BorderLayout.CENTER);
        } catch (SQLException ex)
          String msg = "SQL error: "+ex.toString();
        } catch (Exception ex)
          String msg = "Error: "+ex.toString();
      }                                     // end constructor
      public static void main(String[] args) {
          TableTest frame = new TableTest();
          frame.setSize(500, 400);
          frame.setTitle("TableTest");
          frame.setVisible(true);
    }  // TableTest end class

    if you are interested here is a generic table model for displaying ResultSets in a JTable. The resultset needs to support calling resultset meta data and the basic methods in there but then it should support anything you give it.
    import java.sql.*;
    import java.util.*;
    import javax.swing.table.*;
    public class ResultSetTableModel extends AbstractTableModel{
      Vector rows;          
      int[] types;          
      String[] names;     
      public ResultSetTableModel(ResultSet rs)throws SQLException{
        ResultSetMetaData rsmd = rs.getMetaData();          
        types = new int[rsmd.getColumnCount()];          
        names = new String[rsmd.getColumnCount()];          
        for(int n=0;i<types.length;n++){               
          types[n] = rsmd.getColumnType(n+1);
          names[n] = rsmd.getColumnName(n+1);     
        rows = new Vector();
        while(rs.next()){
          Vector aRow = new Vector();
          for(int j=0;j<types.length;j++){
               switch(types[j]){
              case Types.TINYINT:
                aRow.addElement(new Byte(rs.getByte(j+1)));
                break;
              case Types.SMALLINT:
                aRow.addElement(new Short(rs.getShort(j+1)));
                break;
                 case Types.INTEGER:
                   aRow.addElement(new Integer(rs.getInt(j+1)));
                   break;
                 case Types.BIGINT:
                   aRow.addElement(new Long(rs.getLong(j+1)));
                   break;
                 case Types.REAL:
                   aRow.addElement(new Float(rs.getFloat(j+1)));
                   break;
                 case Types.FLOAT:
                   aRow.addElement(new Double(rs.getDouble(j+1)));
                   break;
                 case Types.DOUBLE:
                   aRow.addElement(new Double(rs.getDouble(j+1)));
                   break; 
                 case Types.DECIMAL:
                   aRow.addElement(rs.getBigDecimal(j+1));
                   break;
                 case Types.NUMERIC:
                   aRow.addElement(new Long(rs.getLong(j+1)));
                   break;
                 case Types.BIT:
                   aRow.addElement(new Boolean(rs.getBoolean(j+1)));
                   break;
                 case Types.BINARY:
                   aRow.addElement(rs.getBytes(j+1));
                   break;
                 case Types.DATE:
                   aRow.addElement(rs.getDate(j+1));
                   break;
                 case Types.TIME:
                   aRow.addElement(rs.getTime(j+1));
                   break;
                 case Types.TIMESTAMP:
                   aRow.addElement(rs.getTimestamp(j+1));
                   break;           
                 default:
                   aRow.addElement(rs.getString(j+1));
          rows.addElement(aRow);           
      public Class getColumnClass(int column){
        switch(types[column]){
          case Types.BIT:
            return Boolean.class;
          case Types.DATE:
            return java.sql.Date.class;
          case Types.TIME:
            return java.sql.Time.class;
          case Types.TIMESTAMP:
            return java.sql.Timestamp.class;
          default:
            return Object.class;     
      public int getRowCount(){
        return rows.size();     
      public int getColumnCount(){
        return types.length;     
      public Object getValueAt(int row, int column){
        Vector aRow = (Vector) rows.elementAt(row);
        return aRow.elementAt(column);
      public String getColumnName(int column){
        return names[column];
    }

  • Can you use nested sql statements in jsp??

    HI, I was wondering if you can use nexted sql statements...
    example...
    <%@ page language="java" contentType="text/html" %>
    <%@ page import="java.sql.*" %>
    <%@ page import="forum.DataAccess" %>
    <%
         // Create a new instance of the DataAccess Class
              DataAccess d = new DataAccess();
         // This call the database connection method from the DataAccess Class
              d.ConnectDatabase();
         /* This gets the threads from database for the categories */
              // This is initilzing the variables
                   String threadname = null;
                   int threadid = 0;
              // This sets the sql variable to nothing
                   String sql = "";
                   String sql1 = "";
              // This sets the rs variable to null
                   ResultSet rs = null;
                   ResultSet rs1 = null;
              // This is doing a SELECT on the thread table based on the category id
                   sql += "select * from forum_threads where ft_catid = 2";
                   rs = d.SQLQuery(sql);
         /* End of categories */
         while (rs.next()){
                                       threadid = rs.getInt("ft_threadid");
                                       threadname = rs.getString("ft_threadname");
         sql1 += "select * from forum_messages where fm_catid = 2 and fm_threadid = " + threadid + "";
         rs1 = d.SQLQuery(sql1);
    %>
    THis is the error I get.....
    javax.servlet.ServletException: [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt
    I know what that is.. it is because I am trying to open another result set before the first one is closed... but I need that one open cause I need to loop through the ids and run it against the second query??
    Any suggestions...

    I am not positive but it seems from your error message you will not be able to use the nested SQL. Another option would be to store the values of the ResultSet in a Vector (or Array), and then close your ResultSet and loop through the vector or array instead...
    Zac

  • Get Comma separated result from SQL Query

    Hey Everyone
    I have a requirement where i need to get comma separated result of names because there is one to many relationship i.e for every protocol there are mutiple people associated to it , and i created PL/SQL function for that and everything was fine and when it is in production multiple number of cursors were opened because of the logic and leading to RAC fail over and for that we were manually clearing the cursors every weekend and i am looking to create a Materialized view for this logic but i was unable to code the logic using Connect by clause
    Result is like and i want comma separated names for every protocol
    P06065     TESTER13 TESTER13
    P02095     PATRICIA CARMELITANO
    P02095     ANNE MUIR
    P02095     ROBERT HARLOW
    P02095     JANICE ALBERT
    P02095     Jacqueline van Dalen
    P02095     GUENTER HENNIG DR.
    P05209     Olga Xenaki
    P05553     Birgit Limbach-Angele
    P05553     Anja Schulz Dr.
    P05553     CHRISTA HAGENBUCHER
    here is the function which i wrote, i need to get the same logic through SQL Statement .. thanks for your help
    cursor c_GSCR is
    select T565804.FST_NAME||' '||T565804.LAST_NAME
    from
    S_PT_POS_HST_LS T544105 /* S_PT_POS_HST_LS_Protocol_Team */ ,
    S_CONTACT T565804 /* S_CONTACT_Protocol_Team */,
    S_CL_PTCL_LS T541903 /* S_CL_PTCL_LS_Protocol */
    where ( T541903.ROW_ID = T544105.CL_PTCL_ID and
    T544105.POSTN_ID = T565804.PR_HELD_POSTN_ID and
    T544105.ROLE_CD = 'Lead Project Manager' AND
    T541903.ROW_ID = v_PTCL_ID and
    T541903.PAR_PTCL_ID is null and T544105.END_DT is null );
    BEGIN
    l_row_num := 0;
    l_role := '';
    l_role_list := '';
    v_PTCL_ID := PTCL_ID;
    OPEN C_GSCR;
    if C_GSCR%isopen THEN
    LOOP
    FETCH C_GSCR INTO l_role;
    exit when C_GSCR%notfound;
    IF l_role_list IS NULL THEN
    l_role_list:=l_role;
    ELSE
    l_role_list:=l_role_list||', '||l_role;
    END IF;
    END LOOP;
    CLOSE C_GSCR;
    end if;
    ~Srix

    Hi,
    Srix wrote:
    Thanks for the Info .. My database in 10g R 2 i started using COLLECT Function
    select T541903.PTCL_NUM ,
    CAST(COLLECT(T565804.FST_NAME||' '||T565804.LAST_NAME) AS varchar2_ntt) , 7) AS LPM_NAME
    from
    S_PT_POS_HST_LS T544105 /* S_PT_POS_HST_LS_Protocol_Team */ ,
    S_CONTACT T565804 /* S_CONTACT_Protocol_Team */,
    S_CL_PTCL_LS T541903 /* S_CL_PTCL_LS_Protocol */
    where T541903.ROW_ID = T544105.CL_PTCL_ID and
    T544105.POSTN_ID = T565804.PR_HELD_POSTN_ID and
    T544105.ROLE_CD = 'Lead Project Manager' AND
    T541903.PAR_PTCL_ID is null and T544105.END_DT is null
    GROUP BY T541903.PTCL_NUM
    The result i like ...Do you mean "The result *is* like ..."?
    Or do you mean "The result I [would] like [is] ..."?
    The code above has unblanaced parentheses. If you are getting anything other than an error message, then I don't believe you are really running what you posted.
    Whenever you have a problem, post a complete test script that people can use to recreate the problem and test their ideas.
    Please do that. Post CREATE TABLE and INSERT statements to crate the sample data, the code you used to create the carachr2_ntt type and the function, and your best attempt at a query (formatted). Simplify as much as possible. For example, do you really need 3 tables to illustrate the problem? For purposes of asking a question on this forum, can't you pretend you have just one table, with 2 columns?
    I suspect the problem has to do with the user-defined type and function, which you didn't post. I can't even see how you called the function in your query. Without the information I mentioned above, there's not much I can do to help you.

  • Whitespace in xml result from SQL Utility

    We're currently using the XML SQL Utility (ver XSU12, 8.1.7 database) with PL/SQL. We're able to successfully retrieve XML based result from the database.
    However, almost a fourth of the document that's returned from the utility in CLOB is whitespace, which is not necessary in our application. Is there any way we can suppress this whitespace, so that the resulting document trasferred over the network is kept the smallest possible.
    Thanks in advance
    Murthy Jarugumilli

    Use one of the XPath string functions. I don't have my reference book here but the one you want is called something like normalize-text, so look it up in your reference. Your element would then look something like this:
    <xsl:value-of select="/results/record[normalize-text(id)=12]"/>

  • Convert a logic from SQL statement to java

    Hi.,
    I m using jdeveloper 11.1.1.5
    I had used one sql statement as gievn below
    (SELECT max(decode(LENGTH(fy_year),4, fy_year + 1,6,SUBSTR(fy_year, 1, 4)+1||SUBSTR(SUBSTR(fy_year, 1, 4) + 2, 3, 2)))YEAR from fin_years)I need to use this logic in java
    Could anyone pls help me

    "wilhelm,"
    I've seen some ridiculous questions in my life. This is one of them.
    There are just so many things wrong here. So, so many.
    SELECT statements get data from databases; they are not "logic."
    Do you really expect us to parse your SQL and try to guess what it is supposed to do?
    Do you really believe that when converting a Forms app to Java that you "convert" SQL statements to Java?
    Do you really believe that going through your forms app and "converting" it to ADF is a sensible approach?
    John

  • DropDownList using result in sql statement

    hi
    i made a dropdownlist in which i get the data from a sql table.
    when i select a date i wanna press a button and this button starts a procedure which is creating a view on a table in which the where statement is the result of the selected item in the drop down box
    how do i get the selected item in my procedure?
    thanks a lot
    Falk

    ok my problem is how do i get the selected item in this :P1_DATE?
    do i have to declare it anywhere? where do i have to write the var into?
    i am a completely beginner so plz give me a simple how to
    ok i think ur :P1_DATE is the name of my dropdown menu
    so if i try this method i get an error "Bindevariables are not allowed for data definition operations
    i have to creat a view of the table because the table contains more than 100.000 entries and if i want to search s.th. i takes about 4 sec
    i want to do a pre selection with the view so people can select a date in the dop down menu and then the createtd view will contain about 400 entries and if u search in the new view it takes only 1 sec
    i also want to do this because of performing the database
    sorry for my english, hope u will understand all
    Edited by: user10247044 on 19.09.2008 07:11

  • 404 and other odd results from 11.2 docs in tahiti

    Just an observation, searching on things like pga at tahiti.oracle.com then clicking on 11.2 results gives 404 errors. Clicking on the 11.2 docs then searching gives not found errors. No problems with other versions. I optimistically take this as a sign that someone is updating the doc set. But it would seem odd to update at 11:00AM on a workday.

    user13312943 wrote:
    Hi,
    I would like to test downgrade process through the scripts (@catdwgrd.sql). Oracle documentation http://docs.oracle.com/cd/E18283_01/server.112/e17222/downgrade.htm
    says
    "2.If you previously installed a recent version of the time zone file and used the DBMS_DST PL/SQL package to upgrade TIMESTAMP WITH TIME ZONE data to that version, then you must install the same version of the time zone file in the release to which you are downgrading. For example, the latest time zone files that are supplied with Oracle Database 11g Release 2 (11.2) are version 14 as of this printing. If after the database upgrade, you had used DBMS_DST to upgrade the TIMESTAMP WITH TIME ZONE data to version 14, then install the version 14 time zone file in the release to which you are downgrading. This ensures that your TIMESTAMP WITH TIME ZONE data is not logically corrupted during retrieval. To find which version your database is using, query V$TIMEZONE_FILE"
    1) In my case, I used DBMS_DST and now the version if the time zone file is 14. If I have to go back to 10.2.0.4, Should i copy the files to $ORACLE_HOME/ORACORE/ZONEINFO (where $ORACLE_HOME is 10.2.0.4)?
    No - you should not copy files from the 11gR2 HOME to the 10.2.0.4 HOME - instead apply patch 9742718 to the 10.2.0.4 HOME (which corresponds to v14 of the DST patch)
    Updated DST transitions and new Time Zones in Oracle Time Zone File patches [ID 412160.1]
    2) If my Oracle 10.2.0.4 is shared with multiple instances, will i introduce risk for other databases running on the same oracle home when I copy the files?
    You will need to follow steps in 9742718 for all of the databases running out of the 10.2.0.4 HOME
    3) What other steps should I do other than copying the version 14 files into this directory?
    See above
    Thank You
    SarayuHTH
    Srini

  • Small problem: SQL statement in JSP

    Hello, I have the following problem: I have an SQL-expression like this:
    SELECT * FROM tablename WHERE ...
    In the WHERE clausule I have to refer to a variable, like this:
    String varname = "abcde"
    "SELECT * FROM tablename WHERE attribute = varname";
    This doesn't work, also when I put the " before the referral to varname. In that way I get an error that there is a semicolon expected...
    Can anybody help me with this ??
    Thanx, Erik.

    String varname = "abcde";
    "SELECT * FROM tablename WHERE attribute = ' "+ varname + " ' ";
    Since u are passing a string value from outside it needs to be enclosed in single coats....use the select statement like shown above it will work....

  • Different Results from SQL-Query in Oracle 10.2 and  Oracle 11.2

    Look at the following example:
    CREATE TABLE GZP_PLAN (GZP_ID
    NUMBER(9) NOT NULL, PARENT_GZP_ID NUMBER(9),
    CONSTRAINT GZP_PLAN_PK1 PRIMARY KEY(GZP_ID)
    USING INDEX
    TABLESPACE USERS
    TABLESPACE USERS;
    insert into GZP_PLAN values(1,NULL);
    CREATE TABLE GZP_WB (OBJECTID NUMBER
    NOT NULL, GZP_ID NUMBER(10),
    CONSTRAINT GZP_WB_PK1_1 PRIMARY KEY(OBJECTID)
    USING INDEX
    TABLESPACE USERS
    TABLESPACE USERS;
    insert into GZP_WB values(1,1);
    CREATE OR REPLACE VIEW VW_GZP (GZP_ID1) AS
    SELECT xxx.gzp_id
    FROM gzp_plan xxx
    WHERE gzp_id IN (
    SELECT MAX (z.gzp_id) zzz
    FROM gzp_plan z
    START WITH z.gzp_id = xxx.gzp_id
    CONNECT BY PRIOR gzp_id = parent_gzp_id);
    -- query
    select a.* from GZP_WB a where gzp_id in (select gzp_id1 from vw_gzp);
    Result in Oracle 10.2. (Windows Server 2003 32-bit, Oracle 10.2.0.2 or Oracle 10.2.0.5, Enterprise Edition)
    OBJECTID     GZP_ID
    *1 1*
    Result in Oracle 11.2 (Windows Server 2008 64-bit, Oralcle 11.2.0.2, Enterprise Edition or Standard Edition One)
    no rows selected
    The result of the following queries are identical in Oracle 10.2 and 11.2
    SQL> select * from GZP_WB where to_char(gzp_id) in
    2 (select to_char(gzp_id1) from vw_gzp);
    OBJECTID GZP_ID
    1 1
    SQL>
    SQL> select a.* from GZP_WB a, vw_gzp b where a.gzp_id=b.gzp_id1;
    OBJECTID GZP_ID
    1 1

    The solution is Oracle 11.2.0.3 - patchset released 11th November.

  • Creating JTree with results from SQL Query

    I have the following source in SQLJ:
    String temp=null;
    iter1 it1;
    iter2 it2;
    #sql it1={select id,fdn,level from groups connect by prior fdn=parent_fdn start with fdn='/' };
    while(it1.next())
    System.out.println(it1.id()); // Display Parent
    temp=it1.fdn();
    #sql it2= {select clli from nes where parent_fdn=:temp order by clli };
    while(it2.next())
    System.out.println(it2.clli());//Display Child of above Parent if any
    My problem is to construct a Tree GUI using JTree from the above
    code with the same hierarchy of parent-child relationship.
    I have tried every possible solution using Vectors,Hashtables,String Arrays etc but have not come up with a successful solution so far
    IF ANYONE HAS A SOLUTION PLEASE HELP ME WITH AN EXAMPLE.
    Thank You
    Sharath

    sharathkv,
    Your issue seems to be in figuring out an algorithm to convert row-based SQL resultsets to a hierarchical data structure suitable for display in a tree.
    Run the jython (www.jython.org) app below: it simulates doing just that. jython is indentation-sensitive, so you'll need to exercise care when copying. If copy-paste to a text editor doesn't work, copy-paste to a HTML-aware editor (even Outlook Express, if on Windows), then copy from there and paste in a text editor.
    --A
    This is a jython (www.jython.org) app that illustrates
    converting row-based data (eg. a SQL resultset) to a custom
    hierarchical data structure, and displaying it in a JTree.
    from javax.swing import *
    from javax.swing.tree import *
    import java
    def getSQLRows():
        Simulates a SQL resultset.
        Columns fdn and parent-fdn indicate parent/child relationships.
        rows = [
            # id, fdn, parent-fdn, level
              [1, '/', None, 1]
            , [2, '/fruits', '/', 2]
            , [3, '/colors', '/', 2]
            , [4, '/sports', '/', 2]
            , [5, '/fruits/apples', '/fruits', 3]
            , [6, '/fruits/oranges', '/fruits', 3]
            , [7, '/colors/red', '/colors', 3]
            , [8, '/colors/blue', '/colors', 3]
            , [9, '/sports/petanc', '/sports', 3]
            , [10, '/sports/rugby', '/sports', 3]
        return rows
    def convertRowsToHierarchy(rows):
        Converts row-based results to hierarchical structure.
        Uses known parent/child relations present in rows.
        root = None
        for row in rows:
            fdn, parentfdn = row[1], row[2]
            node = SQLTreeNode(fdn, parentfdn)
            if root:
                root.addEx(node)
            else:
                root = node
        return root
    class SQLTreeNode(java.lang.Object):
        '''Custom tree node; displayed in JTree'''
        def __init__(self, fdn, parentfdn):
            self.fdn = fdn
            self.parentfdn = parentfdn
            self.nodes = []
        def add(self, node):
            '''Adds node as immediate child'''
            self.nodes.append(node)
        def addEx(self, node):
            '''Adds-with-search.  NOTE: naive implementation'''
            if self.fdn == node.parentfdn:
                self.add(node)
            else:
                for child in self.nodes:
                    child.addEx(node)
        def toString(self):
            return self.fdn
        def dump(self):
            '''Debug routine to dump hierarchy'''
            print 'fdn=%s, parentfdn=%s' % (self.fdn, self.parentfdn)
            for node in self.nodes:
                node.dump()
    class SQLTreeModelAdapter(TreeModel):
        '''Tree model adapter: adapts custom data structure to TreeModel'''
        def __init__(self, root):
            self.__root = root
        def getChild(self, parent, index):
            return parent.nodes[index]
        def getChildCount(self, parent) :
            return len(parent.nodes)
        def getIndexOfChild(self, parent, child):
            return parent.nodes.index(child)
        def getRoot(self) :
            return self.__root
        def isLeaf(self, node):
            return len(node.nodes) == 0
        def addTreeModelListener(self, l):
            pass
        def removeTreeModelListener(self, l):
            pass
        def valueForPathChanged(self, path, newValue):
            pass
    class SQLTreeDemo(JFrame):
        Tree demo UI
        Displays a tree displaying [hierarchical] results
        of a BOM-type SQL query
        def __init__(self):
            # Get matrix simulating SQL resultset
            rows = getSQLRows()
            # Convert to custom hierarchical data structure
            root = convertRowsToHierarchy(rows)
            model = SQLTreeModelAdapter(root)
            tree = JTree(model)
            sp = JScrollPane(tree)
            self.contentPane.add(sp)
            self.size = 200, 300
    if __name__ == '__main__':
        s = SQLTreeDemo()
        s.visible = 1

  • How to get accurate results from sql code ?

    Hello everybody,
    I have a problem with some portion of my code.
    I get more results than I specify in the where clause.
    Here is the sample code:
    c.gl_acct_id between '110'||'-'||'6890'||'-'||'69000'||'-'||'%'
    and '110'||'-'||'7000'||'-'||'67999'||'-'||'%'
    For some reason I also get the following results back:
    110-6910-51001-001, and 110-6910-51003-001 But I don't need the 51001 and 51003. How do I specify in sql what range I really want. I was sure that the code above is correct. I guess not.
    I would appreciate any help,
    Thanks,
    Sonya

    Have you tried using the query either of the following...
    1) c.gl_acct_id between '110-6890-69000-000'
    and '110-7000-67999-999'
    and c.gl_acct_id not like '110-6910-51001-%'
    and c.gl_acct_id not like '110-6910-51003-%'
    assuming you have only 3 digits at the end of gl_acct.
    2)If you know that your acct_id belongs to only 69000 or 67999
    then
    (c.gl_acct_id LIKE '110-6890-69000-%' OR
    c.gl_acct_id LIKE '110-7000-67999-%' )
    Plz. let me know if this not what you are looking for.
    thanx
    rajkiran
    Here is the whole script:
    select distinct c.gl_acct_id acct_no,
    c.gl_acct_desc,
    min(a.local_act_beg_bal) local_act_beg_bal,
    sum(b.local_act_mtd_dr_amt) debits,
    sum(b.local_act_mtd_cr_amt) credits,
    nvl(min(a.local_act_beg_bal),0)+sum(nvl(b.local_act_mtd_dr_amt,0))-
    sum(nvl(b.local_act_mtd_cr_amt,0)) end_bal
    from gl_acct c, gl_acct_bal a, gl_acct_bal b
    where c.org_unit_id = '110'
    and b.gl_acct_id = c.gl_acct_id
    and a.gl_acct_id = c.gl_acct_id
    and c.sum_det_ind = 'D'
    and c.gl_acct_class_ind in ( 'A' , 'L' , 'Q' , 'I' , 'E' )
    and a.year_no = '2001'--:loyear
    and a.period_no = '1'--:loperiod
    and ( ( b.year_no = '2001'--:hiyear
    and b.period_no between '1'--:loperiod
    and'13')-- :hiperiod
    and c.gl_acct_id between '110'||'-'||'6890'||'-'||'69000'||'-'||'%'
    and '110'||'-'||'7000'||'-'||'67999'||'-'||'%'
    group by c.gl_acct_id, c.gl_acct_desc
    I want to have ability to specify ranges for gl_accoount.
    Thanks,
    Sonya

Maybe you are looking for

  • Itunes update to firmware fails, because connection times out.

    I have been unsuccessfully attempting to update my iphone 3gs and ipad to iOS 5 for over a month now.  I have spent many, many hours on this, and many phone calls to apple support.  I disable Norton 360, and windows firewall, and my firewall on my ro

  • Any more update for Nokia N8 after belle refresh??...

    Hello guys...great work on your part for providing new updates for nokia n8.... Its really great on your part...now my phone is fantastic... Just wanted to know if Nokia is planning to release new updates for the N8, after Belle Refresh?? If new upda

  • Published site won't load. Are my video files too big?

    I'm a video editor and have published a site through iWeb. I have about 8 movie files on the site. The site never fully loads. Are my video files too big? If so, what would you recommend the average MB's should be?

  • AP server client connection on SoH with System Replication

    Hi Experts I'm using Business Suite on HANA with  System Replication for HA purpose. As client access from ABAP server to HANA DB, I use DNS redirection. When I takeover to secondary system & after DNS redirection, the working process of user client

  • I've lost my ipod

    Now I've gone and lost my ipod somewhere i have the serial number but i cant use icloud because i have win. XP with service pack 3 plz some one help soon