DBAsupport.com Forums - Powered by vBulletin
Results 1 to 5 of 5

Thread: How to insert strings containing quotes into the database?

  1. #1
    Join Date
    Jan 2001
    Posts
    59

    Why the following will not work? isn't the backslach a escape character?


    SQL> insert into test3 values('good', '\'bad\'');
    insert into test3 values('good', '\'bad\'')
    *
    ERROR at line 1:
    ORA-00917: missing comma


    SQL> insert into test3 values('good',''bad'');
    insert into test3 values('good',''bad'')
    *
    ERROR at line 1:
    ORA-00917: missing comma

    SQL>





  2. #2
    Join Date
    May 2000
    Posts
    58
    If your intention is to insert 'bad' , try '''bad''' or chr(39)||'bad'||chr(39)

  3. #3
    Join Date
    Apr 2001
    Location
    Alameda, CA
    Posts
    6
    /demo/cdwprod/SQL>insert into temp values ('"Good"');

    1 row created.

    /demo/cdwprod/SQL>select * from temp;

    TMP
    --------------------
    "Good"


    Have Fun

    Naveen

  4. #4
    Join Date
    Aug 2000
    Posts
    462
    in the middle of a string, use two single quotes next to each other to include a single quote in a string. For example:

    declare X varchar2(1000);

    begin

    X := 'This is kmesser''s string'; - between the r and s are two single quotes
    insert into kmessertable values(X);
    X := ''''; -- that is four single quotes in a row, which will result in one, single quote being stored in X as a varchar2 value;
    insert into kmesstable values(X);

    end;

  5. #5
    Join Date
    Jan 2001
    Posts
    59

    Thanks! using two single quotes works.









Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width