Outputting SQL statement into HTML table

ok, my problem is that i can only output the first row from my table in my DB and i want to be able to display all the rows from that table which are of a particular type..maybe someone here can help..
and if anyone thinks the code is a bit pants please say why..cheers
import java.lang.*;
import java.util.*;
import java.io.*;
import java.util.Vector;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class StockStats3 extends HttpServlet
     String totalStock = "";
     String itemName = "";
     int type = 0;
     int itemId = 0;
     Statement stmt = null;
     ResultSet rs = null;
     Connection con = null;
     String query;
     PrintWriter out;     
     String url = "jdbc:mysql://macneill.cs.tcd.ie/odriscoi_db";
     public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
               out= response.getWriter();
               response.setContentType("text/html");
               out.println("<HTML>");
               out.println("<HEAD>");
               out.println("<TITLE> Check Current Stock </TITLE>");
               out.println("</HEAD>");
               out.println("<body bgcolor=#FFFFFF background=\"U:/back.jpg\" link = white vlink = white>");
               out.println("<font color=#FFFFFF face=COMIC SANS MS size=3>");
               out.print("<form action=\"");
               out.print("StockStats3\" ");
               out.println("method=POST>");
               out.println("<TD><h3><LEFT><font color=#FFFFFF face=COMIC SANS MS size=5>Click on Relevant Button to view Current Stock: </h3></TD>");
               out.println("<TD><h3><LEFT><font color=#FFFFFF face=COMIC SANS MS size=3>KITCHEN FOODS: </h3></TD>");
               out.println("<input type=submit name=action value=\"Meat \">");
               out.println("<input type=submit name=action value=\"Fish\">");
               out.println("<input type=submit name=action value=\"Fruit\">");
               out.println("<input type=submit name=action value=\"Veg\">");
               out.println("<input type=submit name=action value=\"Dairy\">");
               out.println("<input type=submit name=action value=\"Herbs\">");
               out.println("<input type=submit name=action value=\"Pasta\">");
               out.println("<input type=submit name=action value=\"Sauces\">");
               out.println("<input type=submit name=action value=\"Condiments\">");
               out.println("<input type=submit name=action value=\"Total Food\">");
               out.println("<TD><h3><LEFT><font color=#FFFFFF face=COMIC SANS MS size=3>BAR DRINKS: </h3></TD>");
               out.println("<input type=submit name=action value=\"Soda\">");
               out.println("<input type=submit name=action value=\"Water\">");
               out.println("<input type=submit name=action value=\"Beer\">");
               out.println("<input type=submit name=action value=\"Wine\">");
               out.println("<input type=submit name=action value=\"Total Drink\">");
               out.println("<PRE>");
               out.println("<CENTER><TH><h3><A HREF= \"ManageOption \"><FONT face=arial>Back to Options</FONT></A></h3></TH><BR>");
               out.println("</PRE>");
               out.println("<PRE>");
               out.println("<CENTER><TH><h3><A HREF= \"log \"><FONT face=arial>logout</FONT></A></h3></TH><BR>");
               out.println("</PRE>");
               out.println("<BR>");
               out.println("</TR>");
               out.println("</BODY>");
          out.println("</HTML>");
          out.close();
     public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
               String msg11 = "";
               String msg12 = "";
               String msg13 = "";
               String msg14 = "";
               String msg15 = "";
               String msg16 = "";
          String msg17 = "";
          String msg18 = "";
          String msg19 = "";
          String msg20 = "";
               String msg2 = "";
          String msg3 = "";
          String msg4 = "";
          String msg5 = "";
               String msg6 = "";
               String msg7 = "";
               String msg8 = "";
               String msg9 = "";
     if (request.getParameter("action").equals("Meat"))
               msg11 = getItemName(1);
               msg12 = getStock(1);               
               msg13 = getItemName(1);
               msg14 = getStock(1);
               msg15 = getItemName(2);
               msg16 = getStock(2);
               msg17 = getItemName(3);
               msg18 = getStock(3);
               msg19 = getItemName(4);
               msg20 = getStock(4);
          //im only trying to work on one table at the moment
     if (request.getParameter("action").equals("Fish"))
          msg2 = getStock(5);
     if (request.getParameter("action").equals("Fruit"))
          msg3 = getStock(6);
     if (request.getParameter("action").equals("Veg"))
          msg4 = getStock(7);
     if (request.getParameter("action").equals("Dairy"))
          msg5 = getStock(8);
     if (request.getParameter("action").equals("Herbs"))
          msg6 = getStock(9);
     if (request.getParameter("action").equals("Pasta"))
          msg7 = getStock(10);
     if (request.getParameter("action").equals("Sauces"))
          msg8 = getStock(11);
     if (request.getParameter("action").equals("Condiments"))
          msg9 = getStock(12);
               response.setContentType("text/html");
                    PrintWriter out = response.getWriter();
                    out.println("<HTML>");
                    out.println("<HEAD>");
                    out.println("<TITLE>Stock Results </TITLE>");
                    out.println("</HEAD>");
                    out.println("<body bgcolor=#FFFFFF background=\"U:/back.jpg\" link = white vlink = white>");
                    out.println("<font color=#FFFFFF face=COMIC SANS MS size=3>");
                    out.print("<form action=\"");
                    out.print("StockStats3\" ");
                    out.println("method=POST>");
                    out.println("<BR>");
                    out.println("</H2><TABLE BORDER='1' CELLSPACING='2' CELLPADDING='2'>");
                    out.println("<font color=#FFFFFF face=COMIC SANS MS size=3>");
                    out.println("<TR><TH><B>Item Name</B></TH><TH><B>Portions</B></TH></TR>");
                    out.println("<TR><TD>"+getItemName(itemId)+"</TD><TD>"+getStock(itemId)+"</TD></TR>");
                    out.println("</TABLE>");
                    out.println("<BR>");
                    out.println("<CENTER><TH><h3><A HREF= \"StockStats3 \"><FONT face=arial>Back</FONT></A></h3></TH><BR>");
                    out.println("</PRE>");
                    out.println("<PRE>");
                    out.println("<CENTER><TH><h3><A HREF= \"ManageOption \"><FONT face=arial>Back to Options</FONT></A></h3></TH><BR>");
                    out.println("</PRE>");
                    out.println("<PRE>");
                    out.println("<CENTER><TH><h3><A HREF= \"log \"><FONT face=arial>logout</FONT></A></h3></TH><BR>");
                    out.println("</PRE>");
                    out.println("<BR>");
                    out.println("</FORM>");
                    out.println("");
                    out.println("</BODY>");
                    out.println("</HTML>");
