Inserting one table records to the another table

Hi There
Though i don't close the Result set , My program throws the following Exception
java.sql.SQLException: ResultSet is ClosedBecause of this my program Inserts only one record in the another table
My code is this
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.DefaultComboBoxModel.*;
import javax.swing.table.*;
import java.sql.*;
import java.util.*;
public class SearchBook extends JDialog implements ActionListener
     private JComboBox comboCategory,comboAuthor;
     private JSplitPane splitpane;
     private JTable table;
     private JToolBar toolBar;
     private JButton btnclose, btncancel;
     private JPanel panel1,panel2,panel3,panel4;
     private JLabel lblCategory,lblAuthor;
     private Container c;
     //DefaultTableModel model;
     Statement st;
     ResultSet rs;
     Vector v = new Vector();
     public SearchBook (Connection con)
          // Property for JDialog
          setTitle("Search Books");
          setLocation(40,110);
          setModal(true);
          setSize(750,450);
          // Creating ToolBar Button
          btnclose = new JButton(new ImageIcon("Images/export.gif"));
          btnclose.addActionListener(this);
          // Creating Tool Bar
          toolBar = new JToolBar();
          toolBar.add(btnclose);
          try
               st=con.createStatement();
               rs =st.executeQuery("SELECT BCat from Books Group By Books.BCat");
               while(rs.next())
                    v.add(rs.getString(1));
          catch(SQLException ex)
               System.out.println("Error");
          panel1= new JPanel();
          panel1.setLayout(new GridBagLayout());
          GridBagConstraints c = new GridBagConstraints();
          c.fill = GridBagConstraints.HORIZONTAL;
          lblCategory = new JLabel("Category:");
          lblCategory.setHorizontalAlignment (JTextField.CENTER);
          c.gridx=2;
          c.gridy=2;
          panel1.add(lblCategory,c);
          comboCategory = new JComboBox(v);
          comboCategory.addActionListener(this);
          c.ipadx=20;
          c.gridx=3;
          c.gridwidth=1;
          c.gridy=2;
          panel1.add(comboCategory,c);
          lblAuthor = new JLabel("Author/Publisher:");
          c.gridwidth=2;
          c.gridx=1;
          c.gridy=4;
          panel1.add(lblAuthor,c);
          lblAuthor.setHorizontalAlignment (JTextField.LEFT);
          comboAuthor = new JComboBox();
          comboAuthor.addActionListener(this);
          c.insets= new Insets(20,0,0,0);
          c.ipadx=20;
          c.gridx=3;
          c.gridy=4;
          panel1.add(comboAuthor,c);
          comboAuthor.setBounds (125, 165, 175, 25);
          table = new JTable();
          JScrollPane scrollpane = new JScrollPane(table);
          //panel2 = new JPanel();
          //panel2.add(scrollpane);
          splitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,panel1,scrollpane);
          splitpane.setDividerSize(15);
          splitpane.setDividerLocation(190);
          getContentPane().add(toolBar,BorderLayout.NORTH);
          getContentPane().add(splitpane);
     public void actionPerformed(ActionEvent ae)
          Object obj= ae.getSource();
          if(obj==comboCategory)
               String selecteditem = (String)comboCategory.getSelectedItem();
               displayAuthor(selecteditem);
               System.out.println("Selected Item"+selecteditem);
          else if(obj==btnclose)
               dispose();     
          else if(obj==comboAuthor)
               String selecteditem1 = (String)comboAuthor.getSelectedItem();
               displayavailablity(selecteditem1);
               //System.out.println("Selected Item"+selecteditem1);
               System.out.println("Selected Author"+selecteditem1);
     private void displayAuthor(String selecteditem)
          try
          {     Vector data = new Vector();
               rs= st.executeQuery("SELECT BAuthorandPublisher FROM Books where BCat='" + selecteditem + "' Group By Books.BAuthorandPublisher");
               System.out.println("Executing");
               while(rs.next())
                    data.add(rs.getString(1));
               //((DefaultComboBoxModel)comboAuthor.getModel()).setVectorData(data);
               comboAuthor.setModel(new DefaultComboBoxModel(data));
               //rs.close();
          catch(SQLException ex)
               System.out.println("ERROR");
     private void displayavailablity(String selecteditem1)
               try
                    Vector columnNames = new Vector();
                    Vector data1 = new Vector();
                    String bname,bauthor,bcategory,bref1,bavail,bid;
                    int bref,mid,num;
                    rs = st.executeQuery("SELECT * FROM Books where BAuthorandPublisher='" + selecteditem1 +"'");     
                    while(rs.next())
                         bname = rs.getString("BName");                         
                         bauthor = rs.getString("BAuthorandPublisher");
                         bcategory = rs.getString("BCat");
                         bref = rs.getInt("BRef");
                         if(bref==1)bref1="Yes";
                         else bref1 = "No";
                         mid = rs.getInt("Mid");
                         if(mid==0)bavail="Available";
                         else bavail="Issued To:"+mid;
                         bid = rs.getString("BId");
                         System.out.println("Book Name is::"+bname);
                         System.out.println("Book Availabilty::"+bavail);
                         num = st.executeUpdate("insert into BSearch Values('"+bid+"','"+bname+"','"+bcategory+"','"+bauthor+"','"+bavail+"','"+bref1+",')");
                         System.out.println("Inseted in the table");
                    /**ResultSetMetaData md= rs.getMetaData();
                    int columns =md.getColumnCount();
                    String booktblheading[]={"Book ID","Book NAME","BOOK AUTHOR/PUBLISHER","REFRENCE","CATEGORY"};
                    for(int i=1; i<= booktblheading.length;i++)
                         columnNames.addElement(booktblheading[i-1]);
                    while(rs.next())
                         Vector row = new Vector(columns);
                         for(int i=1;i<=columns;i++)
                              row.addElement(rs.getObject(i));
                         data1.addElement(row);
                         //System.out.println("data is:"+data);
                    ((DefaultTableModel)table.getModel()).setDataVector(data1,columnNames);
                    //DefaultTableModel model = new DefaultTableModel(data1,columnNames);
                    //table.setModel(model);
                    //rs.close();
                    //st.close(); */
               catch(SQLException ex)
                    ex.printStackTrace();
}Please help me Friends. I am very new to java. otherwise give me some suggestion to implement this idea in effective manner.
Thank you for your service
Cheers

