Facing problem in constructing a sql query

I want a SQL Query through which I can Select all the values in a column of a table( which is Primary Key and another field in the table refers this field) I want to select all the values of the primary key which are either reffered by a particular value of the referring field or all the parents corrosponing to the value or their parents or their parents.... until I get a value which doen't refers any value.

I want a SQL Query through which I can Select all the values in a column of a table( which is Primary Key and another field in the table refers this field) I want to select all the values of the primary key which are either reffered by a particular value of the referring field or all the parents corrosponing to the value or their parents or their parents.... until I get a value which doen't refers any value. Hi
Did u try using Self Join
I think that might solve the problem
Sri

Similar Messages

  • How to construct a sql query when field having single quote

    Hi all,
    I have been working on web application , here is my requirement:
    I'm constructing sql statement dynamically from dynamic user input (form data). In one of the field having single quote.
    while executing the query it is getting problem because of single quote .. so how do i resolve my problem.
    single quote should be there. (I'm using Ms-Access as my database).
    Thanks in advance
    abel

    Use PreparedStatement. Always. It not only eases setting Java objects in a SQL query, but also protects you against SQL injections.
    Prepare yourself: [http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html].

  • Storing data filters to construct a SQL query

    Hi, this is the picture:
    I have list or table of data object, they are shown in more detail in another panel as an action occurs (mouse / keys). The objects of that list or table are fetch from a db. What I would like to do is create some user based filters of many fields to the fetch data and also store the filters so other users may use them. To add some more complexity I would also like to be able to group various filters.
    The approaches that I am thinking about would be to store a hash table<db Filed, Criteria> for each filter (a filter may have many criterias). Based on the hashtable a SQL Query can be build.
    To join or group various filters I would use union/except or sub queries (have not decided).
    This brings me to ask for some advise, is their any patterns or libs for this and if someone else has done something similar and would like to share his approaches or logic they will be very welcomed.
    Thanks
    Billy

    Hi Billy,
    I have come across a similar scenario.
    I need to develop a way to store, retrieve and use user defined filter criteria.
    I see that you were developing a similar design in March this year.
    Can you please let me know how did you do it.
    Thanks,
    Chetan Jindal.

  • Problem with parameter and sql query

    I've a problem with te query of my report. The query is:
    SELECT [DESCRIPTN]
          ,[LOGTIME]
          ,[STATUS]
          ,[CARDNO]
          ,[LOGDATE]
    FROM [Granta5P0].[dbo].[TIMELOG32]
    where cardno in ({?cardNo})
    the parameter as multiple values checked so I can query for more than one card.
    If i put just one parameter everything works fine but when I put 2 or more I have his error
    [http://www.megagaleria.com/pictures/Pic_10074_25.jpg]
    I realized that the field as no ' delimiting the parameters, I have a function that already does it but I don't know how to put it in my sql command.
    If anyone can help I appreciate

    Yes, because your parameter is only looking for one card.
    where cardno in ({?cardNo})
    Will you only be creating querys on two cards or less ?
    Are you trying to create an Array?
    If two or less you could
    where cardno = ({?cardNo}) or cardno = ({?cardNo2})

  • Problem populating textfields from sql query

    As seen in the code below I pass a String and a database connection to the constructor of this class. If I use the query commented out in the code the connection works fine and the values text fields get populated with the data. However if I use the uncommented query, the connection fails and so the query is not executed.(Connection code included as well)
    Anyone have any ideas why???
    public invInfoPanel(String name, DBConnection db)
              try
                   this.setBorder(
                        BorderFactory.createCompoundBorder(
                             BorderFactory.createCompoundBorder(
                                                 BorderFactory.createEtchedBorder(),
                                                 BorderFactory.createEmptyBorder(2,2,2,2)),
                             this.getBorder()));
                   panel1 = new JPanel();
                   panel1.setLayout(new GridLayout(0,2,10,10));
                   nameLabel = new JLabel("Name ");
                   panel1.add(nameLabel);
                   nameText = new JTextField(15);
                   panel1.add(nameText);
                   deptLabel = new JLabel("Dept ");
                   panel1.add(deptLabel);
                   deptList = new JComboBox(deptStrings);
                   deptList.setBackground(Color.white);
                   panel1.add(deptList);
                   extLabel = new JLabel("Ext ");
                   panel1.add(extLabel);
                   extText = new JTextField(15);
                   panel1.add(extText);
                   panel2 = new JPanel();
                   panel2.setLayout(new GridLayout(0,1,2,10));
                   saveButton = new JButton("Save");
                   panel2.add(saveButton);     
                   printButton = new JButton("Print ");
                   panel2.add(printButton);
                   cancelButton = new JButton("Cancel");
                   panel2.add(cancelButton);
                   panel3 = new JPanel();
                   blankLabela = new JLabel(" ");
                   panel3.add(blankLabela);
                   panel3.setLayout(new GridLayout(0,4,2,10));
                   searchButton = new JButton("Search by");
                   panel3.add(searchButton);
                   searchList = new JComboBox(searchStrings);
                   searchList.setBackground(Color.white);
                   panel3.add(searchList);
                   blankLabel = new JLabel(" ");
                   panel3.add(blankLabel);
                   this.add(panel1, BorderLayout.WEST);
                   this.add(panel3, BorderLayout.CENTER);
                   this.add(panel2, BorderLayout.EAST);
                   query = ("select STAFF_NAME, DEPT, EXT from INV_DETAILS where STAFF_NAME = " + name);
    //query = ("select STAFF_NAME, DEPT, EXT from INV_DETAILS where EXT = 320);
                   rs = db.runQuery(query);
                   display(rs);
              catch(java.sql.SQLException e)
                   System.out.println("Could not connect");
         public void display(ResultSet rs)
    try
              if(rs != null)
                   if(rs.next())
                        nameText.setText(rs.getString("STAFF_NAME"));
                        deptList.setSelectedItem(rs.getString("DEPT"));
                        extText.setText(rs.getString("EXT"));
              else
                   System.out.println("No record found");
         catch ( SQLException sqlex )
              System.out.println("*** Details Not In Database ***" );
    //----------------DBConnection.java----------------------//
    import java.sql.*;
    import java.util.*;
    public class DBConnection
    static String url =
    "jdbc:oracle:thin:@kiwi.isg.computing.dcu.ie:1521:kiwi";
    String username = getUser();
    String password = getPass();
    static String driver = "oracle.jdbc.OracleDriver";
    Connection connection;
    String status = "Not Connected";
    public DBConnection()
    try
    Class.forName(driver);
    status = "Found Oracle driver, starting to connect...";
    catch (java.lang.ClassNotFoundException e)
    status = "Driver not found";
    return;
    try
    connection = DriverManager.getConnection(url,username,password);
    status = "Connected to Oracle";
    catch(java.sql.SQLException e)
    status = "Could not connect";
    public String getStatus()
    return status;
         public static String getPass()
              String a;
              ResourceBundle myResources1 = ResourceBundle.getBundle("info");
              a = myResources1.getString("password");
              return a;
    public static String getUser()
              String b;
              ResourceBundle myResources1 = ResourceBundle.getBundle("info");
              b = myResources1.getString("username");     
              return b;     
    public ResultSet runQuery(String s) throws java.sql.SQLException
    Statement stmt = connection.createStatement();
    System.out.println(s);
    return stmt.executeQuery(s);
    }

    Actually...got it sorted out. Thanks anyway

  • Facing problem in parameters of the Query

    Hi All,
    I made 1 query through query generation ..... The Query withput parameters is working fine but when i have applied selection criteria's like Date wise,Item Wise,Document wise,sales employee wise it is getting executed only when all the parameters are put but it should actually work in either or & also end condition & also wiithout parameters .the query which i tried is given below:---
    *SELECT T1.[ItemCode], T0.[DocDate], T0.[CardName], T0.[DocNum], T1.[U_BARCODE], T1.[U_Pu], T1.[U_Pcs], T1.[U_GRWT], T1.[Quantity],T0.[DocTotal], T2.[SlpName] FROM [dbo].[OINV]  T0 INNER JOIN [dbo].[INV1]  T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OSLP T2 ON T0.SlpCode = T2.SlpCode, CRD1 T3 WHERE ((T0.DocDate >= '[%0]' and T0.DocDate <= '[%1]') or ('[%0]' = '' and '[%1]' = '')) and (T0.CardName= '[%6]' or '[%6]' = '') AND  (T1.ItemCode ='[%2]' or '[%2]' = '') and ((T0.DocNum >= '[%3]' and T0.DocNum <= '[%4]') or ('[%3]' = '' and '[%4]' = '')) and (T1.[u_BARCODE]='[%5]' or '[%5]' = '') AND  ( T2.[SlpName] ='[%7]' or '[%7]' = '') and  (  T3.[City] ='[%8]' or '[%8]' = '')*
    T & R -
    mona

    hai!
    declare @fromDate Datetime
    declare @todate datetime
    set @fromDate = (select min(s0.DocDate) from OINV s0 where s0.Docdate >='[%0]')
    set @todate = (select max(s1.docdate) from OINV s1 where s1.Docdate <='[%1]')
    SELECT T1.ItemCode, T0.DocDate, T0.CardName, T0.DocNum, T1.U_BARCODE, T1.U_Pu, T1.U_Pcs, T1.U_GRWT, T1.Quantity,T0.DocTotal, T2.SlpName FROM dbo.OINV T0 INNER JOIN dbo.INV1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OSLP T2 ON T0.SlpCode = T2.SlpCode, CRD1 T3 WHERE ((T0.DocDate >= @fromdate and T0.DocDate <= @todate) ) and (T0.CardName= '%6' or '%6' = '') AND (T1.ItemCode ='%2' or '%2' = '') and ((T0.DocNum >= '%3' and T0.DocNum <= '%4') or ('%3' = '' and '%4' = '')) and (T1.u_BARCODE='%5' or '%5' = '') AND ( T2.SlpName ='%7' or '%7' = '') and ( T3.City ='%8' or '%8' = '')
    if other selection not working fine, then extend the first four lines to all selections..

  • Problem in design the sql query

    Hi,
    I have following requirement on sql
    table 1 time and table 2 person entry in class room
    time date column
    entries time date column
    tab1 tab2
    time room no entries_time
    09:00 1 09:00
    09:15 1 09:15
    09.30 null null
    09:45 null null
    10.00 null null
    I want to display last entry time for every time column, i mean output like
    time room no entries_time
    09:00 1 09:00
    09:15 1 09:15
    09.30 1 09:15
    09:45 1 09:15
    10.00 1 09:15
    10.15 1 09:15
    10.30 1 09:15
    Regards,
    Ram

    CREATE TABLE "TAB1"
    ("REF_TIME" DATE NOT NULL ENABLE
    Insert into TAB1 (REF_TIME) values (to_date('25-JUN-2012 12.00.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB1 (REF_TIME) values (to_date('25-JUN-2012 12.01.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB1 (REF_TIME) values (to_date('25-JUN-2012 12.02.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB1 (REF_TIME) values (to_date('25-JUN-2012 12.03.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB1 (REF_TIME) values (to_date('25-JUN-2012 12.04.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB1 (REF_TIME) values (to_date('25-JUN-2012 12.05.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB1 (REF_TIME) values (to_date('25-JUN-2012 12.06.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB1 (REF_TIME) values (to_date('25-JUN-2012 12.07.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB1 (REF_TIME) values (to_date('25-JUN-2012 12.08.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB1 (REF_TIME) values (to_date('25-JUN-2012 12.09.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB1 (REF_TIME) values (to_date('25-JUN-2012 12.10.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB1 (REF_TIME) values (to_date('25-JUN-2012 12.11.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB1 (REF_TIME) values (to_date('25-JUN-2012 12.12.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB1 (REF_TIME) values (to_date('25-JUN-2012 12.13.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB1 (REF_TIME) values (to_date('25-JUN-2012 12.14.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB1 (REF_TIME) values (to_date('25-JUN-2012 12.15.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB1 (REF_TIME) values (to_date('25-JUN-2012 12.16.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB1 (REF_TIME) values (to_date('25-JUN-2012 12.17.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB1 (REF_TIME) values (to_date('25-JUN-2012 12.18.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB1 (REF_TIME) values (to_date('25-JUN-2012 12.19.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB1 (REF_TIME) values (to_date('25-JUN-2012 12.20.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB1 (REF_TIME) values (to_date('25-JUN-2012 12.21.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB1 (REF_TIME) values (to_date('25-JUN-2012 12.22.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    commit;
    CREATE TABLE "TAB2"
    ("ROOM_NO" NUMBER, "TIME" DATE NOT NULL ENABLE
    Insert into TAB2 (ROOM_NO,TIME) values (1,to_date('25-JUN-2012 12.00.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB2 (ROOM_NO,TIME) values (1,to_date('25-JUN-2012 12.02.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB2 (ROOM_NO,TIME) values (1,to_date('25-JUN-2012 12.03.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB2 (ROOM_NO,TIME) values (1,to_date('25-JUN-2012 12.04.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB2 (ROOM_NO,TIME) values (1,to_date('25-JUN-2012 12.10.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    Insert into TAB2 (ROOM_NO,TIME) values (1,to_date('25-JUN-2012 12.15.00 AM','DD-MON-YYYY HH.MI.SS AM'));
    commit;
    output need in this format
    12.00.00 AM     1     12.00.00 AM
    12.01.00 AM     1     12.00.00 AM
    12.02.00 AM     1     12.02.00 AM
    12.03.00 AM     1     12.03.00 AM
    12.04.00 AM     1     12.04.00 AM
    12.05.00 AM     1     12.04.00 AM
    12.06.00 AM     1     12.04.00 AM
    12.07.00 AM     1     12.04.00 AM
    12.08.00 AM     1     12.04.00 AM
    12.09.00 AM     1     12.04.00 AM
    12.10.00 AM     1     12.10.00 AM
    12.11.00 AM     1     12.10.00 AM
    12.12.00 AM     1     12.10.00 AM
    12.13.00 AM     1     12.10.00 AM
    12.14.00 AM     1     12.10.00 AM
    12.15.00 AM     1     12.15.00 AM
    12.16.00 AM     1     12.15.00 AM
    12.17.00 AM     1     12.15.00 AM
    12.18.00 AM     1     12.15.00 AM
    12.19.00 AM     1     12.15.00 AM
    12.20.00 AM     1     12.15.00 AM
    12.21.00 AM     1     12.15.00 AM
    12.22.00 AM     1     12.15.00 AM
    Thanks

  • Facing problem in implementing the analytical query in OWB

    Hi All,
    I was trying analytical function for my Customer Dimension but am not able to implement the same in my OWB.I have 2 tables who have duplicates customers which cannot be figured out by Customer id as customer id is not unique.So, i have to filter out the information on the basis of First Name, middle name, last name & DOB. Since, each customer has multiple address records( for Permanent, Correspondence, Unknown ).
    I want 1 record for all the three address types.
    Can i do thru the following query???
    If yes, how will i implment the same in OWB.
    SELECT PRENOM, MIDDLE_NAME, NOM, DEBUT, SEXE, OCCUPATION, FAMILY_STATUS,
         EDUC_QUALIFICATION, CUSTOMER_NATIONALITY, SIGLE, ANNUAL_INCOME,
         FATHER_HUSBAND_NAME,TYPE_ADDRESS, ADDRESS1, ADDRESS2, ADDRESS3,
         TOWN, REGION, POSTCODE,ADDRESS_EFFECT_DATE
    FROM
    (SELECT C1.PRENOM, C1.MIDDLE_NAME, C1.NOM, C1.DEBUT, C1.SEXE, C1.OCCUPATION, C1.FAMILY_STATUS,
         C1.EDUC_QUALIFICATION, C1.CUSTOMER_NATIONALITY, C1.SIGLE, C1.ANNUAL_INCOME,
         C1.FATHER_HUSBAND_NAME,C1.TYPE_ADDRESS, C1.ADDRESS1, C1.ADDRESS2, C1.ADDRESS3,
         C1.TOWN, C1.REGION, C1.POSTCODE,C1.ADDRESS_EFFECT_DATE,
    ROW_NUMBER() OVER (PARTITION BY C1.PRENOM, C1.MIDDLE_NAME, C1.NOM, C1.DEBUT,C1.TYPE_ADDRESS
    ORDER BY C1.ADDRESS_EFFECT_DATE DESC)M
    FROM CUST_1 C1
    UNION ALL
    SELECT C1.PR_FIRST_NM, C1.PR_MIDDLE_NM, C1.PR_LAST_NM, C1.PR_DOB, C1.PR_GENDER, C1.PR_OCCUPATION, C1.PR_MARITAL_STATUS,
    C1.PR_EDUCATION_QUAL, C1.PR_NATIONALITY, C1.PR_TITLE, C1.GP_ANNUAL_INC, C1.PR_FATHER_NM,
    C1.AD_TYPE, C1.AD_ADDR1, C1.AD_ADDR2, C1.AD_ADDR3, C1.TOWN, C1.REGION, C1.AD_PIN_CD,C1.REC_UPDT_DT,
    ROW_NUMBER() OVER (PARTITION BY C1.PR_FIRST_NM, C1.PR_MIDDLE_NM, C1.PR_LAST_NM, C1.PR_DOB,C1.AD_TYPE
    ORDER BY C1.REC_UPDT_DT DESC )M
    FROM CUST_2 C1)
    WHERE M = 1
    Please help me out as right now, am using aggregators which are taking lot of time. Loading type on my Customer Dimension table is- Insert/Update
    Thanks in advance
    -Nikita.

    Hello Nikita,
    From your first post I understand that you would like to merge 3 similar (but not complete identical) records into 1 record. If this is the case, then have you thought about using the match-merge operator in OWB?
    With the match-merge operator you can tell the mapping which records are similar by selecting "first_nm", "middle_nm", "last_nm" in the Match-Bin of the operator.
    Then you define how attributes should be merged.
    This way you do not need to aggregate your source data set. Just select all records from both source tables. Put those in the Set-Operator "UNION ALL" and this will be you input for the match-merge operator.
    Regards,
    Ilona

  • Problem in sql query because of order by clause

    Hi All,
    I am facing a one problem in my one sql query.I am using Oracle 10gR2.
    Query is given below:
    SELECT t1.ename
            FROM T1, T2
           WHERE T1.EMPNO = 1234
             AND T1.ACCOUNTNO = T2.ACCOUNTNO
             AND T1.SEQ = T2.SEQ
           ORDER BY T2.SEQThe Plan of the query is :
    | Id  | Operation                     | Name                 | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT              |                      |     2 |   218 | 11716   (1)| 00:00:41 |
    |*  1 |  TABLE ACCESS BY INDEX ROWID  | T1                   |     1 |    89 |     1   (0)| 00:00:01 |
    |   2 |   NESTED LOOPS                |                      |     2 |   218 | 11716   (1)| 00:00:41 |
    |*  3 |    TABLE ACCESS BY INDEX ROWID| T2                   |     2 |    40 | 11715   (1)| 00:00:41 |
    |   4 |     INDEX FULL SCAN           | PK_T2_SEQ            | 58752 |       |   122   (5)| 00:00:01 |
    |*  5 |    INDEX RANGE SCAN           | FK_ACCOUNTNO         |     3 |       |     0   (0)| 00:00:01 |
    ----------------------------------------------------------------------------------------------------Now i want to reduce the time of this query.
    If i am removing Order by clause from query than performance of the query is totally perfect but with order by clause its taking a time.
    I have already set SORT_AREA_SIZE but still nothing is improving.
    Welcome and thanks for your suggestions.
    Thanks,
    Edited by: BluShadow on 23-Jun-2011 07:55
    added {noformat}{noformat} tags and formatted explain plan to make it readable.  Please see {message:id=9360002} for details on how to post code and data                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Hi,
    There are a couple of things I do not understand.
    1. Why don't you put {noformat}{noformat} around your code, it makes it so much easier to read, especially your explain plan
    2. You claim that the ORDER BY is problematic compared to no order by. Then why do you choose to post only one plan?
    3. It is hard to understand how your tables relate, and which indexes you have and which you don't.
    - PK_T2_SEQ, does this mean that SEQ alone is primary key of T2?
    - If SEQ is primary key of T2, why do you join on accountno, seq and not just seq?
    - If SEQ is primary key of T2 one of the tables is denormalized.
    4. FK_ACCOUNTNO, is this an index on accountno, alone?
    - Or is this AccountNo, Seq?
    5. Is there no index on T1.EMPNO?
    Above could of course just be a case of my not understanding the names of your indexes.
    So, here are my guesses:
    Above plan is for the ORDER BY query. That means the optimizer, has chosen to full scan PK_T2_SEQ, since data is then read according to the ORDER BY.
    (This could be a bad choice)I
    You could try and order by t1.seq, instead. Result should be the same.
    Regards
    Peter                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Sql query/function problem??

    Hi ,
    I have problems writing a difficult sql query, please help me
    I have a table t in which there are 50000 records
    the table has columns like
    create table t
    (MATCH_ID     NUMBER(4) NOT NULL,
    TEAM_ID NUMBER(4),
    PLAYER_ID     NUMBER(4),
    RUNS     NUMBER(3))
    here match_id, player_id and team_id are jointly primary key
    SQL> SELECT * FORM T WHERE MATCH_ID < 10
    MATCH_ID    TEAM_ID      PL_ID RUNS
            1          2       1228 8
            1          2       1203 82
            1          2       1316 24
            1          1       1150 27
            1          1       1278 13
            1          1       1243 60
            2          1       1278 37
            2          1       1291 0
            2          1       1243 53
            2          2       1228 25
            2          2       1285 103
            2          2       1316 60
            3          2       1228 8
            3          2       1285 25
            3          2        858 43
            3          1       1278 52
            3          1       1394 6
            3          1       1243 31
            4          1       1278 61
            4          1       1394 6
            4          1       1243 3
            4          2       1228 41
            4          2       1285 40
            4          2        858 5
            6          2       1228 20
            6          2       1285 100
            6          2       1408 0
            7          2       1228 15
            7          2       1285 34
            7          2       1408 44
            8          2       1228 0
            8          2       1420 31
            8          2       1340 66
            9          2       1420 19
            9          2       1385 28
            9          2       1340 0
    .....so on upto 50000 records..
    the problem is that I want to extract how many times each player_id in each
    match exists in the table, prior to that match_id (or current_match_id)
    along with that in another column, I also want the sum of 'RUNS' for each
    player_id  prior to that match_id (or current_match_id)
    my disired output is:
    MATCH_ID    TEAM_ID   player_ID RUNS   NO_OF_OCCURENCES    SUM(RUNS)
                                           BEFORE_THIS_MATCH   BEFORE_THIS_MATCH
                                           FOR_THIS_PLAYER_ID  FOR_THIS_PLAYER_ID
            1          2       1228 8      0                   0
            1          2       1203 82     0                   0
            1          2       1316 24     0                   0
            1          1       1150 27     0                   0
            1          1       1278 13     0                   0
            1          1       1243 60     0                   0
            2          1       1278 37     1                   13
            2          1       1291 0      0                   0
            2          1       1243 53     1                   60
            2          2       1228 25     1                   8
            2          2       1285 103    0                   0
            2          2       1316 60     1                   24
            3          2       1228 8      2                   33
            3          2       1285 25     1                   103
            3          2        858 43     0                   0
            3          1       1278 52     2                   50
            3          1       1394 6      0                   0
            3          1       1243 31     2                   113
            4          1       1278 61     3                   102
            4          1       1394 6      1                   6
            4          1       1243 3      3                   144
            4          2       1228 41     3                   41
            4          2       1285 40     2                   128
            4          2        858 5      1                   43
            6          2       1228 20     4                   82
            6          2       1285 100    3                   168
            6          2       1408 0      0                   0
            7          2       1228 15     5                   102
            7          2       1285 34     4                   268
            7          2       1408 44     1                   0
            8          2       1228 0      6                   117
            8          2       1420 31     0                   0
            8          2       1340 66     0                   0
            9          2       1420 19     1                   31
            9          2       1385 28     0                   0
            9          2       1340 0      1                   66
    as you can see from the above data (5TH COLUMN), i have mentioned the
    existance of each player_id in each match prior to the current_match_id
    since match_id = 1 is the 1st match in the table so no player_id comes in the
    table before match number 1.   
    In match number 2 , player_id = 1278 was also present in match_id = 1 so
    thats why Number_OF_OCCURENCES = 1 for  player_id = 1278 in match_id = 2
    and so on..
    same is the case with 'RUNS' column but here RUNS are the SUM of each
    player_id's 'RUNS' before the current match
    Note: if some player_id does not exist in the table before the current
    match_ID then the query should return zero for that player_id ( as in 4th and
    5th columns of no_of_occurances and sum(runs) respectively)
    for example: in above data
    MATCH_ID    TEAM_ID  PLayer_ID RUNS   NO_OF_OCCURENCES    SUM(RUNS)
                                          BEFORE_THIS_MATCH   BEFORE_THIS_MATCH
                                          FOR_THIS_PLAYER_ID  FOR_THIS_PLAYER_ID
           9          2       1385 28     0                   0
    I hope this will clear my problem
    i would be extremely grateful if someone helps me out??
    here is sample ddl of the above data
    create table t
    (MATCH_ID     NUMBER(4) NOT NULL,
    TEAM_ID         NUMBER(4),
    PLAYER_ID     NUMBER(4),
    RUNS     NUMBER(3))
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (1, 2, 1228, 8);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (1, 2, 1203, 82);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (1, 2, 1316, 24);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (1, 1, 1150, 27);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (1, 1, 1278, 13);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (1, 1, 1243, 60);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (2, 1, 1278, 37);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (2, 1, 1291, 0);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (2, 1, 1243, 53);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (2, 2, 1228, 25);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (2, 2, 1285, 103);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (2, 2, 1316, 60);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (3, 2, 1228, 8);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (3, 2, 1285, 25);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (3, 2, 858, 43);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (3, 1, 1278, 52);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (3, 1, 1394, 6);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (3, 1, 1243, 31);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (4, 1, 1278, 61);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (4, 1, 1394, 6);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (4, 1, 1243, 3);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (4, 2, 1228, 41);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (4, 2, 1285, 40);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (4, 2, 858, 5);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (6, 2, 1228, 20);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (6, 2, 1285, 100);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (6, 2, 1408, 0);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (7, 2, 1228, 15);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (7, 2, 1285, 34);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (7, 2, 1408, 44);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (8, 2, 1228, 0);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (8, 2, 1420, 31);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (8, 2, 1340, 66);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (9, 2, 1420, 19);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values  (9, 2, 1385, 28);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (9, 2, 1340, 0);regards
    ramis.

    Ramis,
    SQL> select * from tt;
      MATCH_ID    TEAM_ID  PLAYER_ID       RUNS
             1          2       1228          8
             1          2       1203         82
             1          2       1316         24
             1          1       1150         27
             1          1       1278         13
             1          1       1243         60
             2          1       1278         37
             2          1       1291          0
             2          1       1243         53
             2          2       1228         25
             2          2       1285        103
             2          2       1316         60
             3          2       1228          8
             3          2       1285         25
             3          2        858         43
             3          1       1278         52
             3          1       1394          6
             3          1       1243         31
             4          1       1278         61
             4          1       1394          6
             4          1       1243          3
             4          2       1228         41
             4          2       1285         40
             4          2        858          5
             6          2       1228         20
             6          2       1285        100
             6          2       1408          0
             7          2       1228         15
             7          2       1285         34
             7          2       1408         44
             8          2       1228          0
             8          2       1420         31
             8          2       1340         66
             9          2       1420         19
             9          2       1385         28
             9          2       1340          0
    36 rows selected.
    SQL> select tt.match_id,
           tt.team_id,
           tt.player_id,
           tt.runs,
           nvl(a.sum_player,0) OCC,
           nvl(b.sum_runs,0) SUM_RUNS
    from
    tt,
    (select a.match_id,a.team_id,a.player_id,a.runs,count(*) sum_player
    from tt a,
          (select match_id,player_id
           from   tt
           group by match_id,player_id) b
    where a.match_id>b.match_id
    and   a.player_id=b.player_id
    group by a.match_id,a.team_id,a.player_id,a.runs
    ) a,
    (select a.match_id,a.team_id,a.player_id,a.runs,sum(b.runs) sum_runs
    from tt a,
          (select match_id,player_id,runs
           from   tt) b
    where a.match_id>b.match_id
    and   a.player_id=b.player_id
    group by a.match_id,a.team_id,a.player_id,a.runs
    ) b
    where tt.match_id=a.match_id(+)
    and tt.team_id=a.team_id(+)
    and tt.player_id=a.player_id(+)
    and tt.match_id=b.match_id(+)
    and tt.team_id=b.team_id(+)
    and tt.player_id=b.player_id(+)
      MATCH_ID    TEAM_ID  PLAYER_ID       RUNS        OCC   SUM_RUNS
             1          1       1150         27          0          0
             1          1       1243         60          0          0
             1          1       1278         13          0          0
             1          2       1203         82          0          0
             1          2       1228          8          0          0
             1          2       1316         24          0          0
             2          1       1243         53          1         60
             2          1       1278         37          1         13
             2          1       1291          0          0          0
             2          2       1228         25          1          8
             2          2       1285        103          0          0
             2          2       1316         60          1         24
             3          1       1243         31          2        113
             3          1       1278         52          2         50
             3          1       1394          6          0          0
             3          2        858         43          0          0
             3          2       1228          8          2         33
             3          2       1285         25          1        103
             4          1       1243          3          3        144
             4          1       1278         61          3        102
             4          1       1394          6          1          6
             4          2        858          5          1         43
             4          2       1228         41          3         41
             4          2       1285         40          2        128
             6          2       1228         20          4         82
             6          2       1285        100          3        168
             6          2       1408          0          0          0
             7          2       1228         15          5        102
             7          2       1285         34          4        268
             7          2       1408         44          1          0
             8          2       1228          0          6        117
             8          2       1340         66          0          0
             8          2       1420         31          0          0
             9          2       1340          0          1         66
             9          2       1385         28          0          0
             9          2       1420         19          1         31
    36 rows selected.
    SQL> Is this do you want ?
    Nicolas.

  • Problem with SQL Query

    I am a java developer and having problem writing a simple sql query. Any help is highly appreciated.
    USER_LOGIN
    CREATE TABLE USER_LOGIN
    EMAIL_ADDRESS VARCHAR2(30 BYTE) NOT NULL,
    PASSWORD VARCHAR2(30 BYTE) NOT NULL,
    LAST_NAME VARCHAR2(20 BYTE),
    FIRST_NAME VARCHAR2(20 BYTE),
    STATUS VARCHAR2(1 BYTE)
    DATA:
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, klein, james, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, cullen, sarah, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, cole, kling, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, stein, amy, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, stone, edward, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, simps, harris, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, brown, steven, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, kumar, vikram, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, gray, susan, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, green, monica, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, tile, eric, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, parder, sergey, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, fossil, bill, 1);
    This is just the sample data. In production I have around 30,000 records and I have a requirement to retrieve the records in a batch of 5,000 at a time.
    For testing on the above 10 records, I need to retrieve 3 at a time.
    For instance: From my java servlet phase listener, I am going to run a loop, inside which I make a database call. For the first time inside the loop, it has to fetech records 1 to 3, the second time 4 to 6, the third time 7 to 9 and finally the last record. I will be able to pass two parameters for start and end row indexes.
    I have come up with the following query...
    SELECT U.EMAIL_ADDRESS,
    U.PASSWORD,
    U.LAST_NAME,
    U.FIRST_NAME,
    U.STATUS
    FROM USER_LOGIN U
    WHERE ROWNUM > /*start index*/ AND ROWNUM < /*end index*/
    ORDER BY EMAIL_ADDRESS
    But the results are not as expected. It works well for the first batch where start index is 0 and end index is 4, but it returns zero records when start index is 3 and end index is 7. Any help on this would be highly appreciated
    Thanks.

    Saludos Sirgeneral,
    This is one of the technique you should be working on
    SELECT * FROM(
    SELECT ROWNUM rn,e.* FROM emp e
    ORDER BY empno)
    WHERE rn BETWEEN &st_range AND &end_rangeIn your case the query would be
    select * from(
    SELECT rownum en, U.EMAIL_ADDRESS,
    U.PASSWORD,
    U.LAST_NAME,
    U.FIRST_NAME,
    U.STATUS
    FROM USER_LOGIN U
    ORDER BY EMAIL_ADDRESS)
    where rn between 4 and 6); --second set for exampleCheers!!!
    Bhushan

  • Problem executing a sql query in 10g environment

    Hi,
    I am having problem executing the following sql query in 10g environment. It works fine in 8i environment.
    I tried to_number(to_char) and it did not work.
    **A.APPL_ACTION_DT >= TO_CHAR("&v_strBeginStatusDate&", 'DD-MON-YYYY') AND A.APPL_ACTION_DT <= TO_CHAR("&v_strEndStatusDate&", 'DD-MON-YYYY')))**
    Any suggestions..
    --Pavan                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    I would be surprised if that worked in 8i as posted, although I no longer have 8i to test. You do not tell us the error message you are getting, but there are several things wrong with what you posted.
    First, the substitution variable requires only the & at the beginning, you have one on each end of your string, the one at the end will remain in the string that is passed to the database.
    Second, you cannot TO_CHAR a string with a date format as you are trying to do. The TO_CHAR function is overloaded and has two basic forms TO_CHAR(date, format_model) and TO_CHAR(number, format_model). Note that neither takes a string. It would appear that at least current versions of Oracle choose the second signature unless specifically passed a date datatype.
    SQL> select to_char('&h', 'dd-mon-yyyy') from dual;
    Enter value for h: 12
    old   1: select to_char('&h', 'dd-mon-yyyy') from dual
    new   1: select to_char('12', 'dd-mon-yyyy') from dual
    select to_char('12', 'dd-mon-yyyy') from dual
    ERROR at line 1:
    ORA-01481: invalid number format modelalthough I suspect that the error you are getting with your posted code is more likely to be ORA-01722: invalid number.
    Depending on the data type of appl_action_date, you are probably lokoing for TO_DATE instead of TO_CHAR.
    John

  • Problem creating an sql query with a parameter which is a list

    Hi,
    Im having a problem creating a certain SQL query.
    The query looks like this:
    SELECT gstock_id FROM germplasm_stock gps, germplasm gp WHERE gps.germplasm_id = gp.germplasm_id AND organism_id IN ($childList:VARCHAR).
    the organism_id field is of DECIMAL type.
    the parameter childList is actually a list of Id's, something like: 123,124,789
    and it is created dynamically by an other function, so I cant just put it there staticlly.
    I tried using the ARRAY type instead of VARCHAR, but that didn't work,
    anyone knows how can I give this query a parameter which is a list of numbers ?
    Thanks

    I have tried all the following options and the same issue occurs:
    EXEC dbo.uspGetSiteChanges @ChangeVersion = ?
    With Parameter: 0, @ChangeVersion, ChangeVersion
    EXEC dbo.uspGetSiteChanges ?
    With Parameter: 0, @ChangeVersion, ChangeVersion
    In my first data flow I use the following and it works on two OLE DB Sources:
    EXEC dbo.uspGetSiteChanges @ChangeVersion = ?
    With:
    In my second data flow task, I use the same command and parameter mappings and it fails, very strange.

  • SQL Query constructing  for searching values in Tables single Column

    I have Table USER_SERVICES with 2 Columns USER_NAME, Services. Please find below sample data on USER_SERVICES Table.
    A user can be assigned with multiple services(service1, service2 etc.,). So we store data as below :
    USER_NAME Services
    user1 service1
    user1 service2
    user1 service3
    user2 service1
    user2 service2
    user3 service3
    user4 service4
    I need to frame a SQL Query to 'select users assigned with Service A and Service B and Service n'.
    Note: 'And' condition is used when Searching for multiple services.
    Example: The SQL Query has to dynamically handle condition if i give Single Service, multiple Services(service1 and service2 e.t.c,)
    If i say select users assigned with service1 and service2, from the above Table, result should be user1 and user2
    If i say select users assigned with service1 and service2 and service3, from the above Table, result should be user1
    If i say select users assigned with service4 from the above table, result should be user4
    If i say select users assigned with service1 from the above table, result should be user2,user1
    If i say select users assigned with service1 and service2 from the above table, result should be user2,user1
    How do i construct the SQL Query. Any help will be appreciated.
    Thanks,
    Sathish
    Alternate email: [email protected]

    How it will be stored? In a string or a table or a collection type?
    If you have it in a table you can do like this.
    with t
    as
    select 'user1' user_name, 'service1' services from dual union all
    select 'user1', 'service2' from dual union all
    select 'user1', 'service3' from dual union all
    select 'user2', 'service1' from dual union all
    select 'user2', 'service2' from dual union all
    select 'user3', 'service3' from dual union all
    select 'user4', 'service4' from dual
    t1 as
    select 'service1' services from dual union all
    select 'service2' from dual
    select distinct user_name
      from (
    select t.user_name, t.services, t1.services, count(t1.services) over(partition by t.user_name) cnt, t1.cnt cnt_1
      from t
      left join (select t1.*, count(*) over() cnt from t1) t1 on t1.services = t.services
    where cnt = cnt_1

  • 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.

Maybe you are looking for