Insert Statement is not working

Hi all
I am using MySql.
I want to insert a string into DB which also has singlequotes and double quotes.
I am able to insert single quotes but when i am inserting double quotes i'm getting sql exception.
any example code is much appreciated.
can anybody help?
Advance thamks

Bhanu,
I gotta tell you that is about the dumbest post I have read on here in some time.
It doesn't matter where the variable comes from... one you hard-coded in your source or user entered at run time.... the idea is the same.
USE PREPARED STATEMENTS.
The prepared statement AT RUN TIME will do what needs to be done with your value..
It doesn't matter where it is coming from.
I suppose you know all about design patterns eh? Yeah that's nice.
Just maybe try the code sample out.. replacing the value with the one you get from the user. You will see it works.

Similar Messages

  • Insert statement will not work if select statement has less number of colum

    Hi,
    One of my thread is already resolved on the following URL : unable to insert rows into the table
    DROP TABLE TEMP;
    CREATE TABLE TEMP AS SELECT * FROM CASE_101 WHERE 1=2;
    DECLARE
    S VARCHAR2(200);
    STMT VARCHAR2(500);
    begin
    for C in (select TABLE_NAME INTO S from USER_TABLES where TABLE_NAME like 'CASE%' TABLE_NAME NOT like '%OLD' and Num_ROWS > 0 order by TABLE_NAME) loop
    STMT := 'INSERT INTO TEMP SELECT * FROM ';
    STMT:=STMT || C.TABLE_NAME;
    EXECUTE IMMEDIATE STMT;
    dbms_output.put_line(c.table_name);
    end loop;
    end;
    i am facing now some different; almost all the tables have same number of columns except in few of tables have some additional columns. As above i am creating a table "TEMP" who has highest column temp(by doing some manual process). The table who has less columns than "TEMP" table : Insert statement will not work. 'INSERT INTO TEMP SELECT * FROM less_columns_table_name'.
    Please let me know , how can i execute proper way.
    Thanks.
    Best Regards
    Arshad

    user13360241 wrote:
    Hi,
    One of my thread is already resolved on the following URL : unable to insert rows into the table
    DROP TABLE TEMP;
    CREATE TABLE TEMP AS SELECT * FROM CASE_101 WHERE 1=2;
    DECLARE
    S VARCHAR2(200);
    STMT VARCHAR2(500);
    begin
    for C in (select TABLE_NAME INTO S from USER_TABLES where TABLE_NAME like 'CASE%' TABLE_NAME NOT like '%OLD' and Num_ROWS > 0 order by TABLE_NAME) loop
    STMT := 'INSERT INTO TEMP SELECT * FROM ';
    STMT:=STMT || C.TABLE_NAME;
    EXECUTE IMMEDIATE STMT;
    dbms_output.put_line(c.table_name);
    end loop;
    end;
    i am facing now some different; almost all the tables have same number of columns except in few of tables have some additional columns. As above i am creating a table "TEMP" who has highest column temp(by doing some manual process). The table who has less columns than "TEMP" table : Insert statement will not work. 'INSERT INTO TEMP SELECT * FROM less_columns_table_name'.
    Please let me know , how can i execute proper way.
    Thanks.
    Best Regards
    Arshadmore often than not "TEMP" tables are NOT required & are highly inefficient in Oracle.
    Either only specify explicit column in TEMP to get data,
    or provide value for "extra" column in TEMP

  • Insert statement is not working for z table.

    Hi experts,
    My insert statement is not working.
    I have used follwing code to update z table .
    INSERT ztable FROM TABLE gt_table.
    here i have checked gt_table and its filled up with all the records properly.
    now the problem is in this table i have 15 fields and it inserts 14  fields of it but
    the last field is never inserted though in gt_table i can see value for last fields also.
    I have added this field in ztable recently . so i also used se14 to adjust table but still i am facing same problem.
    please help me out.
    thanks,
    Neo

    > > Table maintainance will have nothing to do with
    > this
    > > issue.
    >
    > It does sometimes when you are trying to see the
    > values from SM30 instead of SE16. The value may be
    > there, but it may just not seen in SM30 because the
    > table maintenance hasn't registered the addition of
    > new field.
    >
    > Another place to look at is the activation log to see
    > if there are any warnings issued there.
    You shouldn't use SM30 to view table entries. You use this transaction to maintain the table entries. Pure and Simple.

  • Insert Statement Will Not Work if a user has

    I am using a MySQL database to process my Java Server Page form.
    Simply, I always try to see if I can process information, first, via the command line client, then thru JSP.
    At the command line client I type:
    I type insert into tablename (favorite_quote) VALUES
    ('Sleepin' in 'da house!');
    That insert throws an error. SImply said, because of the bunches of single quotes... Is there any advanced statement or insert statement to solve this?
    If I do this:
    INSERT INTO tablename (favorite_quote) VALUES
    ('Java');
    It adds the record perfectly normal...
    I am REALLY new to Java, so any help on this issue would be great!
    BTW: Part of my Java Server Pages has:
    String favorite_quote =request.getParameter("favorite_quote");
    "INSERT INTO tablename (favorite_quote) VALUES " +
    "('"+userid+"')";
    Obviously that works fine unless anybody adds a ' or " isn't or what's, etc.
    I'm loving Java, I just REALLY need some help on solving this issue.
    Thank you so much! Any help would BE **WONDERFUL**!

    String favorite_quote
    te =request.getParameter("favorite_quote");
    PreparedStatement ps =
    = connection.prepareStatement(""INSERT INTO tablename
    (favorite_quote) VALUES (?)");
    ps.setString(1, "Sleepin' in 'da house!");
    ps.execute();oops a small error
    PreparedStatement ps = connection.prepareStatement("INSERT INTO tablename (favorite_quote) VALUES (?)");

  • Insert statement is not working properly

    I've problem in inserting values in database.I'm able to retrieve data from a table, but I'm not able to store any values in a table.I've got no runtime error.In code, executeUpdate() statement is also returning 1(which shows successful execution).
    PROGRAM CODE:
    import java.io.*;
    import java.sql.*;
    public class test1
         public static void main(String args[])
              try
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   Connection con=DriverManager.getConnection("jdbc:odbc:office");
                   Statement st=con.createStatement();
                   String query="insert into nam values('[email protected]')";          
                   int i=st.executeUpdate(query);
    System.out.println(i);
              catch(Exception e)
                   System.out.println(e);
    Eagerly Expecting a solution
    Thanks & Regards
    Venki

    Will not help, if he didn't change AutoCommit to false.
    An idea: Do you use Access?
    Then it might be this one again:
    http://forum.java.sun.com/thread.jsp?forum=48&thread=147704

  • Insert Statement is not working in Oracle Form

    Hi all,
    I have developed a custome form from the scarch.
    I have one button on that for called "PROCESS"
    when I cick on the PROCESS button it should insert record in to one custome table.
    I have created custom table in custom schema and given grant to Apps user. as well as I created synonym in Apps for that table.
    The code for WHEN-BUTTON-PRESSED
    DECLARE
    *     l_user_id NUMBER:=FND_GLOBAL.USER_ID;*
    *     l_date DATE :=SYSDATE;*
    BEGIN
    *     FOR i IN REFUND_DETAILS.transaction_tbl.FIRST..REFUND_DETAILS.transaction_tbl.LAST*
    *     LOOP*
    *          fnd_message.DEBUG('l_user_id'||l_user_id);*
    *          fnd_message.DEBUG(REFUND_DETAILS.transaction_tbl(i).OU_NAME);*
    *          fnd_message.DEBUG(REFUND_DETAILS.transaction_tbl(i).cust_account_id);*
    *          fnd_message.DEBUG(REFUND_DETAILS.transaction_tbl(i).receipt_number);*
    *          fnd_message.DEBUG(REFUND_DETAILS.transaction_tbl(i).refund_amount);*
    INSERT INTO xxkci_ar_refund_details
    VALUES(REFUND_DETAILS.transaction_tbl(i).OU_NAME,
    REFUND_DETAILS.transaction_tbl(i).cust_account_id,
    REFUND_DETAILS.transaction_tbl(i).receipt_number,
    REFUND_DETAILS.transaction_tbl(i).refund_amount,
    *'1223',--:CUSTOMER.pn_ref,*
    *'SUCCESS',--:CUSTOMER.status,*
    *'DONE',--:CUSTOMER.MESSAGE,*
    l_user_id,
    l_date,
    l_user_id,
    l_date);
    *     END LOOP;*
    *     COMMIT;*
    END;
    when I am running the form from front end and cliking the process button it is throughing the bellow error.
    ora-01031 insufficient privileges.
    As I have given all the grant for Apps user.
    When I am running the same insert satement in toad for the Apps it is working fine no error.
    Its Urjent please required a help on this.
    Thanks
    Nihar

    Have you tried to give the grant to APPLSYS user as well and see if this helps?
    If you still get the same error, please obtain the FRD file for details about the error -- http://forums.oracle.com/forums/search.jspa?threadID=&q=FRD&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    Thanks,
    Hussein

  • Insert statement is not executing.....

    From below procedure the insert statement is not executing....
    update statement is working perfectly but insert......
    create or replace PROCEDURE PAYMENT(AMT NUMBER,UID NUMBER) IS
    AMT1 NUMBER;
    AMT NUMBER;
    PD VARCHAR2(100);
    C1 NUMBER;
    PER NUMBER;
    ACC1 VARCHAR2(15);
    CF NUMBER;
    CRF NUMBER;
    ACC2 VARCHAR2(15);
    begin
    SELECT  PAY_DESC INTO PD FROM SUB.PAYMENT_TY WHERE ORD=0;
    SELECT NVL(AMOUNT,0) INTO C1 FROM FOOD.MEMBER WHERE LTRIM(RTRIM(UPPER(NAME))) LIKE
    LTRIM(RTRIM(UPPER(PD)))
    AND USER_ID=UID;
    IF NVL(C1,0)>AMT THEN /*CASH*/
    C1:=C1-AMT;
    SELECT ACCOUNT_CODE INTO ACC1 FROM SUB.MASTER WHERE PAY_CODE=2;
    INSERT INTO ACC(AMOUNT_TD,ACC_CODE,EN_DATE,FO_TYPE,PART) VALUES(AMT,ACC1,SYSDATE,'JV','CASH
    PERCENTAGE FOR '||45457);
    STANDARD.COMMIT;STANDARD.COMMIT;STANDARD.COMMIT;
    UPDATE FOOD.MEMBER_DET SET AMOUNT=C1 WHERE USER_ID=UIDAND C_COD=2;
    STANDARD.COMMIT;STANDARD.COMMIT;STANDARD.COMMIT;
    END IF;
    end;the values receiving in insert statement is correct values.
    how to resolve this?
    Thanks skud...

    Check for too many rows or no data found exception.
    And also check the number of rows either inserted or updated.
    Something like this:
    create or replace PROCEDURE PAYMENT(AMT NUMBER,UID NUMBER) IS
      AMT1  NUMBER;
      AMT   NUMBER;
      PD    VARCHAR2(100);
      C1    NUMBER;
      PER   NUMBER;
      ACC1  VARCHAR2(15);
      CF    NUMBER;
      CRF   NUMBER;
      ACC2  VARCHAR2(15);
    begin
      begin
        SELECT  PAY_DESC
        INTO PD
        FROM SUB.PAYMENT_TY
        WHERE ORD=0;
        exception
          when too_many_rows then
            dbms_output.put_line('Too many rows in first SELECT');
          when no_data_found then
            dbms_output.put_line('No data found in first select');
      end;
      begin
        SELECT NVL(AMOUNT,0)
        INTO C1
        FROM FOOD.MEMBER
        WHERE LTRIM(RTRIM(UPPER(NAME))) LIKE LTRIM(RTRIM(UPPER(PD)))
        AND USER_ID=UID;
        exception
          when too_many_rows then
            dbms_output.put_line('Too many rows in second SELECT');
          when no_data_found then
            dbms_output.put_line('No data found in second select');
      end;
      IF NVL(C1,0)>AMT THEN /*CASH*/
        C1:=C1-AMT;
        begin
          SELECT ACCOUNT_CODE
          INTO ACC1
          FROM SUB.MASTER
          WHERE PAY_CODE=2;
          exception
            when too_many_rows then
              dbms_output.put_line('Too many rows in third SELECT');
            when no_data_found then
              dbms_output.put_line('No data found in third select');
        end;
        INSERT INTO ACC(AMOUNT_TD,ACC_CODE,EN_DATE,FO_TYPE,PART) VALUES(AMT,ACC1,SYSDATE,'JV','CASH PERCENTAGE FOR '||45457);
        dbms_output.put_line('Insert ' || sql%rowcount);
        COMMIT;
        UPDATE FOOD.MEMBER_DET SET AMOUNT=C1 WHERE USER_ID=UIDAND C_COD=2;
        dbms_output.put_line('Update ' || sql%rowcount);
        commit;
      END IF;
    end;
    /UNTESTED!!

  • Insert statement does not insert all records from a partitioned table

    Hi
    I need to insert records in to a table from a partitioned table.I set up a job and to my surprise i found that the insert statement is not inserting all the records on the partitioned table.
    for example when i am using select statement on to a partitioned table
    it gives me 400 records but when i insert it gives me only 100 records.
    can anyone help in this matter.

    INSERT INTO TABLENAME(COLUMNS)
    (SELECT *
    FROM SCHEMA1.TABLENAME1
    JOIN SCHEMA2.TABLENAME2a
    ON CONDITION
    JOIN SCHEMA2.TABLENAME2 b
    ON CONDITION AND CONDITION
    WHERE CONDITION
    AND CONDITION
    AND CONDITION
    AND CONDITION
    AND (CONDITION
    HAVING SUM(COLUMN) > 0
    GROUP BY COLUMNS

  • CASE Statement is not working Derived table

    Hi All,
    in the bello SQL Statement case statement is not working in derived table. I am new to creation of derived table if any body knows plz kinldy help me out on this.
    SELECT x.market, x.droprate as med1
    FROM
    (select upper(market_name) as market, fulldate as date_value,
         (sum([Dy_LOT_DROPS_N][Dy_OB_HO_DROPS][Dy_NonRF_Drop]))/
              nullif(sum(CASE WHEN (month(BBHDLY.FullDate)}>= 6 and { year(BBHDLY.FullDate)} = 2011) or {fn year(IDENSLABBHDLY.FullDate)} > 2011
    THEN  BBHDLY.Dy_Calls - BBHDLY.Dy_HO_CHAN_ALLOC ELSE BBHDLY.Dy_Calls END),0)*100 as droprate
    from BBHDLY sla
    inner join Dim mkt
         on sla.bts_name = mkt.bts_name and sla.SectorID = mkt.Sector_Id
                   where fulldate >= GETDATE()-46
                   group by market_name, fulldate) x,
    (select market_name as market, fulldate as date_value,
    (sum([Dy_LOT_DROPS_N][Dy_OB_HO_DROPS][Dy_NonRF_Drop]))/
              nullif(sum(CASE WHEN ({fn month(BBHDLY.FullDate)}>= 6 and {fn year(BBHDLY.FullDate)} = 2011) or {fn year(BBHDLY.FullDate)} >
    2011 THEN  BBHDLY.Dy_Calls - BBHDLY.Dy_HO_CHAN_ALLOC ELSE BBHDLY.Dy_Calls END),0)*100 as droprate
    from BBHDLY sla
    inner join Dim mkt
         on sla.bts_name = mkt.bts_name and sla.SectorID = mkt.Sector_Id
                   where fulldate >=GETDATE()-46
                   group by market_name, fulldate) y
    where x.market = y.market
    GROUP BY x.droprate, x.market
    HAVING
       SUM(CASE WHEN y.droprate <= x.droprate
          THEN 1 ELSE 0 END)>=(COUNT(*)+1)/2 AND
       SUM(CASE WHEN y.droprate >= x.droprate
          THEN 1 ELSE 0 END)>=(COUNT(*)/2)+1
    Thanks

    It looks like SQL Server or Sybase given that you're using getdate().
    As such, Vinesh's comment to use decode is wrong - decode is  Oracle syntax.
    Looking at your statement again, I've noticed the following:
    you have no { to match the first } - not sure why you're using them anyway.
    you haven't given x.market a name - use x.market as market instead
    use coalesce instead of nullif if you're on SQL Server.

  • Delete Statement is not working correctly

    Hello,
    The following delete statement is not working correctly.
    If I press delete it will delete everything in the category table
    I don't know whats wrong with it.
    ----delete row from category if there is not infrastructure to support------
    IF :P12_DFCY_SEQNO4 IS NOT NULL AND :P12_DFCY_CATG_C = '7' THEN
    DELETE FROM DFCY_CATG
    WHERE NOT EXISTS(SELECT I.DFCY_SEQNO
    FROM DFCY_CATG C, DFCY_CATG_INFRSTRCTR I
    WHERE C.DFCY_SEQNO = I.DFCY_SEQNO
    AND :P12_DFCY_SEQNO4 = I.DFCY_SEQNO);
    end if;
    Thanks
    Mary

    Hi,
    IF :P12_DFCY_SEQNO4 IS NOT NULL AND :P12_DFCY_CATG_C = '7' THEN
    DELETE FROM DFCY_CATG
    WHERE NOT EXISTS(SELECT I.DFCY_SEQNO
    FROM DFCY_CATG C, DFCY_CATG_INFRSTRCTR I
    WHERE C.DFCY_SEQNO = I.DFCY_SEQNO
    AND :P12_DFCY_SEQNO4 = I.DFCY_SEQNO);
    end if;So, if P12_DFCY_SEQNO4 does not exist, then I would expect all records to be deleted because the NOT EXISTS() function would just return TRUE for every record on the table. Somewhere in the statement, I would expect to see something that links between the table being deleted from and the NOT EXISTS() data or, perhaps, using the P12_DFCY_CATG_C value as a filter?
    Andy

  • Delete statement is not working.

    Hi,
    find the code. Here the delete statement is not working and i am getting sy-subrc = 4. although ,
    xe1edp10-idnkd = 34596 and dint_edidd -sdata = 34596.
    please help me ...
    loop at dekek_x.
    loop at dint_edidd where segnam = 'E1EDP10'.
    if dekek_x-stpin = 1 .
    CLEAR xe1edp10.
      MOVE dint_edidd-sdata TO xe1edp10.
    delete dint_edidd where sdata = xe1edp10-idnkd.
    endif.
    endloop.

    1st thing..
    i tried this :
    tables: edidd, e1edp10.
    edidd-sdata = '315934 EA 017'.
    WRITE edidd-sdata.
    move edidd-sdata to e1edp10.
    IF edidd-sdata = e1edp10-idnkd.
    WRITE: e1edp10-idnkd.
    else.
      WRITE: 'nothing'.
    ENDIF.
    output
    >315934 EA 017
    >315934 EA 017
    2nd thing,.
    your loop inside loop doesnt make any sense as they are not related any where.
    3rd thing:
    the fields are not type compatible.. this might be the reason for wrong delete statement..
    and 1 more clarification:
    TABLES: edidd, e1edp10.
    DATA :it TYPE TABLE OF edidd WITH HEADER LINE.
    edidd-sdata = '315934 EA 017'.
    WRITE edidd-sdata.
    APPEND edidd TO it.
    edidd-sdata = '315934 EA 018'.
    APPEND edidd TO it.
    LOOP AT it." where segnam = 'E1EDP10'.
      CLEAR e1edp10.
      MOVE it-sdata TO e1edp10.
      DELETE it WHERE sdata = e1edp10-idnkd.
    ENDLOOP.
    in this also delete is working perfectly fine... you run and check..

  • SORT statement is not working!

    Hi frdz,
    Below SORT statement is not working. Can any one explain me why this is happening.
    SORT i_bseg ASCENDING BY belnr bukrs
                        DESCENDING kunnr.
    I have table content as below.
    BELNR      BUKRS KUNNR   
    0016000000|CROP |         
    0016000000|CROP |0008910168
    Before and after the sort content order is same.
    I want to sort the content like below.
    0016000000|CROP |0008910168
    0016000000|CROP |       
    Is there any thing wrong with the sort statement???
    i_bseg is defined as TYPE STANDARD TABLE OF
    Sort criteria must not change i. e ascending by belnr and bukrs and descending by kunnr.
    Thanks,
    Vinod.

    hi vinod,
    this is because on your statement, you are sorting BUKRS in descending order and KUNNR in ASCENDING order.
    please take note that the sort order should come after the sorted field. if no order is given, the default which is ASCENDING will be used.
    do your sorting like this
    SORT i_bseg BY belnr bukrs kunnr DESCENDING.
    regards,
    Peter

  • Message statement is not working?

    I would like to place a message in the following method:
    It's defined like this:
    Position & cannot be delimited because the position is occupied until &
    This is in the program:
    MESSAGE: s029(zpom_001) WITH st_hrp1001-objid(8) st_hrp1001-endda(8), display like 'E'.
    I inserted the (display like 'E' ) in so I can get the RED 'X' error message.  If I take out the display like 'E', it works.
    I get the following error:
    Three-digit error number XXX required in the "MESSAGE EXXX..." statement.
    Thanks for any help you can give?
    Jeff

    Satish,
    That did not work...
    If I remove the part of the message (  Display like 'E' )  it works......  But if I want to get a RED X error message, what would I do?
    JeffG

  • SELECT statement does not work if characters ## are contained in field

    Hi Experts,
    I have the following statement:
    select single field1
        from table1
        into var1
        where field2 = text.
    This is a very simple statement that is working for me almost always correct. However there is a situation where the system is not able to find the record in my table. If text is equal to JAN##2011 the system won't deliver a result even if I have an entry in table1 with exactly this value.
    TABLE1
    field1 field2
    rome JAN##2011
    paris JAN2011
    only if text is JAN2011 the select will find a result.
    all fields are defined as CHAR.
    Thanks in advanced

    Hi Alberto,
    probably ## is not ## :-).
    is the visible representation used by ABAP to show any non-displayable characters as control characters like TAB, CR, LF, FF and the like.
    In debugger you can switch to HEX display of values, if you see something like 0A0D you can find this using CL_ABAP_CHAR_UTILITIES constant attributes.
    Regards
    Clemens

  • PrevFrame() buttons in a swf file inserted in html not working in Firefox

    Hi!
    I have a very weird problem.
    I have created a photo gallery using AS3 in Flash CS5. I have used prevFrame() and nextFrame() actions for "previous photo" and "next photo" buttons as well as for "previous thumbnails" and "next thumbnails" buttons.
    All the buttons work fine when i run the swf files as well as when i run the swf files in Firefox 8.0 and IE9. However, once I insert this swf file into my html file using Dreamweaver CS5->Insert->Media->swf, the "previous" buttons dont work in Firefox 8.0! the previous image button works sometimes whereas the previous thumbnails button does not work at all!  They work fine in IE9. The next buttons also work fine in every browser. Heres my code:
    stop();
    thumbprev_btn.visible=false;
    next_btn.addEventListener(MouseEvent.CLICK, nextimage);
    prev_btn.addEventListener(MouseEvent.CLICK, previmage);
    thumbprev_btn.addEventListener(MouseEvent.CLICK, prevthumbs);
    thumbnext_btn.addEventListener(MouseEvent.CLICK, nextthumbs);
    function nextimage(event:MouseEvent):void
    if(mc_content.currentFrame==mc_content.totalFrames)
    mc_content.gotoAndStop(1);
    else
    mc_content.nextFrame();
    function previmage(event:MouseEvent):void
    if(mc_content.currentFrame==1)
    mc_content.gotoAndStop(mc_content.totalFrames);
    else
    mc_content.prevFrame();
    function nextthumbs(event:MouseEvent):void
    thumbprev_btn.visible=true;
    nextFrame();
    if(currentFrame==3)
    thumbnext_btn.visible=false;
    function prevthumbs(event:MouseEvent):void
    thumbnext_btn.visible=true;
    prevFrame();
    if(currentFrame==1)
    thumbprev_btn.visible=false;
    Please help.

    Thankyou Ned. The html file published by flash worked perfectly however the problem persisted even if i used this html file's code. But strangely, the problem disappeared after a few days! Now the original dreamweaver code is also working fine.

Maybe you are looking for