Hi
Here i am Posting My programs code
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.DefaultComboBoxModel.*;
import javax.swing.table.*;
import java.sql.*;
import java.util.*;
public class SearchBook extends JDialog implements ActionListener
     private JComboBox comboCategory,comboAuthor;
     private JSplitPane splitpane;
     private JTable table;
     private JToolBar toolBar;
     private JButton btnclose, btncancel;
     private JPanel panel1,panel2,panel3,panel4;
     private JLabel lblCategory,lblAuthor;
     private Container c;
     //DefaultTableModel model;
     Statement st,st1;
     ResultSet rs,rs1,rs2;
     Vector v = new Vector();
     public SearchBook (Connection con)
          // Property for JDialog
          setTitle("Search Books");
          setLocation(40,110);
          setModal(true);
          setSize(750,450);
          // Creating ToolBar Button
          btnclose = new JButton(new ImageIcon("Images/export.gif"));
          btnclose.addActionListener(this);
          // Creating Tool Bar
          toolBar = new JToolBar();
          toolBar.add(btnclose);
          try
               st=con.createStatement();
               rs =st.executeQuery("SELECT BCat from Books Group By Books.BCat");
               while(rs.next())
                    v.add(rs.getString(1));
          catch(SQLException ex)
               System.out.println("Error");
          panel1= new JPanel();
          panel1.setLayout(new GridBagLayout());
          GridBagConstraints c = new GridBagConstraints();
          c.fill = GridBagConstraints.HORIZONTAL;
          lblCategory = new JLabel("Category:");
          lblCategory.setHorizontalAlignment (JTextField.CENTER);
          c.gridx=2;
          c.gridy=2;
          panel1.add(lblCategory,c);
          comboCategory = new JComboBox(v);
          comboCategory.addActionListener(this);
          c.ipadx=20;
          c.gridx=3;
          c.gridwidth=1;
          c.gridy=2;
          panel1.add(comboCategory,c);
          lblAuthor = new JLabel("Author/Publisher:");
          c.gridwidth=2;
          c.gridx=1;
          c.gridy=4;
          panel1.add(lblAuthor,c);
          lblAuthor.setHorizontalAlignment (JTextField.LEFT);
          comboAuthor = new JComboBox();
          comboAuthor.addActionListener(this);
          c.insets= new Insets(20,0,0,0);
          c.ipadx=20;
          c.gridx=3;
          c.gridy=4;
          panel1.add(comboAuthor,c);
          comboAuthor.setBounds (125, 165, 175, 25);
          table = new JTable();
          JScrollPane scrollpane = new JScrollPane(table);
          //panel2 = new JPanel();
          //panel2.add(scrollpane);
          splitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,panel1,scrollpane);
          splitpane.setDividerSize(15);
          splitpane.setDividerLocation(190);
          getContentPane().add(toolBar,BorderLayout.NORTH);
          getContentPane().add(splitpane);
     public void actionPerformed(ActionEvent ae)
          Object obj= ae.getSource();
          if(obj==comboCategory)
               String selecteditem = (String)comboCategory.getSelectedItem();
               displayAuthor(selecteditem);
               System.out.println("Selected Item"+selecteditem);
          else if(obj==btnclose)
               dispose();     
          else if(obj==comboAuthor)
               String selecteditem1 = (String)comboAuthor.getSelectedItem();
               displayavailablity(selecteditem1);
               //System.out.println("Selected Item"+selecteditem1);
               System.out.println("Selected Author"+selecteditem1);
     private void displayAuthor(String selecteditem)
          try
          {     Vector data = new Vector();
               rs1= st.executeQuery("SELECT BAuthorandPublisher FROM Books where BCat='" + selecteditem + "' Group By Books.BAuthorandPublisher");
               System.out.println("Executing");
               while(rs1.next())
                    data.add(rs1.getString(1));
               //((DefaultComboBoxModel)comboAuthor.getModel()).setVectorData(data);
               comboAuthor.setModel(new DefaultComboBoxModel(data));
          catch(SQLException ex)
               System.out.println("ERROR");
     private void displayavailablity(String selecteditem1)
               try
                    Vector columnNames = new Vector();
                    Vector data1 = new Vector();
                    String bname,bauthor,bcategory,bref1,bavail,bid;
                    int bref,mid,num;
                    //rs2.Open();
                    rs = st.executeQuery("SELECT * FROM Books where BAuthorandPublisher='" + selecteditem1 +"'");     
                    boolean tr=true;
                    while(rs.next())
                         if(true)
                              bname = rs.getString("BName");                         
                              bauthor = rs.getString("BAuthorandPublisher");
                              bcategory = rs.getString("BCat");
                              bref = rs.getInt("BRef");
                              if(bref==1)bref1="Yes";
                              else bref1 = "No";
                              mid = rs.getInt("Mid");
                              if(mid==0)bavail="Available";
                              else bavail="Issued To:"+mid;
                              bid = rs.getString("BId");
                              System.out.println("Book Name is::"+bname);
                              System.out.println("Book Availabilty::"+bavail);
                         num = st1.executeUpdate("insert into BSearch Values('"+bid+"','"+bname+"','"+bcategory+"','"+bauthor+"','"+bavail+"','"+bref1+",')");
                         System.out.println("Inseted in the table");
               catch(SQLException ex)
                    ex.printStackTrace();
}Thank you for your service

