473,889 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What's the escape char in DB2 SQL

hi all,

I want to output something this way:
Select 'This is 'A' book' from ...
how to do this?
Mar 29 '07 #1
3 30676
Tiger Champ wrote:
hi all,

I want to output something this way:
Select 'This is 'A' book' from ...
how to do this?
Double the single-quote:

SELECT 'This is ''A'' book' FROM ...

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Mar 29 '07 #2
Thanks Knut, but I hope I can print right same as I want:
This is 'a' book
Can I do this? Actually I want to use this Select to generate another query,
and there's some constant string in it, so I need to do this.

"Knut Stolze" <st****@de.ibm. com>
??????:57****** *******@mid.ind ividual.net...
Tiger Champ wrote:
>hi all,

I want to output something this way:
Select 'This is 'A' book' from ...
how to do this?

Double the single-quote:

SELECT 'This is ''A'' book' FROM ...

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany

Mar 29 '07 #3
Tiger Champ wrote:
Thanks Knut, but I hope I can print right same as I want:
This is 'a' book
What does "print" mean in your context?
Can I do this? Actually I want to use this Select to generate another
query, and there's some constant string in it, so I need to do this.
The escaping is only necessary when the string is interpreted somehow:
either when you construct the string from literals, or when you give it to
DB2 to prepare the statement. Once interpreted, DB2 has internally a
single-quote character and there are no string delimiters any longer
relevant.

Here is an example:

$ db2 "VALUES 'This is a ''string'''"

1
------------------
this is a 'string'

1 record(s) selected.

When DB2 parses this SQL statement, it finds the first single-quote and
knows that you provide a string literal. Then it searches for the next
single-quote. Following that is another single-quote, indicating that only
a _single_ single-quote should remain and that the string literal is not
yet finished. So you have a nested single-quote in the string. The same
happens with the 2nd escaped single-quote. Finally, DB2 encounters the
last single-quote. That does not escape another single-quote so that it
marks the end of the string literal.

That's just the parsing/interpretation process. Internally, you just have a
string as the one shown in the result for my query above.

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Mar 29 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1612
by: thri | last post by:
What is the escape character for ACCESS strings. I have a function to parse a string into words and '' is the delimiter. but access recognises only one of the \\. for eg : \\one\\two is the string and my function getsubtring returns \two if i wanted the second word. I have tried single quote ' and that does not work. any help will be appreciated.
13
19371
by: Vijay Kumar R. Zanvar | last post by:
Hello, I have few questions. They are: 1. Is "const char * const *p;" a valid construct? 2. How do I align a given structure, say, at 32-byte boundary? 3. Then, how do I assert that a given object is aligned, say, at 32-byte boundary?
6
27783
by: G Patel | last post by:
I've been looking at some code for string functions (certain implementation of them) and the non modified string is usually declared as a const char *s in the parameter list. I was wondering, what exactly does that mean. Does that mean the function is restricted from changing the address (changing s) or changing what's being pointed to (*s)?
2
8337
by: Pep | last post by:
I have been investigating a piece of code that deals with buffers and have the real possibility that after a convoluted algorithm to determine the length of the desired buffer is executed, the applcation could attempt to allocate a buffer of zero size! Could you tell me the effects of the following piece of code? #include <iostream> #include <stdio.h>
58
4913
by: LuisC | last post by:
What is better for holding small numbers in a program? I know that char uses less memory, but, with 32 or 64 bits systems, there are advantages (such as processing time) in using int instead of char for small numbers? Luis
0
10792
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10895
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10443
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9611
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7998
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5830
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6029
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4251
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3256
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.