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

Similar Messages

  • 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();

  • 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

  • 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

  • How to put the SQL-statement returned value into the field (as a default)

    Hi,
    I am using Developer/2000 (Forms Designer) under windows 98.
    Please tell me how to put the SQL-statement value (as a default value) into the field before enter-query mode. Noted that I have tried the following ways but still some problems:-
    1) Place the SQL-statement into PRE_QUERY trigger in the form/block level.
    There is a message box which ask 'Do you want to save the changes?'.
    2) Place the SQL-statement before execute enter_query. There is still a
    message box which ask 'Do you want to save the changes?'.
    Any hints? Thanks. Urgent.

    solved it!
    1) Suppress DEFAULT save message
    if form_failure then
    raise form_trigger_failure;
    end if;
    2) Place the default value before enter-query.
    Ref: Title='Default value in query field in ENTER_QUERY mode' in designer forum by CVZ
    form level trigger
    ============
    WHEN-NEW-ITEM-INSTANCE
    =======================
    if :system.mode = 'ENTER-QUERY' then
    :block.item := 'default waarde';
    end if;
    3) Suppress the changes whenever leaving the default field.
    if :block.item is null then
    -- assign statement
    end if;

  • 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

  • Prepared SQL statement to test existence of a value in a row

    Excuse my ignorance in SQL. I didn't do much in SQL queries or DB design in general, but I'm eager to learn.
    Idea behind: I'm traversing a directory tree (Java, jdbc) (depth first) and want to collect all files
    in that tree and put the as BLOBS into the database.
    To find out whether a file is the same as another file (possibly in a different path) I calculate the md5sum
    (not sure whether it is proof against collisions or if I should use SHA-256 or some combination of md5sum + chksum).
    Anyway, let the md5sum be the unique value that makes the identity of a file for now.
    My problem: Find the jdbc/SQL statements that let me decide whether the file (md5sum) is already stored in a ROW
    upon which I can decide to either do the INSERT or mark the existing file as being present in a different path.
    I stumbled across the problem in the moment when I first time tried to INSERT a row and got told that
    md5sum gotta be unique.
    Any ideas for design and query? The code example below is incomplete. Especially what I'm looking for is
    how to construct a prepared SQL statement into which I can inject the variable later found (md5sum)
    Whether I should do that by COUNT(*) or a different method?
    Christoph
    Here is my sketchy code (Netbeans project) under construction:
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package testsqlite;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;
    import java.sql.*;
    import java.util.Iterator;
    import java.util.List;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    * @author chris
    public class Main {
    * @param args the command line arguments
    private static Connection conn;
    private static String sql="INSERT INTO part(name,md5sum) VALUES (?,?)";
    private static PreparedStatement pstmnt,pstmnt_ifexists ;
    private static String sql_ifexists="SELECT COUNT(*) FROM part WHERE md5sum=?"; // ???
    public static void main(String[] args) throws Exception{
    // TODO code application logic here
    System.out.println("Testsuite-Collector\n");
    String path="c:/usr/local/www/data/testsuite/mandanten/chris/probanden";
    File f = new File(path);
    Class.forName ("org.sqlite.JDBC");
    conn =
    DriverManager.getConnection("jdbc:sqlite:c:/users/chris/testsuite/versionen");
    Statement stat = conn.createStatement();
    pstmnt = conn.prepareStatement(sql);
    pstmnt_ifexists = conn.prepareStatement(sql_ifexists);
    // process
    Traverse(f);
    // watch result
    ResultSet rs = stat.executeQuery("select * from part;");
    while (rs.next()) {
    System.out.print("name=" + rs.getString("name") + " ");
    System.out.println("md5sum= " + rs.getString("md5sum"));
    rs.close();
    conn.close();
    private static void Traverse(File f) throws IOException {
    File[] files = f.listFiles();
    for( File file : files) {
    if(file.isDirectory()){
    Traverse(file);
    else {
    try {
    if(file.length() > 0){
    FileInputStream fis = new FileInputStream( file );
    String md5 = org.apache.commons.codec.digest.DigestUtils.md5Hex( fis );
    System.out.println(file.length() +" " md5"->"+file.getPath());
    // check whether md5sum is already existing
    pstmnt_ifexists=?????
    pstmnt.setString(1, file.getPath());
    pstmnt.setString(2, md5);
    pstmnt.executeUpdate();
    catch (SQLException e) {
    System.out.println("SQL error:" e.getMessage()"\n");
    }

    And you seriously think that attempting to insert a record and catching the error of it failing is a good design!?!?I certainly do. I agree with Peter here. You can either test for the existence of the record and insert it if absent, or insert the record willy-nilly and catch the exception. The second option is (a) atomic even without transactions and (b) clearly twice as efficient. Same consideration applies to e.g.
    if (!map.containsKey(key))
      map.put(key, value);
    else
      ; // it was already thereas opposed to
    if (!map.put(key, value)
      ; // it was already thereand many other situations of this kind, e.g.
    try
      if (InetAddress.isReachable(ip))
        s = new Socket(ip, port);
      else
        ; // host not up
    catch (ConnectException exc)
      // the host wasn't up during connect
    }as opposed to
    try
      s = new Socket(ip, port);
    catch (ConnectException exc)
      // host not up
    }or
    try
      if (file.exists())
        in = new FileInputStream(file);
      else
        ; // it wasn't there
    catch (IOException exc)
      // it wasn't there, etc ...
    }as opposed to
    try
      in = new FileInputStream(file);
    catch (FileNotFoundException exc)
      // it wasn't there
    }Slight absence of timing window problems in the cases that detect via exceptions, and considerably simpler code. Phobias about how to use exception handling need to be overcome.
    I've also had it seriously argued to me that you shouldn't catch EOFExceptions, merely change the format of your file so you 'know' when one is coming up. Sorry to say that I think this sort of thing is complete rubbish. There is a need for an out of band EOF signal with all the readXXX() methods, and this is it.

  • Spooling Extracts from Multiple SQL statements in 1 File

    Hi all,
    I am trying to spool extract results of 3 separate SQL statements into one single file. I wrote a SQL block similar to the one below. However, the result of the statements overwrite each other: 3 overwrote 2 and overwrote 1. Any suggestion how to combined there extracted results in one file?
    spool c:\test.txt
    <SQL statement 1>
    <SQL statement 2>
    <SQL statement 3>
    /spool OFF
    Thanks in advance
    Jason

    Please paste you SQL file here. These is no way one should overwrite another.
    Eric

  • Pininig frquently used sql statements in SGA

    Hi
    Can you pls let me know the procedure to pin Oracle sql or pl/sql statements into SGA
    Thanks in anticipation.
    Hariharan.T

    William Robertson wrote:
    Perhaps it is used frequently but other code is used even more frequently.Yep, and of course pinning the less frequently used code will cause the more frequently used code to be aged out which will require pinning that code which in turn will age out code that is run even more frequently to be aged out which will require pinning that until everything but the most frequently used code will be pinned and the most frequently used code will be aged out.

  • How to assign a sql statement to a variable

    hey
    i am assigning a sql statement into a variable. But in sql statement where condition i am passing a variable, i am getting syntax error while processing this statement . Could please help me
    my code is like this
    sSql:='select id from SOURCES where name=' || vc_arr(i);
    Open C for sSql;
    ....

    If you use bind variables, you don't need the single quotes, and may avoid significant performance and security problems otherwise associated with dynamic SQL.
    sSql := 'select id from SOURCES where name = :some_value';
    OPEN C FOR sSql USING vc_arr(i);

  • OpenSQLException - The SQL statement "INSERT INTO "KMC_SUB_RCPT"...

    Hallo,
    We have the problem that subscriptions cannot be sent. In defaultTrace I have found following entry:
    #1.5 #32B150008004002400001641000710B80004539FE52B4274#1217846116565#com.sapportals.wcm.repository.service.subscription.wcm.SubscriptionsOpenSQL#sap.com/irj#com.sapportals.wcm.repository.service.subscription.wcm.SubscriptionsOpenSQL#LI01736#118449##iscp63.isc.aok.de_LFP_399377450#LI01736#03186780621111ddb4c432b150008004#SAPEngine_Application_Thread[impl:3]_10##0#0#Fatal##Plain###Cannot unsubscribe user. Context: ResourceContext: user=LI01736, creationTime=1217846116420, locale=de. User: LI01736. ID: 50cdd784-51ac-2810-2393-ea9709f50de3. Recipient: com.sapportals.wcm.util.channels.wcm.Recipient@ce9b7f70. Step: Executing SQL INSERT. . Trying to rollback transaction.#
    #1.5 #32B150008004002400001643000710B80004539FE52B989A#1217846116586#com.sap.sql.jdbc.common.StatementAnalyzerImpl#sap.com/irj#com.sap.sql.jdbc.common.StatementAnalyzerImpl#LI01736#118449##iscp63.isc.aok.de_LFP_399377450#LI01736#03186780621111ddb4c432b150008004#SAPEngine_Application_Thread[impl:3]_10##0#0#Error#1#/System/Database/sql/jdbc/common#Java#com.sap.sql_0019##Exception of type com.sap.sql.log.OpenSQLException caught: The SQL statement "INSERT INTO "KMC_SUB_RCPT" ("ID","RECIPIENT","RCPTTYPE","UNSUBSCRIBED") VALUES ('50cdd784-51ac-2810-2393-ea9709f50de3','LI01736','0','X')" contains the semantics error[s]: - 1:27 - the column >>ID<< is undefined in the current scope
    [EXCEPTION]
    #3#com.sap.sql.log.OpenSQLException#The SQL statement "INSERT INTO "KMC_SUB_RCPT" ("ID","RECIPIENT","RCPTTYPE","UNSUBSCRIBED") VALUES ('50cdd784-51ac-2810-2393-ea9709f50de3','LI01736','0','X')" contains the semantics error[s]: - 1:27 - the column >>ID<< is undefined in the current scope
    #com.sap.sql.log.OpenSQLException: The SQL statement "INSERT INTO "KMC_SUB_RCPT" ("ID","RECIPIENT","RCPTTYPE","UNSUBSCRIBED") VALUES ('50cdd784-51ac-2810-2393-ea9709f50de3','LI01736','0','X')" contains the semantics error[s]: - 1:27 - the column >>ID<< is undefined in the current scope
         at com.sap.sql.jdbc.common.StatementAnalyzerImpl.check(StatementAnalyzerImpl.java:38)
         at com.sap.sql.jdbc.common.StatementAnalyzerImpl.preprepareStatement(StatementAnalyzerImpl.java:101)
         at com.sap.sql.jdbc.common.StatementAnalyzerImpl.preprepareStatement(StatementAnalyzerImpl.java:87)
         at com.sap.sql.jdbc.common.CommonStatementImpl.executeUpdate(CommonStatementImpl.java:159)
         at com.sap.engine.services.dbpool.wrappers.StatementWrapper.executeUpdate(StatementWrapper.java:162)
         at com.sapportals.wcm.repository.service.subscription.wcm.SubscriptionsOpenSQL$SqlCommand.executeUpdate(SubscriptionsOpenSQL.java:3834)
         at com.sapportals.wcm.repository.service.subscription.wcm.SubscriptionsOpenSQL.unsubscribe(SubscriptionsOpenSQL.java:2127)
         at com.sapportals.wcm.repository.service.subscription.wcm.SubscriptionManager.unsubscribe(SubscriptionManager.java:3226)
         at com.sapportals.wcm.repository.service.subscription.wcm.SubscriptionManager.unsubscribe(SubscriptionManager.java:3205)
         at com.sapportals.wcm.repository.service.subscription.wcm.ActionInboxItemProducer.executeItemAction(ActionInboxItemProducer.java:222)
         at com.sapportals.wcm.service.actioninbox.wcm.ActionInboxService.executeItemAction(ActionInboxService.java:610)
         at com.sapportals.wcm.service.actioninbox.wcm.ActionInboxService.executeItemActions(ActionInboxService.java:1221)
         at com.sapportals.wcm.control.actioninbox.ActionInboxDetailsControl.onClick(ActionInboxDetailsControl.java:396)
    Any Idea?
    Regards,
    Gerhard

    Statement statement = connection.createStatement();
    //createing a statement object
    String query= "INSERT INTO table......"
    output.append("\nSending query:" + connection.nativeSQL(query));
    int result = statement.executeUpdate(query);//updates database wit record
    if (result==1)
    output.append("\ninsertation successfull");
    JOptionPane.showMessageDialog(null,"Insertation successfull ",
    JOptionPane.INFORMATION_MESSAGE);
    else
    output.append("\ninsertation unsuccessfull");
    JOptionPane.showMessageDialog(null,"Insertation unsuccessfull",
    JOptionPane.WARNING_MESSAGE);
    statement.close();
    have left out the trys and catches and some other bits and pieces that i dont think ud need its the bare bones but it might help or at least give u an idea. have used this code before to do something similar.

  • How to store data into database by reading sql statements from text file

    how to write java program for storing data into database by reading sql statements from text file

    Step 1: Create a property file to add various queries.
    Step 2: Read the properties file using ResourceBundle
    Step 3: Use the jdbc to execute the query read from the property file.
    So in future if you need to change query no need do any modifications in java program. But depends on how you use the property file.

  • Passing parameter into SQL statement in Crystal Reports

    Hi all,
    I would like to call Crystal Reports in JSP. I can handle it well now. But I hope to let user input their selection criteria before printing out the report. I know how to get the parameter value in JSP, but I really dunno how to pass these parameter values into the SQL statement in Crystal Report. Actually, is it possible to do so?
    If anyone has idea, please tell me. Thx Thx!
    Regards,
    Betty

    Dear Sir,
    I want to use Crystal Report as a web base using JSP. But, I am getting how to call .rpt file in .jsp file & passing of parameter.
    If you have any idea, please reply as early as possible
    Thanking U.
    My userid = [email protected]
    Regds
    Pankaj..

  • Convert the insert statement of an MS SQL server into an oracle statement

    Hi ,
    The insert statement in the ms sql server is
    INSERT INTO #temp EXEC Procedurename @Id OUTPUT
    where table temp
    CREATE TABLE #temp(
              Id varchar(10),
              FNa varchar(40),
              LNa varchar(40),
              SId varchar(20),
              Aid varchar(20),
              Did varchar(20),
              CCNa varchar(255),
              CCId int,
              ISu char(1),
              IA char(1),
              Dir char(1),
              Ema varchar(60),
              St char(2),
              DId char(3)
    I converted the insert statement like this
    Procedurename(Id);
    LOOP
    FETCH cv_1 INTO v_temp;
    EXIT WHEN cv_1%NOTFOUND;
    INSERT INTO TEMP VALUES v_temp;
    END LOOP;
    CLOSE cv_1;
    But i am receiving PL/SQL: ORA-00947: not enough values
    Can anyone help on this?
    Thanks

    1) Are you sure that you even need a temp table? Fetching all the rows from a cursor 1-by-1 and then inserting them into a temp table (I'm assuming the Oracle table TEMP is declared as a global temporary table) would seem rather unusual and most likely pointless. In Oracle, readers don't block writers, so there is generally no need to use temp tables to hold intermediate results.
    2) If you do need to store a set of results into a table, it's going to be more efficient to do this in a single SQL statement rather than using a cursor. Something like
    INSERT INTO my_table ( <<list of columns>> )
      SELECT <<list of columns>>
        FROM <<other tables>>
       WHERE <<some conditions>>The SELECT part of the statement here is likely whatever SQL you use in declaring the cursor.
    Justin

Maybe you are looking for

  • Oracle R12 Solutions Architect (Oracle E-business Suite, SOA, OBIEE)

    Hi All can any one help to find documents concept & implementation of integeration between Oracle E-business Suite R12, SOA and OBIEE ?? Thanks a lot Mohamed

  • Find a virus in email

    I imported old outlook email into Thunderbird. My inbox started receiving lots of rejected email notices, some that say rejected due to virus. I'm thinking an old email may have a virus in it, but I don't know how to track down which one. I can't sca

  • How to Forecast and run MRP for consumed materials

    Hi Experts,   I need help urgently on below business requirement. Objective: Forecast consumable materials (like Gas , Chemical) to produce Finish product Scenario: 1.  We have Plant WF01  - to produce finish products, Sales related activities, SOP f

  • Help with osCommerce  + Dreamweaver

    I know what you are thinking, why use DW with osCommerce. Well the problem i'm having is I need to click on a category e.g. Leaflets and then have a grid/table come up with all the quantities coming down on the left hand column and the Sizes (A4, A5,

  • JApplet  clippboard !=  Windows  clipboard ?

    Hi, I'm just a beginner in Java. I like use a Windows clipboard in a Java JApplet. i.e. I need copy and paste some text from windows into the Java Applet (JTextField for example) (I usually use 'CTRL+C" and 'CTRL+V') But it's not possible to copy any