Similar Messages

  • Insert a new record in the database table in between the records.

    i va a database table which ve 100 records. but i want to insert my new record  as 50th record. how i want to  proceed?
    thanks ,
    velu.

    V,
    This is an odd request.  Why?
    Ignoring that, you can ATTEMPT to insert into the 50th position IF:
    1) The DB table has just had the primary key index re-built/re-shuffled to GUARANTEE that it IS in primary key order
    2) And the primary key of the new record is built so that it follows the 49th record
    Regardless, once this table has activity against it, its sort order can/will get out of promary key order (with adds/changes/deletes). 
    But when you select data from it, you can use ORDER BY or an ABAP SORT to organzie the date as needed.
    Again... not sure WHY you need a record in a particular physical position... who cares... it is a relational DB.

  • Best way to insert millions of records into the table

    Hi,
    Performance point of view, I am looking for the suggestion to choose best way to insert millions of records into the table.
    Also guide me How to implement in easier way to make better performance.
    Thanks,
    Orahar.

    Orahar wrote:
    Its Distributed data. No. of clients and N no. of Transaction data fetching from the database based on the different conditions and insert into another transaction table which is like batch process.Sounds contradictory.
    If the source data is already in the database, it is centralised.
    In that case you ideally do not want the overhead of shipping that data to a client, the client processing it, and the client shipping the results back to the database to be stored (inserted).
    It is must faster and more scalable for the client to instruct the database (via a stored proc or package) what to do, and that code (running on the database) to process the data.
    For a stored proc, the same principle applies. It is faster for it to instruct the SQL engine what to do (via an INSERT..SELECT statement), then pulling the data from the SQL engine using a cursor fetch loop, and then pushing that data again to the SQL engine using an insert statement.
    An INSERT..SELECT can also be done as a direct path insert. This introduces some limitations, but is faster than a normal insert.
    If the data processing is too complex for an INSERT..SELECT, then pulling the data into PL/SQL, processing it there, and pushing it back into the database is the next best option. This should be done using bulk processing though in order to optimise the data transfer process between the PL/SQL and SQL engines.
    Other performance considerations are the constraints on the insert table, the triggers, the indexes and so on. Make sure that data integrity is guaranteed (e.g. via PKs and FKs), and optimal (e.g. FKs should be indexes on the referenced table). Using triggers - well, that may not be the best approach (like for exampling using a trigger to assign a sequence value when it can be faster done in the insert SQL itself). Personally, I avoid using triggers - I rather have that code residing in a PL/SQL API for manipulating data in that table.
    The type of table also plays a role. Make sure that the decision about the table structure, hashed, indexed, partitioned, etc, is the optimal one for the data structure that is to reside in that table.

  • INSERT works for only last record of the Internal table ...??

    I am trying to insert data from an internal table JTAB to a Databse Table
    in CRM. The name of the databse table in CRM is CRMD_PARTNER
    For this i first declared an internal table JTAB with same structure as that of
    the databse table CRMD_PARTNER
    DATA: BEGIN OF JTAB OCCURS 0,
         INCLUDE STRUCTURE CRMD_PARTNER,
          END OF JTAB.
    Then I filled my JTAB with the required entries. For filling the JTAB i am
    getting data from couple of other tables and filling the internal table JTAB
         loop at ktab.
    here i am filling values in JTAB and then i say APPEND JTAB.
            endloop.
         Till here every thing works well and my internal table JTAB has all values that
    I need to insert to the CRMD_PARTNER table. Also my JTAB has vales for all primary key fields.
    Now I write a condition like below.
    if not jtab[] inital.
    MODIFY CRMD_PARTNER from TABLE JTAB.
    COMMIT WORK.
    endif.
    Here comes the problem...once this code is executed and once program totally executes...
    i always see that only last record in JTAB is being inserted to the databse table CRMD_PARTNER.
    When i check in the debugger ..i see that the loop is being executed only once
    and the SY-TABIX of JTAB is being always set to the length of JTAB and
    that is why only last  record is being inseretd to the table CRMD_PARTNER.
    Now what should i do ..to insert all records of JTAB to CRMD_PARTNER table?
    is there a way i can restet the SY-TABIX and make the modify statement work for all records of JTAB?
    Finally i hardcoded the values in JTAB then i dont have any problem and all records of JTAB are being
    inserted into the database table.
    only if i am dynamically fetching the values into JTAB(by Putting in loop..endloop statements and
    pushing values to JTAB and APPENDING JTAB ) i have a problem .
    in this case also my JTAB is being correctly filled with values ..but when i try to
    insert theses values to CRMD_PARTNER with MODIFY stmt ..only always last record is being inserted.
    i tried with INSERT instead of MODIFY and i am getting runtime error.
    kindly pease help.
    Regards,
    Jessica Sam

    yes a@s i am really struggling from last 3 days.
    I actually want to create a sales order in CRM and want to
    assign ship to party for each line item in a sales order in CRM
    for that i used the standard bapi BAPI_BUSPROCESSND_CREATEMULTI and i am able
    to create an order successfully, but i see that the ship toparty
    that i give at header is being copied to each line item.
    but this is not what is expected.
    So finally i tracked in which table the ship to party gets stored in each line item
    and then tried to insert the records directly into databse. and it worked
    but only if i am hardcoding..but not when i am dynamically fecthing the values into JTAB for insertion,
    Can yoy help ..if you have any idea why insert/modify is processing only last record?
    any help will be highly appreciated.
    Regards,
    Jessica Sam

  • Delete allowed in a multirow blk only if no records exist in another table

    How can I delete an existing row in a multirow block after checking that no records exist in another table ?
    How do I proceed please ?
    I know I need to check the primary keys of both tables to do that . Please help.

    I've written the following code in the KEY-DELREC trigger :
    DECLARE
    *     Fail EXCEPTION;*
    *     alert_title varchar2(100) := null;*
    *     p_button_choice number := 0; -- 10g : for Stop_Alert, Caution_Alert & Note_Alert*
    *     cnt NUMBER;*
    *     choice NUMBER;*
    Begin
    *     If :system.record_status NOT IN ('INSERT', 'NEW') THEN -- can be CHANGED or QUERY mode*
    *          begin*
    *          SELECT count(AMD_CODE)*
    *          INTO cnt*
    *          FROM t_mmamd,t_amdtype*
    *          WHERE AMD_CODE = :AMD_CODE*
    *          AND MMA_AMD_CODE = AMD_CODE;*
    *     IF cnt > 0 THEN*
    Alerts.Stop_Alert('Error: IMDG Code '||:AMD_CODE||'Delete not allowed!!Exists in t_mmamd table', choice);
    RAISE FORM_TRIGGER_FAILURE;                       
    *          ELSE*
    *          alert_title := 'Are you sure to remove this record ?';*
    *          Alerts.Stop_Alert_YesNo (alert_title, p_button_choice);*
    If p_button_choice = 1 Then
    *     delete_record;*
    End if;
    END IF;
    end;
    Else -- record status is in INSERT or NEW mode
    *          delete_record;*
    *     End if;*
    End;
    It works okay and prevents me from deleting records in the other table . However I get the following errors when I try to delete a record which doesn't exist in t_mmamd table :
    Could not resolve record(2 tries) keep trying?
    Error : 40501 - oracle Error unable to reserve record for update or delete .

  • Refering the target table records in the transfering quey

    Hi all
    I am trying to load some records using my job in DI in the target table. The query I should use is a bit tricky. While I'm loading records into the target table using query, I should check whether one of the columns has been used in transferring record or not. As I want to have a unique value on one column. It is distinct, distinct get the unique records, I need have unique value in one column accross whole the table.
    I noticed it's not possible to refer to target column in the Query object to see whether that value has been used already there or not. But how can I address this requirement? Do you have any experience?
    I write the SQL Code here which I should use in Query object in Data Integrator:
    In the target table, every city should just come in one and only record.
    INSERT INTO target
         Effective_From_Date,
         Effective_To_Date,
         Business_Unit_ID,
         Provider_ID
    SELECT distinct
         table1.Effective_From_Date,
         table2.Effective_To_Date,
         table4.city_ID,
         table4.provider_ID
    FROM
         table1 a
         INNER JOIN table2 b
              ON (a.typeID = b.typeID)
         INNER JOIN table3 c
              ON (a.professionID = c.professionID)
         INNER JOIN table4 d
              ON (c.city_ID = d.city_ID)
                   WHERE  NOT EXISTS
                                    (SELECT * FROM target e 
                               WHERE d.city_ID = e.Business_Unit_ID)
    Thanks.

    You can use the target table as a source table as well, just drag is into your dataflow again and select Source instead of Target this time.  Then you can outer join the new source target table to your query (I might do this in a second query instead of trying to add it to the existing one).
    You could also use a lookup function to check the target table.  In this case you'd also have to add a second query to check the result of your lookup.
    Worst case, you can just throw that whole SQL query you've already created into a SQL transform and then use that as your source.

  • Duplicate records in the same table

    Hello.
    I want to duplicate records in the same table, changing just two date fields and id. Id is changed with sequence.
    Example:
    id name start_date end_date
    1 record_1 01.01.04 31.12.04
    2 record_2 01.01.03 31.12.03
    I want to duplicate record with the start_date year 04 and the duplicated record would change that start_date into year 05.
    After duplicate it should look like:
    1 record_1 01.01.04 31.12.04
    2 record_2 01.01.03 31.12.03
    3 record_1 01.01.05 31.12.05
    How should my insert look like?
    Thanks

    create sequence A_SEQ
       start with 3
       nocache
    insert into tableA
            (ID, name, start_date end_date)
       select
               A_SEQ.nextval   
              ,NAME
              ,start_date + add_months (12)
              ,end_date   + add_months (12)
         from
               tableA
        where
               start_date >= to_date('01.01.2004','dd.mm.yyyy')
          and  start_date <= to_date('01.01.2004','dd.mm.yyyy')

  • Unable to find the deleted record in the child table

    Hi,
    I have two tables and a trigger:
    CREATE TABLE parent (a INTEGER, b CHAR(10));
    CREATE TABLE child (c CHAR(10), d INTEGER);
    CREATE TRIGGER parent_trigger
    AFTER INSERT OR DELETE OR UPDATE ON parent
    REFERENCING NEW AS newRow
    FOR EACH ROW
    BEGIN
    INSERT INTO child VALUES(:newRow.b, :newRow.a);
    END parent_trigger;
    Now my point is , after insertion or updation of the records in the parent table, the records are created successfully in child table...
    BUT.. on deleting a record the record is deleted successfully from parent table..but the record is not displayed in the child table.
    SQL> delete from parent where A=2;
    1 row deleted.
    SQL> select * from parent;
    no rows selected
    SQL> set feedback on
    SQL> select * from child;
    C D
    a 1
    a 2
    3 rows selected.
    Please help.

    What's the value of :NEW variables after deletion? NULL! What gets inserted into your child table? You guess it... :)

  • Calculating average time from two records from the same table.

    Hi all
    I need to calculate the average time between two events that are recorded in the same table.
    The table is TMS_MESSAGE_AUDIT_LOG
    MESSAGE_ID VARCHAR2(16 BYTE) NOT NULL,
    MESSAGE_VERSION NUMBER(2) NOT NULL,
    CREATE_TM VARCHAR2(18 BYTE) NOT NULL,
    MESSAGE_STATUS VARCHAR2(30 BYTE),
    TRANSACTION_TYPE_NM VARCHAR2(30 BYTE),
    MESSAGE_TP VARCHAR2(3 BYTE),
    WORKFLOW_OBJECT VARCHAR2(30 BYTE) NOT NULL,
    WORKFLOW_REQUEST VARCHAR2(30 BYTE) NOT NULL,
    WORKFLOW_RETURN_CD VARCHAR2(30 BYTE) NOT NULL,
    AUDIT_ACTION VARCHAR2(255 BYTE),
    LAST_UPDATE_USER_LOGON_ID VARCHAR2(12 BYTE),
    LOCAL_TM VARCHAR2(18 BYTE) NOT NULL,
    LOCAL_TIME_ZN_NM VARCHAR2(70 BYTE) NOT NULL,
    LOCAL_DAYLIGHT_IN CHAR(1 BYTE) NOT NULL,
    FPRINT VARCHAR2(30 BYTE)
    What i now need is
    When the MESSAGE_ID is the same i need have the average time between when the MESSAGE_STATUS is AA and BB ( I need the time out of the CREATE_TM field )
    And this for every 15 minutes interval.
    Because this table will become BIG millions and millions of records it needs to be fast.
    Can anybody help me.
    Marcel

    Something like this?
    CREATE TABLE wr_test
    ( message_id                 VARCHAR2(16 BYTE) NOT NULL
    , message_version            NUMBER(2) NOT NULL  -- Assumption: Acknowledged ver > Received ver
    , create_tm                  VARCHAR2(18 BYTE) NOT NULL
    , message_status             VARCHAR2(30 BYTE)
    , transaction_type_nm        VARCHAR2(30 BYTE)
    , workflow_object            VARCHAR2(30 BYTE) DEFAULT 'x' NOT NULL
    , workflow_request           VARCHAR2(30 BYTE) DEFAULT 'x' NOT NULL
    , workflow_return_cd         VARCHAR2(30 BYTE) DEFAULT 'x' NOT NULL
    , audit_action               VARCHAR2(255 BYTE)
    , last_update_user_logon_id  VARCHAR2(12 BYTE)
    , local_tm                   VARCHAR2(18 BYTE) NOT NULL
    , local_time_zn_nm           VARCHAR2(70 BYTE) DEFAULT 'GMT' NOT NULL
    , local_daylight_in          CHAR(1 BYTE) DEFAULT 'x' NOT NULL );
    INSERT ALL
    INTO   wr_test
           ( message_id
           , message_version
           , create_tm
           , message_status
           , local_tm )
    VALUES ( message_id
           , 1
           , create_tm
           , '(Receive)'
           , TO_CHAR(local_tm,'YYYYMMDD HH24:MI:SS') )
    INTO   wr_test
           ( message_id
           , message_version
           , create_tm
           , message_status
           , local_tm )
    VALUES ( message_id
           , 2
           , create_tm
           , 'Wait CLSB Ack'
         , TO_CHAR
           ( local_tm + NUMTODSINTERVAL(DBMS_RANDOM.VALUE(0,2e5),'SECOND')
           , 'YYYYMMDD HH24:MI:SS' ) )
    SELECT ROWNUM AS message_id
         , TO_CHAR(SYSDATE,'YYYYMMDD HH24:MI:SS') AS create_tm
         , DATE '2000-01-01' + DBMS_RANDOM.VALUE(0,3) AS local_tm
    FROM dual CONNECT BY ROWNUM < 100000;
    WITH src AS
         ( SELECT message_id
                , message_status
                , message_version
                , TO_DATE(SUBSTR(local_tm,1,17),'YYYYMMDD HH24:MI:SS') AS dt
                , TO_DATE(SUBSTR(local_tm,1,8),'YYYYMMDD') AS dt_day
                , TO_CHAR(TO_DATE(SUBSTR(local_tm,10,8),'HH24:MI:SS'),'SSSSS') AS dt_sec
           FROM   wr_test
           WHERE  message_status IN ('(Receive)','Wait CLSB Ack') )
    SELECT dt_day + NUMTODSINTERVAL(period,'SECOND') AS dt
         , NUMTODSINTERVAL(AVG(elapsed),'DAY') AS avg_elapsed
         , NUMTODSINTERVAL(MIN(elapsed),'DAY') AS min_elapsed
         , NUMTODSINTERVAL(MAX(elapsed),'DAY') AS max_elapsed
         , COUNT(*)
    FROM   ( SELECT message_id
                  , message_status
                  , dt_day
                  , TRUNC(dt_sec/300)*300 AS period
                  , LEAD(dt) OVER (PARTITION BY message_id ORDER BY message_version) AS ack_dt
                  , LEAD(dt) OVER (PARTITION BY message_id ORDER BY message_version) - dt AS elapsed
             FROM   src ) cal
    WHERE  cal.message_status = '(Receive)'
    GROUP BY dt_day, period
    ORDER BY 1;Replace "wr_test" with "tms_message_audit_log" in the WITH subquery to test on your data.

  • How to process each records in the derived table which i created using cte table using sql server

    I want to process each row from the CTE table I created, how can I traverse from first row to second row and so on....
    how to process each records in the derived table which i created using  cte table using sql server

    Ideally you would be doing a set based processing rather than traversing row by row as thats more efficient. To answer it specific to your scenario we may need more info. Can you explain with some sample data your exact requirement?
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to insert into a table with a nested table which refer to another table

    Hello everybody,
    As the title of this thread might not be very understandable, I'm going to explain it :
    In a context of a library, I have an object table about Book, and an object table about Subscriber.
    In the table Subscriber, I have a nested table modeling the Loan made by the subscriber.
    And finally, this nested table refers to the Book table.
    Here the code concerning the creation of theses tables :
    Book :
    create or replace type TBook as object
    number int,
    title varchar2(50)
    Loan :
    create or replace type TLoan as object
    book ref TBook,
    loaning_date date
    create or replace type NTLoan as table of TLoan;
    Subscriber :
    create or replace type TSubscriber as object
    sub_id int,
    name varchar2(25)
    loans NTLoan
    Now, my problem is how to insert into a table of TSubscriber... I tried this query, without any success...
    insert into OSubscriber values
    *(1, 'LEVEQUE', NTLoan(*
    select TLoan(ref(b), '10/03/85') from OBook b where b.number = 1)
    Of course, there is an occurrence of book in the table OBook with the number attribute 1.
    Oracle returned me this error :
    SQL error : ORA-00936: missing expression
    00936. 00000 - "missing expression"
    Thank you for your help

    1) NUMBER is a reserved word - you can't use it as identifier:
    SQL> create or replace type TBook as object
      2  (
      3  number int,
      4  title varchar2(50)
      5  );
      6  /
    Warning: Type created with compilation errors.
    SQL> show err
    Errors for TYPE TBOOK:
    LINE/COL ERROR
    0/0      PL/SQL: Compilation unit analysis terminated
    3/1      PLS-00330: invalid use of type name or subtype name2) Subquery must be enclosed in parenthesis:
    SQL> create table OSubscriber of TSubscriber
      2  nested table loans store as loans
      3  /
    Table created.
    SQL> create table OBook of TBook
      2  /
    Table created.
    SQL> insert
      2    into OBook
      3    values(
      4           1,
      5           'No Title'
      6          )
      7  /
    1 row created.
    SQL> commit
      2  /
    Commit complete.
    SQL> insert into OSubscriber
      2    values(
      3           1,
      4           'LEVEQUE',
      5           NTLoan(
      6                  (select TLoan(ref(b),DATE '1985-10-03') from OBook b where b.num = 1)
      7                 )
      8          )
      9  /
    1 row created.
    SQL> select  *
      2    from  OSubscriber
      3  /
        SUB_ID NAME
    LOANS(BOOK, LOANING_DATE)
             1 LEVEQUE
    NTLOAN(TLOAN(000022020863025C8D48614D708DB5CD98524013DC88599E34C3D34E9B9DBA1418E49F1EB2, '03-OCT-85'))
    SQL> SY.

  • BAPI to insert a new row in the MCHA table

    Hi all,
    I am in search of a BAPI to insert a new row in the MCHA table... with the fields of the materail, plant and batch values.
    Any inputs on this..is highly appreciable...
    thanks in advance...
    regards..
    prathima.

    explore BAPI_BATCH_CREATE

  • BAPI to insert a new row in the AUSP table

    Hi all,
    I am in search of a BAPI to insert a new row in the AUSP table... with the fields of the object and
    characteristic values.
    Any inputs on this..is highly appreciable...
    thanks in advance...
    regards..
    prathima.

    hi,
    from best of my knowledge  here is list of bapi through you can insert ausp table.
    check it.
    CLSE_SELECT_AUSP
    CLVF_INSERT_AUSP
    BAPI_CLASS_CREATE
    C14K_AUSP_CHANGE_VALUE
    CLSE_SELECT_AUSP
    CLVF_UPDATE_AUSP
    C14K_AUSP_ADD_UPD
    BAPI_CLASS_CREATE
    regards,
    vipul

  • Master and Detail records in the same table

    Hi Steve,
    I have master and detail address records in the same table (self-reference). The master addresses are used as templates for detail addresses. Master addresses do not have any masters. Detail addresses have three masters: a master address, a calendar reference and a department. Addresses change from time to time and every department has its own email-account, but they refer to the same master to pre-fill some common values.
    Now I need to edit the master and detail address records on the same web page simultaneously.
    My question is: Can I implement a Master-View and Detail-View which refer to the same Entity-Object? Or should I implement a second Entity-Object? Or can it be done in a single Master-Detail-View?
    Thanks a lot.
    Kai.

    At a high level, wouldn't this be similar to an Emp entity based on the familiar EMP table that has an association from Emp to itself for the Emp.Mgr attribute?
    You can definitely build a view object that references two entity usages of the same entity like this to show, say, an employee's ENAME and at the same time their manager's ENAME.
    If there are multiple details for a given master, you can also do that with separate VO's both based on the same entity, sure. Again, just like a VO that shows a manager, and a view-linked VO of all the employees that report to him/her.

  • I HAVE A SOURCE TABLE WITH 10 RECORDS AND TARGET TABLE 15 RECORDS. MY WUESTION IS USING WITH THE TABLE COMPARISON TRANSFORM I WANT TO DELETE UNMATCHED RECORDS FROM THE TARGET TABLE ??

    I HAVE A SOURCE TABLE WITH 10 RECORDS AND TARGET TABLE 15 RECORDS. MY QUESTION IS USING WITH THE TABLE COMPARISON TRANSFORM .I WANT TO DELETE UNMATCHED RECORDS FROM THE TARGET TABLE ?? HOW IT IS ??

    Hi Kishore,
    First identify deleted records by selecting "Detect deleted rows from comparison table" feature in Table Comparison
    Then Use Map Operation with Input row type as "delete" and output row type as "delete" to delete records from target table.