//This method is used to retrieve the total stock of each item
     private String getStock(int itemId) throws ServletException, IOException
          String result = "";     
          try
               String driver = "org.git.mm.mysql.Driver";
               try
                    Class.forName(driver).newInstance();
                    //out.println("Driver Called!");
               catch(java.lang.ClassNotFoundException e)
          System.err.print("Couldn't find ClassNotFoundException: ");
          System.err.println(e.getMessage());
          out.println(e.getMessage());
               catch(Exception ex)
                    ex.printStackTrace();
               Connection con = DriverManager.getConnection(url, "odriscoi", "3vk7WgdO");
               //out.println("Connection made!");
               Statement stmt = con.createStatement();
               //get stock of items
               String query = "SELECT Portions FROM Kitchen WHERE Item_ID = '"+itemId+"';";
               result = query;
               ResultSet rs = stmt.executeQuery(query);
               while(rs.next())
                    totalStock = rs.getString("Portions");
               rs.close();
               stmt.close();
     con.close();
     catch(SQLException ex)
     out.println("SQLException: " + ex.getMessage());
     return totalStock;
//Ths method is used to retrieve the name of each item
     private String getItemName(int itemId) throws ServletException, IOException
          String result = "";     
          try
               String driver = "org.git.mm.mysql.Driver";
               try
                    Class.forName(driver).newInstance();
                    //out.println("Driver Called!");
               catch(java.lang.ClassNotFoundException e)
          System.err.print("Couldn't find ClassNotFoundException: ");
          System.err.println(e.getMessage());
          out.println(e.getMessage());
               catch(Exception ex)
                    ex.printStackTrace();
               Connection con = DriverManager.getConnection(url, "odriscoi", "3vk7WgdO");
               //out.println("Connection made!");
               Statement stmt = con.createStatement();
               //get name of item
               String query = "SELECT item FROM Kitchen WHERE item_ID = '"+itemId+"';";
               result = query;
               ResultSet rs = stmt.executeQuery(query);
               while(rs.next())
                    itemName = rs.getString("item");
               rs.close();
               stmt.close();
     con.close();
     catch(SQLException ex)
     out.println("SQLException: " + ex.getMessage());
     return itemName;

