Help needed in executing SQL query...

Hi,
I am very new to JDeveloper. Curently i am tryin to execute an SQL query from the BPEL process, the output of the query is to be mapped to a variable field from a target xsd file. the query is fairly simple, like
SELECT emp
FROM emp_table
WHERE emp_id=123
The target field, namely "employee", is an element from the xsd file. I tried using Java embedding activity to connect to the db and execute the query through a piece of Java code, but couldn't find a way to assign the output of the query to the field. however lately i also discovered the Database Adapter services which helps me create a database connection, but still i am not sure as of how to handle and map the output of the query to the variable field.
Can somebody please help me in resolving the issue either through Java Embed activity or Database Adapter services??
Thanks in advance
Anjan

Anjan,
I suggest you try the [url http://forums.oracle.com/forums/forum.jspa?forumID=212]BPEL Forum
John

Similar Messages

  • Help needed in framing SQL query.

    Hi,
    I have table having following schema:
    PRODUCT_ID         INT
    DATE                   DATETIME
    ITEMS_SOLD         INT
    This table contains data for a week (sunday to saturday). I want to write an SQL query to get (filter out) PRODUCT_ID of products which has same no. of ITEMS_SOLD for all 7 days. Also for given PRODUCT_ID I need to find the longest period of successive days where the no. of ITEMS_SOLD is same for all days in this period. Eg.(PRODUCT_ID 23 was sold as following along the week in no. of units sold: 4,6,6,6,6,7,4 .So the longest period is *4 days* from Monday to Thursday.) The first condition is special case of second condition where no. of days is 7.
    Any help to get the SQL query will be appreciated.
    Thanks,
    Akshay.

    PRODUCT_ID      DATE           ITEMS_SOLD
    1          10/10/2011     3
    1          11/10/2011     3
    1          12/10/2011     3
    1          13/10/2011     3
    1           16/10/2011     5
    2          10/10/2011     4
    2           11/10/2011     4
    2          12/10/2011     4
    2          13/10/2011     4
    2           14/10/2011     4
    2          15/10/2011     4
    2          16/10/2011     4
    Output:
    PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
    1          3                4     
    2          4               7
    Explanation of results:
    The table to be queried contains data for 1 week: from 10/10/2011(Sunday) to 16/10/2011(Saturday). Now, product with PRODUCT_ID '1' was sold on dates 10,11,12,13,16. Out of these 5 days 3 units were sold on 4 successive days (from 10-13). So output should be like :
    PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
    1          3               4     
    as longest period of successive days is 4 where same no. of units were sold i.e 3 units (other period is of 1 day on 16th ).
    For PRODUCT_ID 2 we have only one period of 7 days where 4 units were sold each day. So we output :
    PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
    2           4               7
    Other case where same PRODUCT_ID have different units sold on each day should be ignored.
    I hope that clarifies the problem more. Let me know in case I have missed out anything which should have been mentioned.
    -Akshay.

  • Help needed for SCCM SQL query

    Hello.
    I have the below query to extract the workstations build date as well as the hardware info. This works fine. 
    Select distinct
    v_R_System.Name0,
    v_GS_COMPUTER_SYSTEM.Manufacturer0,
    v_GS_COMPUTER_SYSTEM.Model0,
    v_GS_COMPUTER_SYSTEM_PRODUCT.Version0,
    v_GS_OPERATING_SYSTEM.Caption0,
    v_GS_OPERATING_SYSTEM.CSDVersion0,
    v_GS_OPERATING_SYSTEM.InstallDate0
    From v_R_System
    LEFT JOIN v_GS_OPERATING_SYSTEM ON v_GS_OPERATING_SYSTEM.ResourceID=v_R_System.ResourceID
    LEFT JOIN v_GS_COMPUTER_SYSTEM_PRODUCT ON v_GS_COMPUTER_SYSTEM_PRODUCT.ResourceID=v_R_System.ResourceID
    LEFT JOIN v_GS_COMPUTER_SYSTEM ON v_GS_COMPUTER_SYSTEM.ResourceID=v_R_System.ResourceID
    LEFT JOIN v_GS_SYSTEM_CONSOLE_USAGE ON v_R_System.ResourceID=v_GS_SYSTEM_CONSOLE_USAGE.ResourceID
    Where v_GS_OPERATING_SYSTEM.Caption0 = 'Microsoft Windows 7 Enterprise' and v_R_System.Is_Virtual_Machine0 =0
    order by v_GS_OPERATING_SYSTEM.InstallDate0 desc
    Now, I want a report of count of machines built based on "v_GS_COMPUTER_SYSTEM_PRODUCT.Version0" against every month and year of "v_GS_OPERATING_SYSTEM.InstallDate0".
    For example, I want to know the number of machines under a particular model (which appears under  v_GS_COMPUTER_SYSTEM_PRODUCT.Version0) built in June 2014. In this fashion I want a report for every model count for every month and year available under
    InstallDate0 column)
    Example:
    Jan 2013 ->  ThinkCentre M92p -> 55
    Jan 2013 ->  ThinkCentre M93 -> 40
    Feb 2013 ->  ThinkCentre M92p -> 10
    Feb 2013 ->  ThinkCentre M93 -> 39
    Jan 2014 ->  ThinkCentre M92p -> 20
    Jan 2014 ->  ThinkCentre M93 -> 25
    Feb 2014 ->  ThinkCentre M92p -> 12
    Feb 2014 ->  ThinkCentre M93 -> 35
    Can anyone help?

    After scratching my head a bit, I came up with the below. Do you find any flaw in it?
    Select
    v_GS_COMPUTER_SYSTEM.Manufacturer0 as Manufacturer,
    v_GS_COMPUTER_SYSTEM.Model0 as Model,
    v_GS_COMPUTER_SYSTEM_PRODUCT.Version0 as "Model Info",
    COUNT(*) as "No. of machines built",
    CASE WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '1' THEN 'January'
    WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '2' THEN 'February'
    WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '3' THEN 'March'
    WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '4' THEN 'April'
    WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '5' THEN 'May'
    WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '6' THEN 'June'
    WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '7' THEN 'July'
    WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '8' THEN 'August'
    WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '9' THEN 'September'
    WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '10' THEN 'October'
    WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '11' THEN 'November'
    WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '12' THEN 'December'END as "Month",
    YEAR(v_GS_OPERATING_SYSTEM.InstallDate0) as "Year"
    From v_GS_COMPUTER_SYSTEM
    LEFT JOIN v_GS_OPERATING_SYSTEM ON v_GS_OPERATING_SYSTEM.ResourceID=v_GS_COMPUTER_SYSTEM.ResourceID
    LEFT JOIN v_GS_COMPUTER_SYSTEM_PRODUCT ON v_GS_COMPUTER_SYSTEM_PRODUCT.ResourceID=v_GS_COMPUTER_SYSTEM.ResourceID
    Where v_GS_OPERATING_SYSTEM.Caption0 = 'Microsoft Windows 7 Enterprise' Group By v_GS_COMPUTER_SYSTEM.Manufacturer0,
    v_GS_COMPUTER_SYSTEM.Model0,
    v_GS_COMPUTER_SYSTEM_PRODUCT.Version0,
    Month(v_GS_OPERATING_SYSTEM.InstallDate0),
    YEAR(v_GS_OPERATING_SYSTEM.InstallDate0)
    Order by v_GS_COMPUTER_SYSTEM_PRODUCT.Version0 desc

  • How to execute SQL Query in Code behind Using infopath 2010?

    Hi,
    I've repeatable on infopath form, and want bind it throuth code behind from SQL table. My question is that how to execute SQL Query in code behind from infopath as well as how would get Query result to bind repeatable control?
    Thanks In Advance
    Shoeb Ahmad

    Hello,
    You first need to add new SQL DB connection then you need execute connection from code behind.
    See below link to create new connection
    http://office.microsoft.com/en-in/infopath-help/add-a-data-connection-to-a-microsoft-sql-server-database-HP010092823.aspx:
    http://www.bizsupportonline.net/infopath2010/connect-infopath-2010-sql-server-2008-table.htm
    Then use below code to execute this connection:
    AdoQueryConnection conn = (AdoQueryConnection)(this.DataConnections["Data connection name"]);
    string origCommand = Select * from tablename;
    conn.Command = origCommand;
    conn.Execute();
    Finally bind your table:
    http://www.bizsupportonline.net/infopath2007/4-way-programmatically-add-row-repeating-table.htm
    http://stevemannspath.blogspot.in/2010/09/infopath-20072010-populate-repeating.html
    Hope it could help
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • Execute SQL query in JavaBean

    I want to execute SQL query in the JavaBean.
    Is there any problem in the following code.
    There is no error message, but the database do not update. And I try to use JSP , it is ok. What is the problem in JavaBean ??
    How to execute SQL in JavaBean ???
    Please help ! Thank you !
    test.jsp - call UserTrace.java
    UserTrace.java - execute SQL
    Code:
    ** test.jsp **
    <%@ page language="java" contentType="text/html" %>
    <%@ page import="user.*, java.util.*" %>
    <jsp:useBean id="usertrace" class="user.UserTrace" scope="session" />
    <%
    if (session.isNew())
         session.setAttribute("usertrace", usertrace);
         session.setMaxInactiveInterval(15);
    %>
    ** UserTrace.java **
    package user;
    import java.util.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.beans.*;
    import java.sql.*;
    import user.*;
    public class UserTrace implements javax.servlet.http.HttpSessionBindingListener {
         private Connection con = null;
         Statement stmt = null;
         ResultSet rs = null;
         String sql;
         public void valueBound(HttpSessionBindingEvent event) {
         public void valueUnbound(HttpSessionBindingEvent event) {
              try {
                   Class.forName("org.gjt.mm.mysql.Driver");
                   con = DriverManager.getConnection("jdbc:mysql://localhost/test?user=abc&password=abcd");
                   stmt = con.createStatement();
                   sql = "insert into list(username, session_id) values ('mary', 'xxxxxxxxx')";
                   int count = stmt.executeUpdate(sql);
              catch (ClassNotFoundException e) {
              catch (SQLException e) {
    }

    Hi,
    U can use the following code:
    /********** IMPORTING PACKAGES AND CLASSES *******/
    // General package id
    package id;
    //Import the Vector class as this bean handles Vector.
    import java.util.Vector;
    //Import the SQL class to create the connections,statement,resultset etc.,
    import java.sql.*;
    //Import the SQL Types to call the setNull Method.
    import java.sql.Types.*;
    /* Main Class */
    public class dataBean
    /*********** Global Declarations ********/
    // To create the connection object
    Connection con;
    // To create the Statement object
    Statement stmt;
    // To create the PreparedStatement object
    PreparedStatement psmt;
    // To Handle the ResultSet
    ResultSet rs;
    // Most of the method need to hold the querystring for which qryString variable declare globally.
    String qryString=null;
    /************ METHODS **************/
    /* To set the connection object
         con - Connection object
    public void setConnection(Connection con)
    try
         this.con = con;
         catch(Exception e)
    /* insertRecord with column type argument
    tblNameString - Name of the Table
         dataVector - vector contains the values according to the table order
         eg., element(0) has first field, element(1) has second field vice versa
         colType - String array contains type of all the fields.                    
    return true -     if record inserted successfully
         fase - if insertion fails                    
    public boolean insertRecord(String tblNameString,Vector dataVector,String colType[])
    boolean sucFlag=false;
    try
    String commaString = "";
    int fieldCount = dataVector.size();
    for (int i=0;i<fieldCount-1;i++)
    commaString +="?,";
    commaString+="?";
    if (fieldCount > 0)
    qryString = "insert into "+tblNameString+" values ("+commaString+")";
    psmt = con.prepareStatement(qryString);
    for(int i=0;i<colType.length;i++)
    if (colType.equals("I"))
    psmt.setInt(i+1,Integer.parseInt(dataVector.elementAt(i).toString()));
    else if (colType[i].equals("F"))
    psmt.setFloat(i+1,Float.parseFloat(dataVector.elementAt(i).toString()));
    else if (colType[i].equals("S") || colType[i].equals("D"))
    psmt.setString(i+1,dataVector.elementAt(i).toString());
    else if (colType[i].equals("IN")||colType[i].equals("FN"))
    psmt.setNull(i+1,java.sql.Types.NUMERIC);
    else if (colType[i].equals("SN"))
    psmt.setNull(i+1,java.sql.Types.VARCHAR);
    else if (colType[i].equals("DN"))
    psmt.setNull(i+1,java.sql.Types.DATE);
    int sucCnt = psmt.executeUpdate();
              if (sucCnt > 0) sucFlag=true;
    catch(Exception e)
    return sucFlag;
    /* insertRecord without column type argument
    tblNameString - Name of the Table
         dataVector - vector contains the values according to the table order
         eg., element(0) has first field, element(1) has second field vice versa
    return true -     if record inserted successfully
         fase - if insertion fails                    
    public boolean insertRecord(String tblNameString,Vector dataVector)
    boolean sucFlag=false;
    Vector colType = getColumnType(tblNameString);
    try
    String commaString = "";
    int fieldCount = dataVector.size();
    for (int i=0;i<fieldCount-1;i++)
    commaString +="?,";
    commaString+="?";
    if (fieldCount > 0)
    qryString = "insert into "+tblNameString+" values ("+commaString+")";
    psmt = con.prepareStatement(qryString);
    for(int i=0;i<colType.size();i++)
    if (colType.elementAt(i).toString().equals("I"))
              if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
         psmt.setNull(i+1,java.sql.Types.NUMERIC);
                   else               
         psmt.setLong(i+1,Long.parseLong(dataVector.elementAt(i).toString()));
    else if (colType.elementAt(i).toString().equals("F"))
              if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
         psmt.setNull(i+1,java.sql.Types.NUMERIC);
                   else               
         psmt.setDouble(i+1,Double.parseDouble(dataVector.elementAt(i).toString()));
    else if (colType.elementAt(i).toString().equals("S"))
              if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
              psmt.setNull(i+1,java.sql.Types.VARCHAR);
                   else               
         psmt.setString(i+1,dataVector.elementAt(i).toString());
    else if (colType.elementAt(i).toString().equals("D"))
              if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
         psmt.setNull(i+1,java.sql.Types.DATE);
                   else               
         psmt.setString(i+1,dataVector.elementAt(i).toString());
    int sucCnt = psmt.executeUpdate();
              if (sucCnt > 0) sucFlag=true;
    catch(Exception e)
    return sucFlag;
    /* insert particular fields
    tblNameString - Name of the Table
         dataVector - vector which contains the values according to the table order
         eg., element(0) has first field, element(1) has second field vice versa
         colType - String array contains type of all the fields.                    
    return true -     if record inserted successfully
         fase - if insertion fails                    
    public boolean insertRecordPart(String tblNameString,Vector dataVector,String colType[])
    boolean sucFlag=false;
    String fieldString=" ";
    try
    String commaString = "";
    int fieldCount = dataVector.size();
    for (int i=0;i<(fieldCount/2)-1;i++)
    commaString +="?,";
    commaString+="?";
    if (fieldCount > 0)
         String valueString[]= new String[fieldCount];
         for (int i=0,j=0;i<fieldCount;i+=2,j++)
                   fieldString=fieldString+dataVector.elementAt(i)+",";
                   valueString[j]=dataVector.elementAt(i+1).toString();
              if (fieldString.substring(fieldString.length()-1,fieldString.length()).equals(","))
              fieldString=fieldString.substring(0,fieldString.length()-1);
    qryString = "insert into "+tblNameString+"("+fieldString+") values ("+commaString+")";
    psmt = con.prepareStatement(qryString);
              for (int i=1,j=0;i<fieldCount;i+=2,j++)
    if (colType[j].equals("I"))
              if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
         psmt.setNull(j+1,java.sql.Types.NUMERIC);
                   else               
         psmt.setInt(j+1,Integer.parseInt(dataVector.elementAt(i).toString()));
    else if (colType[j].equals("L"))
              if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
         psmt.setNull(j+1,java.sql.Types.NUMERIC);
                   else               
         psmt.setLong(j+1,Long.parseLong(dataVector.elementAt(i).toString()));
    else if (colType[j].equals("F"))
              if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
         psmt.setNull(j+1,java.sql.Types.NUMERIC);
                   else               
         psmt.setFloat(j+1,Float.parseFloat(dataVector.elementAt(i).toString()));
    else if (colType[j].equals("DB"))
              if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
         psmt.setNull(j+1,java.sql.Types.NUMERIC);
                   else               
         psmt.setDouble(j+1,Double.parseDouble(dataVector.elementAt(i).toString()));
    else if (colType[j].equals("S"))
              if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
              psmt.setNull(j+1,java.sql.Types.VARCHAR);
                   else               
         psmt.setString(j+1,dataVector.elementAt(i).toString());
    else if (colType[j].equals("D"))
              if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
         psmt.setNull(j+1,java.sql.Types.DATE);
                   else               
         psmt.setString(j+1,dataVector.elementAt(i).toString());
    int sucCnt = psmt.executeUpdate();
              if (sucCnt > 0) sucFlag=true;
    catch(Exception e)
    return sucFlag;
    /* Get Column Type of require table fields
    tblNameString - Name of the table
    return vector which contains the column types of the desired table
    public Vector getColumnType(String tblNameString)
    int colCount = 0;
         String locString="";
         Vector colVector = new Vector();
    try
         qryString = "select DATA_TYPE from user_tab_columns where table_name=? ORDER BY COLUMN_ID";
    psmt = con.prepareStatement(qryString);
         psmt.setString(1,tblNameString.toUpperCase());
         rs = psmt.executeQuery();
         while (rs.next())
         colCount = rs.getMetaData().getColumnCount();
              for(int i=1;i<=colCount;i++)
              locString = rs.getString(i);
              colVector.addElement(locString.equals("DATE")?"D":locString.equals("NUMBER")?"F":locString.equals("VARCHAR2")?"S":locString.equals("VARCHAR")?"S":"");
         rs.close();
         catch(Exception e)
         return colVector;
    /* update record
    tblNameString - Name of the Table
         dataVector - vector which contains the values according to the table order
         eg., element(0) has first field, element(1) has second field vice versa
         colType - String array contains type of all the fields.                    
         return true - if record successfully updated
         false - if Update fails
    public boolean updateRecord(String tblNameString,Vector dataVector,String colType[],String whereString)
    boolean sucFlag=false;
    String fieldString=" ";
    try
    String commaString = "";
    int fieldCount = dataVector.size();
    for (int i=0;i<fieldCount-1;i++)
    commaString +="?,";
    commaString+="?";
    if (fieldCount > 0)
         String valueString[]= new String[fieldCount];
         for (int i=0,j=0;i<fieldCount;i+=2,j++)
                   fieldString=fieldString+dataVector.elementAt(i)+"=?,";
                   valueString[j]=dataVector.elementAt(i+1).toString();
              if (fieldString.substring(fieldString.length()-1,fieldString.length()).equals(","))
              fieldString=fieldString.substring(0,fieldString.length()-1);
    qryString = "update "+tblNameString+" set "+fieldString+" "+whereString;
    psmt = con.prepareStatement(qryString);
    for(int i=0,vectorPos=1;i<colType.length;i++,vectorPos+=2)
    if (colType[i].equals("I"))
              if (dataVector.elementAt(vectorPos)==null||dataVector.elementAt(vectorPos).toString().equals(""))
              psmt.setNull(i+1,java.sql.Types.NUMERIC);
                   else               
              psmt.setInt(i+1,Integer.parseInt(dataVector.elementAt(vectorPos).toString()));
    else if (colType[i].equals("L"))
              if (dataVector.elementAt(vectorPos)==null||dataVector.elementAt(vectorPos).toString().equals(""))
              psmt.setNull(i+1,java.sql.Types.NUMERIC);
                   else               
              psmt.setLong(i+1,Long.parseLong(dataVector.elementAt(vectorPos).toString()));
    else if (colType[i].equals("F"))
              if (dataVector.elementAt(vectorPos)==null||dataVector.elementAt(vectorPos).toString().equals(""))
              psmt.setNull(i+1,java.sql.Types.NUMERIC);
                   else               
              psmt.setFloat(i+1,Float.parseFloat(dataVector.elementAt(vectorPos).toString()));
    else if (colType[i].equals("DB"))
              if (dataVector.elementAt(vectorPos)==null||dataVector.elementAt(vectorPos).toString().equals(""))
              psmt.setNull(i+1,java.sql.Types.NUMERIC);
                   else               
              psmt.setDouble(i+1,Double.parseDouble(dataVector.elementAt(vectorPos).toString()));
    else if (colType[i].equals("S"))
              if (dataVector.elementAt(vectorPos)==null||dataVector.elementAt(vectorPos).toString().equals(""))
              psmt.setNull(i+1,java.sql.Types.VARCHAR);
                   else               
              psmt.setString(i+1,dataVector.elementAt(vectorPos).toString());
    else if (colType[i].equals("D"))
              if (dataVector.elementAt(vectorPos)==null||dataVector.elementAt(vectorPos).toString().equals(""))
              psmt.setNull(i+1,java.sql.Types.DATE);
                   else               
              psmt.setString(i+1,dataVector.elementAt(vectorPos).toString());
    int sucCnt = psmt.executeUpdate();
              if (sucCnt > 0) sucFlag=true;
    } // end of if
    } // end of try
    catch(Exception e)
         return false;
         return sucFlag;
    public ResultSet getResultSet(String selectString)
         try
              stmt = con.createStatement();
              rs = stmt.executeQuery(selectString);
         catch(Exception e)
         System.out.println(e.getMessage());
         finally
         return rs;
    /* Get Query Result
    selectString - Query
    return the result vector based on the querystring
    public Vector getResultVector(String selectString)
         Vector resVector = new Vector();
         try
              stmt = con.createStatement();
              rs = stmt.executeQuery(selectString);
              while (rs.next())
              resVector.addElement(rs.getString(1));
              resVector.addElement(rs.getString(2));
         catch(Exception e)
         System.out.println(e.getMessage());
         finally
         return resVector;
    /* return next consecutive number
    tablenName - Name of the table for which the number to be generated
         serialFiel - Name of the field for which the number to be generated
         whereString - where condition to filter the records if composite key found,
                        it can be empty if there is no composite primary key.
    startNumber - if there is no record exists in the table, set the starting number
    public String getCurrentSerial(String tableName,String serialField,String whereString,String startNumber)
    String queryString = "select max(to_number("+serialField+")) from "+tableName+" "+whereString;
    int maxSerial=0;
    try
    psmt = con.prepareStatement(queryString);
         rs = psmt.executeQuery();
         while (rs.next())
              maxSerial = rs.getInt(1);
         if (maxSerial < 0)
         maxSerial=Integer.parseInt(startNumber);
         else
              maxSerial+=1;
         rs.close();
    catch(Exception e)
    return String.valueOf(maxSerial);
    /* return next consecutive number
    tablenName - Name of the table for which the number to be generated
         serialFiel - Name of the field for which the number to be generated
         whereString - where condition to filter the records if composite key found,
                        it can be empty if there is no composite primary key.
         Note : if there is no record exists in the table, it starts with 1
    public String getCurrentSerial(String tableName,String serialField,String whereString)
    String queryString = "select max(to_number("+serialField+")) from "+tableName+" "+whereString;
    int maxSerial=0;
    try
         stmt = con.createStatement();
         rs = stmt.executeQuery(queryString);
    while (rs.next())
              maxSerial = rs.getInt(1);
         if (maxSerial < 0)
         maxSerial=1;
         else
              maxSerial+=1;
         rs.close();
    catch(Exception e)
    System.out.println("Error from max serialX:"+e.getMessage());
    return String.valueOf(maxSerial);
    /* return the currnent user name */
    public String getCurrentUser()
    Statement stmt=null;
    ResultSet rs=null;
    String queryString = "select user from dual";
    String userName = "";
    try
    stmt = con.createStatement();
         rs = stmt.executeQuery(queryString);
         while (rs.next())
              userName = rs.getString(1);
         rs.close();
    catch(Exception e)
    return userName;
    /* return current user along with server's current date
    example : userName#today
    public String getCurrentUserDate()
    Statement stmt=null;
    ResultSet rs=null;
    String queryString = "select user,to_char(sysdate,'dd-mon-yyyy') from dual";
    String userName = "";
    String todayDate= "";
    try
    stmt = con.createStatement();
         rs = stmt.executeQuery(queryString);
         while (rs.next())
              userName = rs.getString(1);
                   todayDate = rs.getString(2);
         rs.close();
    catch(Exception e)
    return userName+"#"+todayDate;
    /* return server's current date */
    public String getCurrentDate()
    Statement stmt=null;
    ResultSet rs=null;
    String queryString = "select to_char(sysdate,'dd-mon-yyyy') from dual";
    String todayDate= "";
    try
    stmt = con.createStatement();
         rs = stmt.executeQuery(queryString);
         while (rs.next())
                   todayDate = rs.getString(1);
         rs.close();
    catch(Exception e)
    return todayDate;
    /* return true if atleast one record found in the table
         tblName : Name of the table
         whereString : Where condition to filter the records
    public boolean isRecordExists(String tblName,String whereString)
    String queryString = "select count(1) from "+tblName+" "+whereString;
    boolean recFound = false;
    try
    stmt = con.createStatement();
         rs = stmt.executeQuery(queryString);
         while (rs.next())
         if (rs.getInt(1)==0)
                        recFound = false;
                   else
                        recFound = true;
         rs.close();
    catch(Exception e)
    return recFound;
         // round off decimal Places
    public String fixDecimal(String sourceString,int digits)
    String tmpText="",decimalPart="",returnText="";
    try
    sourceString = String.valueOf(Double.parseDouble(sourceString));
    tmpText = sourceString.substring(sourceString.indexOf(".")+1);
         if (tmpText.length() > digits)
         decimalPart = tmpText.substring(0,digits);
    if (Integer.parseInt(tmpText.substring(digits,digits+1))>=5)
         decimalPart = String.valueOf(Integer.parseInt(decimalPart)+1);
         tmpText = decimalPart;      
         if (decimalPart.length() > 3) // to check wheter 1000 reached, if yes add 1 to actual text      
              returnText = String.valueOf(Integer.parseInt(sourceString.substring(0,sourceString.indexOf(".")))+1);
         else
                   returnText = sourceString.substring(0,sourceString.indexOf("."))+"."+tmpText;
         else // if user entered decimal is with in 3 digits
         if (tmpText.equals("0"))
                   returnText = sourceString.substring(0,sourceString.indexOf("."));
              else               
                   returnText = sourceString.substring(0,sourceString.indexOf("."))+"."+tmpText;
    catch(Exception e)
    System.out.println(e.getMessage());
    return sourceString;
    System.out.println(returnText);
    return returnText;
    } // end of main class
    Access this Bean in JSP as follows:
    <%@ page language="java" %>
    <%@ page import="java.util.*"%>
    <%@ include file="../connectionSetup.jsp"%>
    <jsp:useBean id="dataBeanObj" class="id.dataBean"/>
    <html>
    <head>
         <title>ADDRESS MASTER FORM</title>
    <style type="text/css">      
    .tData
         font-family : sans-serif;
         font-size : 9px;
         font-weight : bolder;
         color : navy;
    .buttonStyle
         font-family : sans-serif;
         font-size :10px;
    </style>
    </head>
    <%
    dataBeanObj.setConnection(con);
    String curCode="";
         String consFld = request.getParameter("consfld")==null?"":request.getParameter("consfld");
         String cat = request.getParameter("cat")==null?"a":request.getParameter("cat").equals("a")?"a":"u";
    boolean updateFlag=false,isWrongCountry=false;
    String code="";
         String name="";
         String add1="";
         String add2="";
         String add3="";
         String state="";
         String country="";
         String zip="";
         String am_pcouncode="";
         String am_pareacode="";
         String am_psubcode="";
         String am_fcouncode="";
         String am_fareacode="";
         String am_fsubcode="";
         String am_phone="";
         String am_fax="";
         String email="";
         String notes="";
         String telex="";
         String mobile="";
         String popup="";
         code = request.getParameter("code")==null?"":request.getParameter("code");
         name = request.getParameter("name")==null?"":request.getParameter("name");
         popup = request.getParameter("popup")==null?"":request.getParameter("popup");
         String submitMode = request.getParameter("submit_mode")==null?"":request.getParameter("submit_mode");
         String editMode = request.getParameter("edit_hidden")==null?"null":request.getParameter("edit_hidden");
         if (name != null && !submitMode.equals("yes")) // ready to retrieve records
         if (!code.equals(""))
              rs = dataBeanObj.getResultSet("select am_code code,am_name name,am_address_1 add1,am_address_2 add2,am_address_3 add3,am_country country,am_state state,am_zip zip,am_phone phone,am_fax fax,am_e_mail email,am_notes notes,am_telex telex,am_mobile mobile from id_vms_address_master where am_code='"+code+"'");
              else
              rs = dataBeanObj.getResultSet("select am_code code,am_name name,am_address_1 add1,am_address_2 add2,am_address_3 add3,am_country country,am_state state,am_zip zip,am_phone phone,am_fax fax,am_e_mail email,am_notes notes,am_telex telex,am_mobile mobile from id_vms_address_master where upper(am_name)='"+name.toUpperCase()+"'");
         if (rs.next()) // if record found
              code = rs.getString("code");          //     retrieve code
              name = rs.getString("name");          //     retrieve name
              add1 = rs.getString("add1");          //     retrieve address 1
              add2 = rs.getString("add2");          //     retrieve address 2
              add3 = rs.getString("add3");          //     retrieve address 3
              country = rs.getString("country");          //     retrieve country
              state = rs.getString("state");          //     retrieve state
              zip = rs.getString("zip");          //     retrieve zip
              am_phone = rs.getString("phone");          //     retrieve phone
              am_fax = rs.getString("fax");          //     retrieve fax
              email = rs.getString("email");          //     retrieve email
              notes = rs.getString("notes");          //     retrieve notes
              telex = rs.getString("telex");          //     retrieve telex number
              mobile = rs.getString("mobile");          //     retrieve mobile number
         else if (submitMode.equals("yes")) // ready to submit
              code = request.getParameter("code");          //     get the input code
              name = request.getParameter("name");          //     get the input name
              add1 = request.getParameter("address1");     //     get the input address 1
              add2 = request.getParameter("address2");     //     get the input address 2
              add3 = request.getParameter("address3");     //     get the input address 3
              country = request.getParameter("country");     //     get the input country
              state = request.getParameter("state");          //     get the input state
              zip = request.getParameter("zip");          //     get the input zip
              am_pcouncode = request.getParameter("pcouncode");          //     get the input phone country code
              am_pareacode = request.getParameter("pareacode");          //     get the input phone area code
              am_psubcode = request.getParameter("psubscode");          //     get the input phone subscriber code
              am_fcouncode = request.getParameter("fcouncode");          //     get the input fax country code
              am_fareacode = request.getParameter("fareacode");          //     get the input fax area code
              am_fsubcode = request.getParameter("fsubscode");          //     get the input fax subscriber code
              am_phone = am_pcouncode+"-"+am_pareacode+"-"+am_psubcode;
              am_fax = am_fcouncode+"-"+am_fareacode+"-"+am_fsubcode;
              telex = request.getParameter("telex");          //     get the input telex
              mobile = request.getParameter("mobile");     //     get the input mobile
              email = request.getParameter("email");          //     get the input email
              notes = request.getParameter("notes");          //     get the input notes
              String colType[] = {"S","S","S","S","S","S","S","S","S","S","S","S","S","S"};
              Vector vec = new Vector();
              if (cat.equals("u"))
                   vec.addElement("am_code");          vec.addElement(code);          //     add code to vector element
              else
              curCode = dataBeanObj.getCurrentSerial("id_vms_address_master","am_code","");
                   vec.addElement("am_code");          vec.addElement(curCode);          //     Next Serial Generation
              vec.addElement("am_name");          vec.addElement(name);          //     add name to vector element
              vec.addElement("am_address_1");     vec.addElement(add1);          //     add address 1 to vector element
              vec.addElement("am_address_2");     vec.addElement(add2);          //     add address 2 to vector element
              vec.addElement("am_address_3");     vec.addElement(add3);          //     add address 3 to vector element
              vec.addElement("am_country");     vec.addElement(country);     //     add country to vector element
              vec.addElement("am_state");          vec.addElement(state);          //     add state to vector element
              vec.addElement("am_zip");          vec.addElement(zip);          //     add zip to vector element
              vec.addElement("am_phone");          vec.addElement(am_phone);          //     add phone to vector element
              vec.addElement("am_fax");          vec.addElement(am_fax);          //     add fax to vector element
              vec.addElement("am_e_mail");          vec.addElement(email);          //     add email to vector element
              vec.addElement("am_notes");          vec.addElement(notes);          //     add notes to vector element
              vec.addElement("am_telex");          vec.addElement(telex);          //     add telex to vector element
              vec.addElement("am_mobile");          vec.addElement(mobile);          //     add mobile to vector element
              if (dataBeanObj.isRecordExists("id_country_master"," where country_code='"+country+"'"))
                   if (cat.equals("u"))
                        // update the records
                        updateFlag = dataBeanObj.updateRecord("id_vms_address_master",vec,colType,"where am_code='"+code+"'");
                   else
                        // insert record
                        updateFlag = dataBeanObj.insertRecordPart("id_vms_address_master",vec,colType);
                   else
                        isWrongCountry=true;               
    %>
    The connectionSetup.jsp is as follows:
    <%@ page import="java.sql.*" %>
    <%@ page import="javax.sql.*" %>
    <%@ page import="javax.naming.*" %>
    <%@ page import="allaire.taglib.*" %>
    <%
         Connection con=null;
         PreparedStatement ps = null;
         Statement stmt=null;
         ResultSet rs=null;
    try
         String jrunDSN = null, lookupDSN = null;
         jrunDSN = request.getParameter("dsnvalue") == null ? "vms_test" : request.getParameter("dsnvalue");
         lookupDSN     = "java:comp/env/jdbc/" + jrunDSN;
         InitialContext ctx     = new InitialContext();
         DataSource     dsn      = (DataSource)ctx.lookup(lookupDSN);
         try
              if (application.getAttribute("connectionapplication") == null)
                   con = dsn.getConnection();
                   application.setAttribute("connectionapplication",con);
              else
              con = (Connection) application.getAttribute("connectionapplication");
         stmt = con.createStatement();
         catch(Exception e)
              con = dsn.getConnection();
              application.setAttribute("connectionapplication",con);
    catch(Exception e)
         out.println("<font face='arial' size='2'><center>Problem with database connection. Please contact your administrator</center></font>");
    %>
    In Connection setup.jsp u can change as u need.
    This is thru JNDI. This works fine for us in our projects.
    Bye.

  • Help needed to optimize the query

    Help needed to optimize the query:
    The requirement is to select the record with max eff_date from HIST_TBL and that max eff_date should be > = '01-Jan-2007'.
    This is having high cost and taking around 15mins to execute.
    Can anyone help to fine-tune this??
       SELECT c.H_SEC,
                    c.S_PAID,
                    c.H_PAID,
                    table_c.EFF_DATE
       FROM    MTCH_TBL c
                    LEFT OUTER JOIN
                       (SELECT b.SEC_ALIAS,
                               b.EFF_DATE,
                               b.INSTANCE
                          FROM HIST_TBL b
                         WHERE b.EFF_DATE =
                                  (SELECT MAX (b2.EFF_DATE)
                                     FROM HIST_TBL b2
                                    WHERE b.SEC_ALIAS = b2.SEC_ALIAS
                                          AND b.INSTANCE =
                                                 b2.INSTANCE
                                          AND b2.EFF_DATE >= '01-Jan-2007')
                               OR b.EFF_DATE IS NULL) table_c
                    ON  table_c.SEC_ALIAS=c.H_SEC
                       AND table_c.INSTANCE = 100;

    To start with, I would avoid scanning HIST_TBL twice.
    Try this
    select c.h_sec
         , c.s_paid
         , c.h_paid
         , table_c.eff_date
      from mtch_tbl c
      left
      join (
              select sec_alias
                   , eff_date
                   , instance
                from (
                        select sec_alias
                             , eff_date
                             , instance
                             , max(eff_date) over(partition by sec_alias, instance) max_eff_date
                          from hist_tbl b
                         where eff_date >= to_date('01-jan-2007', 'dd-mon-yyyy')
                            or eff_date is null
               where eff_date = max_eff_date
                  or eff_date is null
           ) table_c
        on table_c.sec_alias = c.h_sec
       and table_c.instance  = 100;

  • Command the execute sql query and does not clean up data in Table

    Hi Team
    I have an SP, which writes source and target data to Temp Tables and runs except query to get mismatch details
    I am using Exec command to execute source query that writes data to Temp Table, once I execute query using Exec, data is written and immediately #temp table is cleaned, now I cannot use #temp table for comparition.
    Is there any way to execute sql query in SP without using EXEC and will hold the data in temp table.

    You need to create temp table before EXEC statement and rewrite your dynamic query also as below
    declare @source_Sql nvarchar(1000)
    ,@target_Sql nvarchar(1000)
    create table #TempTable1 (name nvarchar(10))
    create table #TempTable2 (name nvarchar(10))
    set @source_Sql = 'INSERT INTO #TempTable1 SELECT [Name] from Employee'
    set @target_Sql = 'INSERT INTO #TempTable2 SELECT [Name] from Employee2'
    EXEC (@source_Sql)   
    EXEC (@target_Sql)             
    select * from #TempTable1 
     Except 
    select * from #TempTable2

  • Need Oracle Payroll SQL Query

    Hello,
    I need Oracle Payroll SQL Query with result:
    First_name, Last_name, Payment_amount, Pay_date, Payroll_Frequency, Employement_status
    Any Help would be greatful appreciated

    You will need the following tales.
    per_all_people_f, per_all_assignments_f,pay_run_results,pay_run_result_values
    Query would e something like :
    select papf.first_name,
             papf.last_name,
             prrv.*
    From  apps.per_all_people_f papf
             apps.per_all_assignments_f paaf
             apps.pay_run_results prr,
             apps.pay_run_result_values prrv
    Where papf.person_id = paaf.person_id
    and papf.business_group_id = paaf.business_group_id
    and papf.current_employee_flag = 'Y'
    and paaf.primary_flag ='Y'
    and paaf.assignment_type = 'E'
    and trunc(sysdate) between papf.effective_start_date and papf.effective_end_date
    and trunc(sysdate) between paaf.effective_start_date and paaf.effective_end_date 
    and prr.assignment_id = paaf.assignment_id

  • How Can I Execute Sql Query in Managed bean?

    Hi,
    I want to execute sql query in managedbean and get the query result. How can I do?
    Best wishes!

    You can do this by having current Database connection your application is using like this
    public static synchronized DBTransaction getDBTransaction(){
    FacesContext ctx = FacesContext.getCurrentInstance();
    ValueBinding vb = ctx.getApplication().createValueBinding("#{data}");
    BindingContext bc = (BindingContext)vb.getValue(ctx.getCurrentInstance());
    DataControl dc = bc.findDataControl("AppModuleDataControl");
    ApplicationModuleImpl am = ((ApplicationModuleImpl)(ApplicationModule)dc.getDataProvider());
    return am.getDBTransaction();
    and then user DBTransaction object to create Statement and PreparedStatement you can find those in java doc.

  • Error in executing SQL query

    Hi All,
    I am working with labview application.
    The database being used is Access.
    The tables i have to use contains the special symbol -   (not underscore.)
    Let the table name be user-data
    When i am executing the query select * from user-data its showing
    error message syntax error in from clause.
    I tried just typing the query in access also and got the same error.
    I believe its because of the usage of the special character other than underscore in table name
    Many applications using the same database is running in VB already.So there is no way for me to rename the table.
    I know i am asking an invalid question.But still....
    Is there any way for me to use the same table name and execute sql query.
    Thanks in advance

    There should be. Try putting the table name in quotes - some DBMS use single quotes, some use double quotes. For example say the table name has a space in it. Try something like:
    select * from 'a funny table';
    or
    select * from "a funny table";   (Actually, I think I'd try this one first...)
    Failing this, you have two choices: change the name of the table, or dump Access and go with a real DBMS - which you will probibly want to do anyway because it will only be a matter of time before you start hitting a performance wall. Access is particularly bad if you have more than one process making a connection to it at a time. Interms of alternatives, there are a couple really good open-source products out there, as well as no-cost versions of Oracle and SQL-Server.
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Help me write a SQL query; urgent

    Hi, can somebody please help me write a SQL query.
    I have 3 tables each with the same column names (Col1, Col2, Col3). Col1 is PK with Unique Constraint.
    I wanted to add values of Col2 and Col3 (from all 3 tables) and put it in a separate table (i.e aggregated) of all values found in Col1.
    Does anybody help me please ?
    thanks alot.

    Please don't mark your question as urgent. You've been around here long enough that you should know that it will not get your question anwered any faster, and may just irritate people into not answering at all.
    I'm not sure exactly what you want.
    Are you saying you want t1.c2 + t1.c3 + t2.c2 + t2.c3+ t3.c2 + t3.c3 for the rows that have the same c1 in all three tables?
    If so, it would be like this, I think: insert into t4
    select t1.c1
    , t1.c2 + t1.c3 + t2.c2 + t2.c3+ t3.c2 + t3.c3
    from t1, t2, t3
    where t2.c1 = t1.c1
    and t3.c1 = t1.c1If that's not what you want, please clarify.
    And next time maybe you should post your SQL question in a SQL forum.

  • Need help in Report From SQL Query

    Hi All,
    I am facing a problem with a report. I need your help.
    I am creating a Report From SQL Query (Portal) with some arguments passed at runtime. I am able to view the output, if the query returns few rows ( arount 1000 rows). But for some inputs it needs to generate >15000 records, at this point the page is getting time out (i think!) and showing error page. I am able to execute query from the SQL Plus console ot using TOAD editor. Here the query is not taking more that 2 mins time to show the result.
    If i am executing from Portal i observed that, once i give the appropriate input and hit submit button a new oracle process is getting created for the query on UNIX (I am usign "TOP" command to check processes). The browser page will be shown error page after 5 minutes (i am assuming session time out!) , but on the backend the process will be executed for more than 30 mins.
    I tried also increase the page time out in httpd.conf, but no use.
    The data returned as a result of the query is sized more than 10 MB. Is caching this much data is possible by the browser page? is the returned data is creating any problem here.
    Please help me to find appropriate reasone for the failure?

    user602513 wrote:
    Hi All,
    I am facing a problem with a report. I need your help.
    I am creating a Report From SQL Query (Portal) with some arguments passed at runtime. I am able to view the output, if the query returns few rows ( arount 1000 rows). But for some inputs it needs to generate >15000 records, at this point the page is getting time out (i think!) and showing error page. I am able to execute query from the SQL Plus console ot using TOAD editor. Here the query is not taking more that 2 mins time to show the result.
    If i am executing from Portal i observed that, once i give the appropriate input and hit submit button a new oracle process is getting created for the query on UNIX (I am usign "TOP" command to check processes). The browser page will be shown error page after 5 minutes (i am assuming session time out!) , but on the backend the process will be executed for more than 30 mins.
    I tried also increase the page time out in httpd.conf, but no use.
    The data returned as a result of the query is sized more than 10 MB. Is caching this much data is possible by the browser page? is the returned data is creating any problem here.
    Please help me to find appropriate reasone for the failure?Do you get any errors or warnings or it is just the slow speed which is the issue?
    There could be a variety of reasons for the delayed processing of this report. That includes parameter settings for that page, cache settings, network configurations, etc.
    - explore best optimization for your query;
    - evaluate portal for best performance configuration; you may follow this note (Doc ID: *438794.1* ) for ideas;
    - third: for that particular page carrying that report, you can use caching wisely. browser cache is neither decent for large files, nor practical. instead, explore the page cache settings that portal provides.
    - also look for various log files (application.log and apache logs) if you are getting any warnings reflecting on some kind of processing halt.
    - and last but not the least: if you happen to bring up a portal report with more than 10000 rows for display then think about the usage of the report. Evaluate whether that report is good/useful for anything?
    HTH
    AMN

  • Need help in rewriting a sql query

    Can any one please tell me if there is any utility that can help me correcting the sql I have I need to tune the query as its taking lot of time. I want to use some tool that will help me re-formating the query.
    Any help in this regard will be highly appreciated.

    If you think that Oracle SQL Tuning Tools like SQL Tuning Advisor and SQL Access Advisor are not helping.
    You might look into thrid party tools like Quest- SQL Navigator and TOAD.
    But I don't advise this based on the following:
    Re: Oracle Third Party Tools and Oracle Database
    Oracle have enough tools of its own to satisfy the various needs.
    Adith

  • Help needed in executing pl/sql programs

    hi all
    iam new to PL/SQL programming
    i have installed oracle 9i
    iam trying to practice some sample pl/sql programs
    i have opened oracle 9i and typed these commands
    sql>ed sum
    then a notepad opens where i type my pl/sql program and save it and then return back to oracle 9i and type this
    sql>@ sum
    then my pl/sql program gets executed.......but iam not getting any output
    its comig as procedure implemented succesfully
    is it compulsory to open notepad to execute pl/sql progams or we can direclty type the programs in oracle 9i
    please help in this matter ASAP
    Regards
    Suresh

    Yes, you can type the program directly at the SQL prompt, but editing will be a bit difficult.
    You should use some good editor that allows you to edit properly and then run like you did.
    You need to do:
    SQL> set serveroutput onbefore running your program to see dbms_output messages.

  • Need Help with Creating the SQl query

    Hi,
    SQL query gurus...
    INFORMATION:
    I have two table, CURRENT and PREVIOUS.(Table Defs below).
    CURRENT:
    Column1 - CURR_PARENT
    Column2 - CURR_CHILD
    Column3 - CURR_CHILD_ATTRIBUTE 1
    Column4 - CURR_CHILD_ATTRIBUTE 2
    Column5 - CURR_CHILD_ATTRIBUTE 3
    PREVIOUS:
    Column1 - PREV_PARENT
    Column2 - PREV_CHILD
    Column3 - PREV_CHILD_ATTRIBUTE 1
    Column4 - PREV_CHILD_ATTRIBUTE 2
    Column5 - PREV_CHILD_ATTRIBUTE 3
    PROBLEM STATEMENT
    Here the columns 3 to 5 are the attributes of the Child. Lets assume that I have two loads, One Today which goes to the CURRENT table and one yesterday which goes to the PREVIOUS table. Between these two loads there is a CHANGE in the value for Columns either 3/4/5 or all of them(doesnt matter if one or all).
    I want to determine what properties for the child have changed with the help of a MOST efficient SQL query.(PARENT+CHILD is unique key). The Database is ofcourse ORACLE.
    Please help.
    Regards,
    Parag

    Hi,
    The last message was not posted by the same user_name that started the thread.
    Please don't do that: it's confusing.
    Earlier replies give you the information you want, with one row of output (maximum) per row in current_tbl. There may be 1, 2 or 3 changes on a row.
    You just have to unpivot that data to get one row for every change, like this:
    WITH     single_row  AS
         SELECT     c.curr_parent
         ,     c.curr_child
         ,     c.curr_child_attribute1
         ,     c.curr_child_attribute2
         ,     c.curr_child_attribute3
         ,     DECODE (c.curr_child_attribute1, p.prev_child_attribute1, 0, 1) AS diff1
         ,     DECODE (c.curr_child_attribute2, p.prev_child_attribute2, 0, 2) AS diff2
         ,     DECODE (c.curr_child_attribute3, p.prev_child_attribute3, 0, 3) AS diff3
         FROM     current_tbl    c
         JOIN     previous_tbl   p     ON  c.curr_parent     = p.prev_parent
                                AND c.curr_child     = p.prev_child
         WHERE     c.curr_child_attribute1     != p.prev_child_attribute1
         OR     c.curr_child_attribute2     != p.prev_child_attribute2
         OR     c.curr_child_attribute3     != p.prev_child_attribute3
    ,     cntr     AS
         SELECT     LEVEL     AS n
         FROM     dual
         CONNECT BY     LEVEL <= 3
    SELECT     s.curr_parent     AS parent
    ,     s.curr_child     AS child
    ,     CASE     c.n
              WHEN  1  THEN  s.curr_child_attribute1
              WHEN  2  THEN  s.curr_child_attribute2
              WHEN  3  THEN  s.curr_child_attribute3
         END          AS attribute
    ,     c.n          AS attribute_value
    FROM     single_row     s
    JOIN     cntr          c     ON     c.n IN ( s.diff1
                                    , s.diff2
                                    , s.diff3
    ORDER BY  attribute_value
    ,            parent
    ,            child
    ;

Maybe you are looking for

  • How to put in Capital letter  a value of a field in Report ?

    Hello, In my report, there is a field that the value is in small letter. Then I want to put it in capital letter always. How must I realize it ? Regardly.

  • Automatic Service purchase requisiton from sales order

    Gurus, We have a business scenario where , service purchase requsition needs to be created automatically from a sales order. Could you please let us know whether anybody has worked on this scenario ? Kindly also suggest if any workaround can make thi

  • Bioware trying to make up for ME3 single player?

    Well anyone that has played ME3 multiplayer knows that they continue to throw us more and more DLC content for absolutely free. Next week isn't an exception. Debuting the 9th for absolutely free is the *drumrole* THE COLLECTORS New weapons, new enemi

  • Sending data through a serial write box (vision processing)

    Hi there, I am fairly new to labview and vision assistant. I was wondering if I could get some assistance on a particular problem we are having with our project. The idea is that we will use a webcamera to analyze a continuous loop of images and iden

  • Dynamic Time Series with Planning connection?

    Hi guys, I have built some reports in HFR, with a connection to a Planning application (the architect requested so). But the only way to get the YTD function properly working is using an Essbase connection (I got an error with the Planning connection