Maybe you are looking for

  • Small picture on 2010 LT46249 Mitsubishi TV using Apple TV

    I have a Mitsubishi LT46249 with all modern connections. When using PC mode and Apple TV 2 the picture is clear but only 2/3 of the 46 inch screen. I have heard there are some capatibility problems with Mitsubishi when not using VUDU.

  • Error in Leave Application

    Hi, We are getting the following error in the Leave Application. Application error occurred during request processing.  Details:          com.sap.tc.webdynpro.services.sal.core.DispatcherException: Wrong WebDynpro-URL: no application name specified E

  • Error is generated when a vi is called dynamically in exe

    i havew the following attached vi's I call the untitled1.vi dynamically from the untitled2.vi. using the load vi dynamically.vi. i dont get any error meassage when i run in the scource code. But when i build the code, i get the error in opening the u

  • Lenovo U410 microphone not working

    My Lenovo U410 microphone(Conexant SmartAudio HD)  isn't working. I tried a number of things from various posts but hard luck. I checked that its configured correctly. The OS is Windows 7. Could somebody help me with steps to check if its an hardware

  • After upgrade to win2K, my AT-GPIB/TN​T(pnp) fails 3rd test in Getting

    Started Wizard Hi, I upgraded my PC to win2k from win98, and loaded GPIB drivers ver. 1.70. After that my GPIB board fails to pass the "GPIB Interfaces Sequentially Verified" test in Getting Started Wizard|Verify your hardware and software installati