the following is my code to retrieve a table, maybe it gives u some ideas.
Wolf
==========================================================================
import java.io.*;
import java.sql.*;
import javax.naming.*;
import javax.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Test extends HttpServlet {
     public void service(ServletRequest request, ServletResponse response)
          throws ServletException, IOException {
          Context initCtx=null;
          Context envCtx=null;
          DataSource ds=null;
          Connection conn=null;
          Statement stmt=null;
          ResultSet rs=null;
          response.setContentType("text/html");
          PrintWriter out = response.getWriter();
          try {
               initCtx = new InitialContext();
               envCtx = (Context)initCtx.lookup("java:comp/env");
               ds = (DataSource)envCtx.lookup("jdbc/Bookingcomputer");
               conn = ds.getConnection();
               stmt=conn.createStatement();
//               rs=stmt.executeQuery("SELECT s_code, description FROM computer");
               rs=stmt.executeQuery("SELECT * FROM computer");
               out.println("<HTML><HEAD><TITLE>Computer List</TITLE></HEAD>");
               out.println("<BODY>");
               out.println("<UL>");
               out.println("<CENTER><FONT SIZE=\"4\"><B>ERC Computer List</B></FONT></CENTER>");
               out.println("<center><table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"80%\" id=\"AutoNumber1\">");
               while(rs.next()) {
                    out.println("<tr>");
                    out.print("<td width=\"10\">");
                    out.print("<LI>");
                    out.print("</td>");
                    out.print("<td width=\"25%\"><B>");
                    out.print(rs.getString("s_code"));
                    out.print("</B></td>");
                    out.print("<td width=\"50%\">");
                    out.print(rs.getString("description"));
                    out.print("</td>");
                    out.print("<td width=\"25%\">");
                    out.print(rs.getString("capacity"));
                    out.print("</td>");
//                    out.println("<LI>"+rs.getString("s_code")+" "+rs.getString("description") );
                    out.println("</tr>");
               out.println("</table></center>");
               out.println("</UL>");
//               out.println("Hi Arthur, How are you doing?");
               out.println("</BODY></HTML>");
          catch(SQLException ex) {
               System.err.println("SQLException:"+ex.getMessage());
          } catch (NamingException e) {
               e.printStackTrace();
          finally {
               try {
                    if (conn!=null)
                         conn.close();
               }catch(SQLException e){
                    e.printStackTrace();

Similar Messages

  • Execute the sql statement stored in table

    friends i m in complication that, how can i execute sql statement which is stored in database table.
    how can i fetch that particular statement from table and make it execute!!!
    Thanks in advance

    I think we should stop at this point and have a little think.
    My understanding is that your plan is to do the following
    -Execute a Dynamic SQL statement which is constructed from values in several columns in a table (Bad idea to begin with)
    -The result of the execution is then loaded into PL/SQL.....not sure how you are handling different column lists but I'll assume you are not having to convert every column value to a VARCHAR2
    -The values returned are then used in an INSERT statement
    So basically your goal here is to take some data from one table and insert it into another table by moving data from SQL to PL/SQL then back to SQL in an elaborate, dynamic way. This is a costly waste of resources and will not scale (this is before we get to the problem of having to read the SQL statement from a table in the first place)
    I would recommend looking the INSERT SELECT statement here: http://psoug.org/reference/insert.html
    This will get the job done in one go. If you really do need it to be dynamic (which you don't, trust me) then you can still store this statement in your "dynamic SQL" table and execute it using EXECUTE IMMEDIATE although I can say for sure that you're going to run into more problems down the line with this architecture, it won't scale very well, and you'll probably waste at least *1* day of your time every week trying to fix a bug caused by the removal of a table, change to a column name etc.......
    However if you believe that storing SQL in a table is the best solution to your problem then go ahead.....at least when you find out that it isn't you'll have learned a valuable lesson.

  • Sql statement in a table not accepting variable

    I have the following problem on 10.1.0.3.0 with varialbe in an execute immediate statement
    here is the code that I am using
    declare
    remote_data_link varchar2(25) := 'UDE_DATATRANSFER_LINK';
    FROM_SCHEMA VARCHAR2(40) := 'UDE_OLTP';
    l_last_process_date date := to_date(to_char(sysdate,'mm-dd-yyyy hh:mi:ss'),'mm-dd-yyyy hh:mi:ss') - 1;
    stmt varchar2(4000) := 'MERGE into applicant_adverseaction_info theTarget USING (select * from '||FROM_SCHEMA||'.applicant_adverseaction_info@'||remote_data_link||' where last_activity > :l_last_process_date ) theSource ON(theTarget.applicant_id = theSource.applicant_id) WHEN MATCHED THEN UPDATE SET theTarget.cb_used = theSource.cb_used, theTarget.cb_address = theSource.cb_address, theTarget.scoredmodel_id = theSource.scoredmodel_id, theTarget.last_activity = theSource.last_activity WHEN NOT MATCHED THEN INSERT(CB_USED, CB_ADDRESS, SCOREDMODEL_ID, APPLICANT_ID, LAST_ACTIVITY) values(theSource.cb_used, theSource.cb_address, theSource.scoredmodel_id, theSource.applicant_id, theSource.last_activity)';
    stmt2 varchar2(4000) := 'MERGE into edm_application theTarget USING (select * from '||from_schema||'.edm_application@'||remote_data_link||' where last_activity > :l_last_process_date) theSource ON (theTarget.edm_appl_id = theSource.edm_appl_id) WHEN MATCHED THEN UPDATE SET theTarget.APP_REF_KEY = theSource.APP_REF_KEY, theTarget.IMPORT_REF_KEY = theSource.IMPORT_REF_KEY, theTarget.LAST_ACTIVITY = theSource.LAST_ACTIVITY WHEN NOT MATCHED THEN INSERT (EDM_APPL_ID, APP_REF_KEY, IMPORT_REF_KEY, LAST_ACTIVITY) values(theSource.EDM_APPL_ID, theSource.APP_REF_KEY, theSource.IMPORT_REF_KEY, theSource.LAST_ACTIVITY)';
    v_error varchar2(4000);
    T_MERGE VARCHAR2(4000);
    stmt3 varchar2(4000);
    BEGIN
    select merge_sql
    INTO T_MERGE
    from transfertables
    where table_name= 'edm_application';
    remote_data_link:= 'UDE_DATATRANSFER_LINK';
    FROM_SCHEMA := 'UDE_OLTP';
    --DBMS_OUTPUT.PUT_LINE(SUBSTR(stmt2,1,200));
    --STMT2 := T_MERGE;
    dbms_output.put_line(from_schema||' '||remote_data_link||' '||l_last_process_date);
    EXECUTE IMMEDIATE stmt2 using l_last_process_date;
    --execute immediate stmt3 ;
    dbms_output.put_line(from_schema||' '||remote_data_link||' '||l_last_process_date);
    dbms_output.put_line(substr(stmt2,1,200));
    commit;
    EXCEPTION
    WHEN OTHERS THEN
    V_ERROR := SQLCODE||' '||SQLERRM;
    v_ERROR := V_ERROR ||' '||SUBSTR(stmt2,1,200);
    DBMS_OUTPUT.PUT_LINE(V_ERROR);
    --dbms_output.put_line(substr(stmt2,1,200));
    END;
    This works perfectly
    but if I change it to get the same statement in a db table
    declare
    remote_data_link varchar2(25) := 'UDE_DATATRANSFER_LINK';
    FROM_SCHEMA VARCHAR2(40) := 'UDE_OLTP';
    l_last_process_date date := to_date(to_char(sysdate,'mm-dd-yyyy hh:mi:ss'),'mm-dd-yyyy hh:mi:ss') - 1;
    stmt varchar2(4000) := 'MERGE into applicant_adverseaction_info theTarget USING (select * from '||FROM_SCHEMA||'.applicant_adverseaction_info@'||remote_data_link||' where last_activity > :l_last_process_date ) theSource ON(theTarget.applicant_id = theSource.applicant_id) WHEN MATCHED THEN UPDATE SET theTarget.cb_used = theSource.cb_used, theTarget.cb_address = theSource.cb_address, theTarget.scoredmodel_id = theSource.scoredmodel_id, theTarget.last_activity = theSource.last_activity WHEN NOT MATCHED THEN INSERT(CB_USED, CB_ADDRESS, SCOREDMODEL_ID, APPLICANT_ID, LAST_ACTIVITY) values(theSource.cb_used, theSource.cb_address, theSource.scoredmodel_id, theSource.applicant_id, theSource.last_activity)';
    stmt2 varchar2(4000) := 'MERGE into edm_application theTarget USING (select * from '||from_schema||'.edm_application@'||remote_data_link||' where last_activity > :l_last_process_date) theSource ON (theTarget.edm_appl_id = theSource.edm_appl_id) WHEN MATCHED THEN UPDATE SET theTarget.APP_REF_KEY = theSource.APP_REF_KEY, theTarget.IMPORT_REF_KEY = theSource.IMPORT_REF_KEY, theTarget.LAST_ACTIVITY = theSource.LAST_ACTIVITY WHEN NOT MATCHED THEN INSERT (EDM_APPL_ID, APP_REF_KEY, IMPORT_REF_KEY, LAST_ACTIVITY) values(theSource.EDM_APPL_ID, theSource.APP_REF_KEY, theSource.IMPORT_REF_KEY, theSource.LAST_ACTIVITY)';
    v_error varchar2(4000);
    T_MERGE VARCHAR2(4000);
    stmt3 varchar2(4000);
    BEGIN
    select merge_sql
    INTO T_MERGE
    from transfertables
    where table_name= 'edm_application';
    remote_data_link:= 'UDE_DATATRANSFER_LINK';
    FROM_SCHEMA := 'UDE_OLTP';
    --DBMS_OUTPUT.PUT_LINE(SUBSTR(stmt2,1,200));
    STMT2 := T_MERGE;
    dbms_output.put_line(from_schema||' '||remote_data_link||' '||l_last_process_date);
    EXECUTE IMMEDIATE stmt2 using l_last_process_date;
    --execute immediate stmt3 ;
    dbms_output.put_line(from_schema||' '||remote_data_link||' '||l_last_process_date);
    dbms_output.put_line(substr(stmt2,1,200));
    commit;
    EXCEPTION
    WHEN OTHERS THEN
    V_ERROR := SQLCODE||' '||SQLERRM;
    v_ERROR := V_ERROR ||' '||SUBSTR(stmt2,1,200);
    DBMS_OUTPUT.PUT_LINE(V_ERROR);
    --dbms_output.put_line(substr(stmt2,1,200));
    END;
    I get ora-00900 invalid sql statement
    can somebody explain why this happens
    Thanks

    I agree with jan and anthony. Your post is too long and ill-formatted. However here's my understanding of your problem (with examples though slightly different ones).
    1- I have a function that returns number of records in a any given table.
      1  CREATE OR REPLACE FUNCTION get_count(p_table varchar2)
      2     RETURN NUMBER IS
      3     v_cnt number;
      4  BEGIN
      5    EXECUTE IMMEDIATE('SELECT count(*) FROM '||p_table) INTO v_cnt;
      6    RETURN v_cnt;
      7* END;
    SQL> /
    Function created.
    SQL> SELECT get_count('emp')
      2  FROM dual
      3  /
    GET_COUNT('EMP')
                  14
    2- I decide to move the statement to a database table and recreate my function.
    SQL> CREATE TABLE test
      2  (stmt varchar2(2000))
      3  /
    Table created.
    SQL> INSERT INTO test
      2  VALUES('SELECT count(*) FROM p_table');
    1 row created.
    SQL> CREATE OR REPLACE FUNCTION get_count(p_table varchar2)
      2     RETURN NUMBER IS
      3     v_cnt number;
      4     v_stmt varchar2(4000);
      5  BEGIN
      6     SELECT stmt INTO v_stmt
      7     FROM test;
      8     EXECUTE IMMEDIATE(v_stmt) INTO v_cnt;
      9     RETURN v_cnt;
    10  END;
    11  /
    Function created.
    SQL> SELECT get_count('emp')
      2  FROM dual
      3  /
    SELECT get_count('emp')
    ERROR at line 1:
    ORA-00942: table or view does not exist
    ORA-06512: at "SCOTT.GET_COUNT", line 8
    ORA-06512: at line 1
    --p_table in the column is a string and has nothing to do with p_table parameter in the function. And since there's no p_table table in my schema function returns error on execution. I suppose this is what you mean by "sql statement in a table not accepting variable"
    3- I rectify the problem by recreating the function.
      1  CREATE OR REPLACE FUNCTION get_count(p_table varchar2)
      2     RETURN NUMBER IS
      3     v_cnt number;
      4     v_stmt varchar2(4000);
      5  BEGIN
      6     SELECT replace(stmt,'p_table',p_table) INTO v_stmt
      7     FROM test;
      8     EXECUTE IMMEDIATE(v_stmt) INTO v_cnt;
      9     RETURN v_cnt;
    10* END;
    SQL> /
    Function created.
    SQL> SELECT get_count('emp')
      2  FROM dual
      3  /
    GET_COUNT('EMP')
                  14
    Hope this gives you some idea.-----------------------
    Anwar

  • How to store output of SQ01 into internal table.

    Hello Experts
    How to store output of SQ01 into internal table.
    Thanks,
    Umesh

    You can't store the sq01 output into internal table.
    Once you create the query it will generate the abap program, in that program you can see the contents.
    Regards
    Sasi

  • Sql statement for a table name with a space in between

    Hi,
    I just noticed that one of my tables for Access is consisted of two word. It is called "CURRENT CPL". How would I put this table name into an sql statement. When I did what I normally do, it only reads the CURRENT and thinks that's the table name.
    Thanks
    Feng

    I just noticed that one of my tables for Access is
    consisted of two word. It is called "CURRENT CPL".
    How would I put this table name into an sql
    statement. When I did what I normally do, it only
    reads the CURRENT and thinks that's the table name.That is called a quoted identifier. The SQL (not java) for this would look like this....
    select "my field" from "CURRENT CPL"
    The double quote is the correct character to use. Note that quoted identifiers are case sensitive, normal SQL is not.

  • Using Oracle Forms Importing Data From SQL Server into Oracle Tables.

    Dear All,
    We are using Oracle Forms 10g in windows XP and having OAS 10g and Oracle database 9i.
    How can we import data from SQL Server 2005 into Oracle tables using Oracle Forms?
    Thanks & Regards
    Eidy

    I have no idea what "Oracle Hetrogenius Services" is, so I can't help you with that, sorry.
    SQL Developer might also assist you. SQL Developer can connect to SQL Server as well as Oracle and has some tools for migration. See the documentation for details:
    http://download.oracle.com/docs/cd/E12151_01/doc.150/e12156/toc.htm
    For additional help on using SQL Developer for this task, please consult Support or the SQL Developer forum: SQL Developer
    Hope this helps,
    Jacob

  • How to store sql statement in oracle table?

    I tried it in this way:
    SQL> insert into sql_text values('select invoice,invoice_dt,DT_INVOICED from PS_BI_HDR where DT_INVOICED= '21
    JAN-2010' and BILL_STATUS='INV'');
    insert into sql_text values('select invoice,invoice_dt,DT_INVOICED from PS_BI_HDR where DT_INVOICED= '21-JAN-
    010' and BILL_STATUS='INV'')
    ERROR at line 1:
    ORA-00917: missing comma
    Please help to solve it, i can't use concatenation (||),
    coz
    'select invoice,invoice_dt,DT_INVOICED from PS_BI_HDR where DT_INVOICED= '21-JAN-2010' and BILL_STATUS='INV' 'it is dynamic.

    user2060331 wrote:
    No sql statement is a dynamic value inserted by a user for executing it on SQl prompt.Then use q-literals:
    SQL> ACCEPT stmt PROMPT "Enter statement: "
    Enter statement: select invoice,invoice_dt,DT_INVOICED from PS_BI_HDR where DT_INVOICED= '21-JAN-2010' and BILL_STATUS='INV'
    SQL> insert into sql_text values('&stmt');
    old   1: insert into sql_text values('&stmt')
    new   1: insert into sql_text values('select invoice,invoice_dt,DT_INVOICED from PS_BI_HDR where DT_INVOICED= '21-JAN-2010' and BILL_STATUS='INV'')
    insert into sql_text values('select invoice,invoice_dt,DT_INVOICED from PS_BI_HDR where DT_INVOICED= '21-JAN-2010' and BILL_STATUS='INV'')
    ERROR at line 1:
    ORA-00917: missing comma
    SQL> insert into sql_text values(q'[&stmt]');
    old   1: insert into sql_text values(q'[&stmt]')
    new   1: insert into sql_text values(q'[select invoice,invoice_dt,DT_INVOICED from PS_BI_HDR where DT_INVOICED= '21-JAN-2010' and BILL_STATUS='INV']')
    1 row created.
    SQL> SY.

  • Sql statement for join tables

    hi there..i need ur helps
    Here are my tables n column name for each tables
    a) rep_arrngt
    Name
    REP_ARRNGT_ID
    REP_ARRNGT_DESC
    REP_ARRNGT_TYPE
    ACCT_CAT
    DEF_INDUSTRY_CODE
    MEDIA_ID
    LANGUAGE_ID
    CURRENCY
    PAGE_ID
    b) bci_rep_arrng
    Name
    REP_ARRNGT_ID
    BCI
    SUB_SUM_CODE
    DP_SUB_SUM_CODE
    c) acct_rep_arrngt_link
    Name
    ACCT_NO
    REP_ARRNGT_ID
    DOC_TYPE
    LAST_BILL_DATE
    BILL_FREQUENCY
    SCALING
    EFF_FROM_DATE
    EFF_TO_DATE
    MEDIA_ID
    Actually, i want to get the unique value for sub_sum_code according to the bci..
    i already use join tables n here is my sql statement :
    SELECT T1.SUB_SUM_CODE,T1.BCI,T1.REP_ARRNGT_ID,T2.REP_ARRNGT_ID,T3.REP_ARRNGT_ID FROM BCI_REP_ARRNG T1, REP_ARRNGT T2, ACCT_REP_ARRNGT_LINK T3 WHERE T1.REP_ARRNGT_ID=T2.REP_ARRNGT_ID AND T2.REP_ARRNGT_ID=T3.REP_ARRNGT_ID AND BCI='TTA00F06'
    n my results is :
    SUB_SUM_CODE BCI REP_ARRNGT_ID
    TBGSR TTA00F06 R1
    TBGSR TTA00F06 R1
    TBGSR TTA00F06 R1
    TBGSR TTA00F06 R1
    I get the repeated results for sub_sum_code..
    so, what i need to do if i want only 1 row results like this :
    [u]SUB_SUM_CODE BCI REP_ARRNGT_ID
    TBGSR TTA00F06 R1
    i try to use group by, but i get the error..plz help me

    If you only want "to get the unique value for sub_sum_code according to the bci" then why are you joining the tables in the first place? Not knowing PKs etc you could just use DISTINCT in your select statement.
    SELECT DISTINCT T1.SUB_SUM_CODE,
                    T1.BCI
    FROM BCI_REP_ARRNG T1
    AND BCI='TTA00F06'

  • SQL statement  - INTO

    I have this SQL statement below:
    SELECT SUM(debit_balance)in_amt,SUM(credit_balance)co_num INTO l_amt_debit,l_amt_credit, src_customer_id From sh_ba_balance where src_customer_id = t.src_customer_id GROUP BY src_customer_id HAVING COUNT (src_customer_id) = 1;However, I encountered this error:
    PLS-00201: identifier 'SRC_CUSTOMER_ID' must be declaredHow should I modify my SQL statement to solve this error?

    Hi,
    i dont understand what you are trying to achieve here,
    SELECT (CASE
               WHEN NVL(SUM(debit_balance),0)
               THEN 0
               ELSE SUM(debit_balance)
               END
               )AS in_amt,
               (CASE
               WHEN NVL(SUM(credit_balance),0)
               THEN 0
               ELSE SUM(credit_balance)
               END
               )AS co_amt
        INTO l_amt_debit,l_amt_credit
        From sh_ba_balance where src_customer_id = t.src_customer_id GROUP BY src_customer_id HAVING COUNT (src_customer_id) = 1;
       (Case
             When Nvl(Sum(Debit_Balance), 0) Then
              0
             Else
              Sum(Debit_Balance)
           End) As In_Amt,
    both times you are doing same thing ? case is of no use here,
      (Case
             When Nvl(Sum(Credit_Balance), 0) Then
              0
             Else
              Sum(Credit_Balance)
           End)
    here also same thing,
    besides the nvl should be given to column name and not on sum...
    sum(nvl(colname,0))
    and regarding your error code
    http://www.techonthenet.com/oracle/errors/ora00920.php
    also i am not sure which docs you saw regards
    nic

  • Servlet into html table ?

    hi
    can i put servlet at html table ?
    how ?
    thanks

    If you mean "can I write from the servlet's Post / Get method into a html table on the client"
    Yes, all you need do is get the response objects Writer()
    (I think the method is response.getWriter())
    then just call println("VALID HTML DOC")
    where VALID HTML DOC is a properly formed html doc to be rendered in the client's browser

  • How to join 2 separate SQL Statements into 1 command

    Hi Everyone,
    I'm pretty new to PL/SQL.. thanks for your help. I'm hoping the answer to this is pretty straight forward.
    I have a report (crystal) that has 1 subreport. The results from the report are exported to excel. I'd like to take this report and include it in another report, however since I've already went 1 sub report down, looks like I need to figure out a way to get this 1 report combined into a SQL Command.
    Is there an easy way to combine the main report and subreport here into 1 SQL Command?
    Main Report SQL Select
    SELECT DISTINCT "ST_WORKORDER_REF"."st_wo_number", "ST_WORKORDER_REF"."gs_guid", "ST_STATION"."st_workorder_ref_guid", "ST_STATION"."gs_guid", "ST_ATTACHED_ASSEMBLIES"."gs_network_feature_guid", "GS_ASSEMBLY_REF"."gs_guid", "ST_ATTACHED_ASSEMBLIES"."gs_assembly_guid", "GS_ASSEMBLY_DEFAULTS"."gs_assembly_ref_guid", "ST_ATTACHED_ASSEMBLIES"."gs_assembly_quantity", "GS_ASSEMBLY_REF"."gs_assembly_description", "GS_ASSEMBLY_REF"."gs_display_feature_name", "ST_ATTACHED_ASSEMBLIES"."gs_network_feature_name", "ST_ATTACHED_ASSEMBLIES"."st_assembly_action_code", "ST_ATTACHED_ASSEMBLIES"."gs_assembly_date_created", "ST_ATTACHED_ASSEMBLIES"."gs_display_feature_name"
    FROM   ((("gs54025_master"."dbo"."ST_WORKORDER_REF" "ST_WORKORDER_REF" LEFT OUTER JOIN "gsXXXXX"."dbo"."ST_STATION" "ST_STATION" ON "ST_WORKORDER_REF"."gs_guid"="ST_STATION"."st_workorder_ref_guid") LEFT OUTER JOIN "gs54gsXXXXX"."dbo"."ST_ATTACHED_ASSEMBLIES" "ST_ATTACHED_ASSEMBLIES" ON "ST_STATION"."gs_guid"="ST_ATTACHED_ASSEMBLIES"."gs_network_feature_guid") LEFT OUTER JOIN "gsXXXXX"."dbo"."GS_ASSEMBLY_REF" "GS_ASSEMBLY_REF" ON "ST_ATTACHED_ASSEMBLIES"."gs_assembly_guid"="GS_ASSEMBLY_REF"."gs_guid") LEFT OUTER JOIN "gsXXXXX"."dbo"."GS_ASSEMBLY_DEFAULTS" "GS_ASSEMBLY_DEFAULTS" ON "GS_ASSEMBLY_REF"."gs_guid"="GS_ASSEMBLY_DEFAULTS"."gs_assembly_ref_guid"
    WHERE  "ST_WORKORDER_REF"."st_wo_number"=N'90295' AND "ST_ATTACHED_ASSEMBLIES"."st_assembly_action_code"=N'C'
    ORDER BY "ST_ATTACHED_ASSEMBLIES"."gs_assembly_guid"I want to append the results from the subreport:
    Sub Report SQL Select
    SELECT DISTINCT "ST_WORKORDER_REF"."st_wo_number", "ST_WORKORDER_REF"."gs_guid", "ST_ATTACHED_ASSEMBLIES"."gs_network_feature_guid", "GS_ASSEMBLY_REF"."gs_guid", "ST_ATTACHED_ASSEMBLIES"."gs_assembly_guid", "GS_ASSEMBLY_DEFAULTS"."gs_assembly_ref_guid", "ST_ATTACHED_ASSEMBLIES"."gs_assembly_quantity", "GS_ASSEMBLY_REF"."gs_assembly_description", "GS_ASSEMBLY_REF"."gs_display_feature_name", "ST_ATTACHED_ASSEMBLIES"."gs_network_feature_name", "ST_ATTACHED_ASSEMBLIES"."st_assembly_action_code", "ST_ATTACHED_ASSEMBLIES"."gs_assembly_date_created", "ST_ATTACHED_ASSEMBLIES"."gs_display_feature_name", "ST_SPAN"."st_workorder_ref_guid"
    FROM   ((("gsXXXXX"."dbo"."ST_WORKORDER_REF" "ST_WORKORDER_REF" INNER JOIN "gsXXXXX"."dbo"."ST_SPAN" "ST_SPAN" ON "ST_WORKORDER_REF"."gs_guid"="ST_SPAN"."st_workorder_ref_guid") INNER JOIN "gsXXXXX"."dbo"."ST_ATTACHED_ASSEMBLIES" "ST_ATTACHED_ASSEMBLIES" ON "ST_SPAN"."gs_guid"="ST_ATTACHED_ASSEMBLIES"."gs_network_feature_guid") LEFT OUTER JOIN "gs54025_master"."dbo"."GS_ASSEMBLY_REF" "GS_ASSEMBLY_REF" ON "ST_ATTACHED_ASSEMBLIES"."gs_assembly_guid"="GS_ASSEMBLY_REF"."gs_guid") LEFT OUTER JOIN "gsXXXXX"."dbo"."GS_ASSEMBLY_DEFAULTS" "GS_ASSEMBLY_DEFAULTS" ON "GS_ASSEMBLY_REF"."gs_guid"="GS_ASSEMBLY_DEFAULTS"."gs_assembly_ref_guid"
    WHERE  "ST_WORKORDER_REF"."st_wo_number"=N'90295' AND "ST_ATTACHED_ASSEMBLIES"."st_assembly_action_code"=N'C'
    ORDER BY "ST_ATTACHED_ASSEMBLIES"."gs_assembly_guid"Thanks,
    BTW, I realize the SQL in both are very similar. GS_station and GS_Span both starting points... why I needed the subreport.
    John

    Not being a Crystal Reports developer, it's not obvious to me what "subreport" means in this context.
    What would it mean to you to combine the main report and the subreport? Do you just want to add the rows that the subreport returns to the end of the results returned by the report? If so, is the structure of the two report sets identical (do they select the same number of columns with the same data types)? Or do you want to join the data from the report query to the data from the subreport query? If so, what key(s) relate the rows in one to the rows in the other? Or do you want to do something else?
    It would be exceptionally helpful if you could post the DDL to create your tables (simplified versions if possible), the DML to insert some reasonable sample data, and an explanation of the output you're trying to get from the combined query.
    Justin

  • SQL Select into Nested Table

    Hi,
    I would like to be able to store results of a query in the database. So far, I believe the best method is to store it as a nested table so that I may refer to it by criteria (e.g. date, name, etc.). I am somewhat new to Oracle and I'm not sure how to do this.
    The query will always return the same columns, so that should make it easier for me. Also, I need to be able to query the data that is stored into an APEX report region.
    Can someone tell me if this is the best method to do this? Also, is there a tutorial anywhere that explains how to do what I want?
    Thanks in advance,
    -David

    would like to be able to store results of a query in the database. So far,
    I believe the best method is to store it as a nested table so that I may refer
    to it by criteria (e.g. date, name, etc.). I am somewhat new to Oracle and
    I'm not sure how to do this.Given that you're new to Oracle how did you decide the best approach was a nested table? As most people who know anything at all about Oracle would take the opposite view (as Dan has done).
    Let's drill down into your requirements some more. How long do what to retain the results for? Do you want to retain the results of many queries? If so, will these queries be the same shape (same number and type of columns) or will they be different? Do you want one user to be able to see the results of another user's queries? Do you want to associate metadata with these result sets?
    In fact, why do you want to be able to store these result sets at all? Oracle is actually pretty good at caching data, especially in 11g. So you may be re-inventing a wheel and designing it wonky at that.
    Cheers, APC
    Blog : http://radiofreetooting.blogspot.com/

  • How to get SQL statements into SE16

    Does anyone know if there is a way in SE16 to get several records for a single Objid?  I do not know the objid but I do know the objid has two records with one having a field1 value of 0001 and the other 0002.  I want to return both records
    This is what the SQL would look like but I'm not sure how I would do in SE16?
    Select * from hrp5122
    where posting_channel = 0001
    and    posting_channel = 0002
    Thanks!

    In the selection screen of SE16, click on the icon on the most right at line POSTING_CHANNEL. You can enter multiple values, ranges and also exclude single entries there.
    Florian

  • Possible to do "grant" sql statement in Native SQL?

    We have a need to do a grant of access from one of our systems out for various applications.  In order for this to work we need to run a grant access command on the table and are trying to put a wrapper around this so we can use an abap.  Below is the code I am unit testing.  Two questions.  First, can a grant be done via native SQL in abap?  Second, if it can be done, what is the error with the logic where I am trying to put in the table name via a parameter.
    REPORT  ZLJTEST2.
    tables dd02l.
    DATA scarr_carrid TYPE dd02l-tabname.
    SELECT-OPTIONS s_carrid for dd02l-tabname no intervals.
    DATA s_carrid_wa LIKE LINE OF s_carrid.
    DATA name TYPE c LENGTH 20.
    TRY.
        EXEC SQL.
          CREATE FUNCTION selfunc( input CHAR(20) )
            RETURNING char(20);
            DEFINE output char(20);
            set schema sapr3;
            grant select on table input to group infouser;
            RETURN output;
            END FUNCTION;
        ENDEXEC.
        LOOP AT s_carrid INTO s_carrid_wa
                         WHERE sign = 'I' AND option = 'EQ'.
          TRY.
             EXEC SQL.
                EXECUTE PROCEDURE selfunc( IN  :s_carrid_wa-low,
                                           OUT :name )
              ENDEXEC.
              WRITE: / s_carrid_wa-low, name.
            CATCH cx_sy_native_sql_error.
              MESSAGE `Error in procedure execution` TYPE 'I'.
          ENDTRY.
        ENDLOOP.
        EXEC SQL.
          DROP FUNCTION selfunc;
        ENDEXEC.
      CATCH cx_sy_native_sql_error.
        MESSAGE `Error in procedure handling` TYPE 'I'.
    ENDTRY.

    Hi,
    Yes it is posible.
    I made one program like you want. But it need very long code.
    Here I explain the idea:
    1. Create Screen with input TEXT EDIT CONTROL.
        This is for input SQL Statement.
    2. Get SQL Statement from Text Edit Control using method <b>get_text_as_r3table</b>.
    3. Now we need to separate SQL Statement into different table.
        We Separate SELECT, FROM, WHERE, GROUP, HAVING, ORDER, etc.
    4. We need dynamic internal table to store the data.
    5. Select the data according SQL statement.
          SELECT (IT_SELECT)
            into corresponding fields of table  <dyn_table>
          FROM (IT_FROM)
          WHERE (IT_WHERE)
          GROUP BY (IT_GROUP)
          HAVING (IT_HAVING)
          ORDER BY (IT_ORDER).
    6. Display our data using ALV GRID
    Hopefully it will help you.
    Regards,

  • How to run a SQL statement which is stored inside an SQL Table

    Hello,
    If anyone please help me with the following problem I would be forever grateful
    I have an SQL statement which is stored inside a certain SQL table, I want to use that SQL statement inside my PL/SQL procedure.
    Was thinking of a simple solution of obtaining the SQL statement into an array and then execute it, yet how could I do so exactly with PL/SQL? I've only started playing around with PL/SQL in the last few days.
    Thanks in advance!
    This is how it looks like more or less:
    Displaying result for:
    SELECT TRIM(OBJ_VALU_TXT)
    FROM   OBJ_VALU_DOC
    WHERE  OBJECT_TYPE  = 'FLD'
      AND  OBJECT_CODE  = 15443
      AND  OBJ_VALU_CD  = 'ACR'
    ORDER BYDOC_SEQ_NO
    00001                                                            
    SELECT
    VALUE(MAX(RECEIPT_NO) + 1, :OUT-COMP-FACTOR)
    FROM RECEIPT
    WHERE (RECEIPT_NO BETWEEN
    :OUT-COMP-FACTOR AND :OUT-TO-NUMBER) OR
    (RECEIPT_NO > :OUT-COMP-FACTOR AND
    :OUT-TO-NUMBER = 0)

    Here's a demo of your requirement.
    create table t ( col1 varchar2(200));
    table created
    insert into t values('select * from dual');
    1 row inserted
    declare
    v_col varchar2(200);
    v_val varchar2(200);
    begin
    select col1 into v_col from t;
    execute immediate v_col into v_val;
    dbms_output.put_line(v_val);
    end;
    X
    Using into clause, you can use as many variables as required. But the basic approach reamins the same.
    But storing SQL in DB is not an efficient design.
    Ishan

Maybe you are looking for

  • How to stop Mail from searching for sender's image?

    When I'm going through messages in Mail, it won't display the message in the preview pane for several seconds until it completes the "Searching for sender's image" process. I have a large address book with several thousand entries. Is there a way to

  • LCD Brightness Toshiba Equium A100-147

    I can't seem to set the brightness on my toshiba laptop. $ xbacklight -set 00 $ Seems to pause for a while then returns a prompt as if it had completed but nothing changes. $ toshset -lcd 50 required kernel toshiba support not enabled. Self explanato

  • Shortcuts in Numbers 09

    Does anyone know how to make a shortcut for ex. the keystroke sequence for opening a Formula Cell ? I'm doing often and it is a lot of keystrokes in large sheets. The operation in Numbers is: Alt+Return then Shift+Left arrow then Alt + Return and rig

  • Popup refreshing parent page

    Hi everyone, I've got a popup window that allows the user to edit some values. These values are displayed on the parent page. Most of the time, when the save button on the popup is clicked, the popup closes and the parent refreshes and displays the n

  • Ical won't sync with iPhone. I can't reset sync history in Lion anymore?

    i'm pulling my hair out! my ical just won't sync with my iphone anymore. i wanted to reset sync history as suggested in some forums but lion doesn't have isync anymore. it is so frustrating as it is supposed to be easy to sync apple products! any ide