If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > ' in a sql statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-04-07, 17:01
Chriz81 Chriz81 is offline
Registered User
 
Join Date: Jun 2007
Posts: 19
' in a sql statement

Hi,

I have the following statement:
insert into User.Ausschnitt values ('O'reilly','2','3','4','5','6');

And I get the message that there is a problem with the '

But how can I solve this problem? I looked for escape signs for the DB2, but I found nothing till now.

Can you help?

Thanks in advance,
Chris
Reply With Quote
  #2 (permalink)  
Old 06-04-07, 17:20
dbamota dbamota is offline
Registered User
 
Join Date: Sep 2003
Posts: 237
Try 'O''Reily'
__________________
mota
Reply With Quote
  #3 (permalink)  
Old 06-05-07, 03:23
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
As dbamota suggested - double apostrophes are the escape character. Apostrophes in fields can cause all sorts of problems - so you must either remove them or make sure you replace all singles withing the field value with (EDIT: two single quotes in succession). It is your decision on whether to drop them completely or replace with (EDIT: two single quotes in succession) for every insert (perhaps this depends on your front end?).
Anyway, ihth
__________________
George
Twitter | Blog

Last edited by gvee; 06-05-07 at 05:56.
Reply With Quote
  #4 (permalink)  
Old 06-05-07, 05:52
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
george, don't say "replace with doubles"

say "replace with two single quotes in succession"

can you see why?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 06-05-07, 05:54
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Mais oui - my apologies.
There is a very big difference.
Rudy is quite correct
__________________
George
Twitter | Blog
Reply With Quote
  #6 (permalink)  
Old 06-05-07, 06:59
Chriz81 Chriz81 is offline
Registered User
 
Join Date: Jun 2007
Posts: 19
Thanks a lot for all your support.
I just implemented it the code. I replace a ' by ''!
But now it's shown like this in the respective field in the database.

Is there no possibility to import the string like it looks orginial, e.g. O'Reilly?
Because now I have O''Reilly in the field.

Chris
Reply With Quote
  #7 (permalink)  
Old 06-05-07, 07:00
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
What happens when you use a SELECT statement to pick out this record?
__________________
George
Twitter | Blog
Reply With Quote
  #8 (permalink)  
Old 06-05-07, 07:01
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
chris, did you see post #4 and the EDITs in post #3?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 06-05-07, 07:13
Chriz81 Chriz81 is offline
Registered User
 
Join Date: Jun 2007
Posts: 19
@georgev: I get O''Reilly

@r937: I have seen the edits and I used two single quotes in succession
Reply With Quote
  #10 (permalink)  
Old 06-05-07, 07:25
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
are you escaping your sql somehow, like the way the php programmers do?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #11 (permalink)  
Old 06-05-07, 07:28
Chriz81 Chriz81 is offline
Registered User
 
Join Date: Jun 2007
Posts: 19
NO! But I'm looking for something like that. E.g. I found an escape function for mysql but not for the DB2. Thats my problem!

My code is written in PHP!
Reply With Quote
  #12 (permalink)  
Old 06-05-07, 07:45
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
well, i don't do php, but i've helped an awful lot of php programmers who get into trouble with sql

you (or your php code) must be doing something to escape each single quote

perhaps you could start a new thread in the php forum?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On