473,395 Members | 1,986 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

CHAR vs CAST DB2 UDB v8.1.9 Linux

Vol. 1 of SQL REFERENCE contains the following statement in the
description of CHAR:

Note: The CAST expression can also be used to return a string expression.

I was trying it in order to get rid of leading zeroes when I got the
surprising result that my result set was empty. The only change in the
select was to change

CHAR(t4.dosage)||' '||t5.dosage_units AS dose,

to

CAST(t4.dosage AS CHAR)||' '||t5.dosage_units AS dose,

I realized that this was (maybe) a syntax error since no length was
supplied, but the result is still surprising.
Dec 16 '05 #1
3 11024
Bob Stearns wrote:
Vol. 1 of SQL REFERENCE contains the following statement in the
description of CHAR:

Note: The CAST expression can also be used to return a string expression.

I was trying it in order to get rid of leading zeroes when I got the
surprising result that my result set was empty. The only change in the
select was to change

CHAR(t4.dosage)||' '||t5.dosage_units AS dose,

to

CAST(t4.dosage AS CHAR)||' '||t5.dosage_units AS dose,

I realized that this was (maybe) a syntax error since no length was
supplied, but the result is still surprising.


If you say CHAR (or CHARACTER), then this is equivalent to CHAR(1), i.e. a
string with exactly one character. You need to provide the length in the
CAST.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Dec 16 '05 #2
Knut Stolze wrote:
Bob Stearns wrote:

Vol. 1 of SQL REFERENCE contains the following statement in the
description of CHAR:

Note: The CAST expression can also be used to return a string expression.

I was trying it in order to get rid of leading zeroes when I got the
surprising result that my result set was empty. The only change in the
select was to change

CHAR(t4.dosage)||' '||t5.dosage_units AS dose,

to

CAST(t4.dosage AS CHAR)||' '||t5.dosage_units AS dose,

I realized that this was (maybe) a syntax error since no length was
supplied, but the result is still surprising.

If you say CHAR (or CHARACTER), then this is equivalent to CHAR(1), i.e. a
string with exactly one character. You need to provide the length in the
CAST.

But why does it cause the result set to be empty with no error?
Dec 16 '05 #3
Bob Stearns wrote:
Knut Stolze wrote:
Bob Stearns wrote:

Vol. 1 of SQL REFERENCE contains the following statement in the
description of CHAR:

Note: The CAST expression can also be used to return a string expression.

I was trying it in order to get rid of leading zeroes when I got the
surprising result that my result set was empty. The only change in the
select was to change

CHAR(t4.dosage)||' '||t5.dosage_units AS dose,

to

CAST(t4.dosage AS CHAR)||' '||t5.dosage_units AS dose,

I realized that this was (maybe) a syntax error since no length was
supplied, but the result is still surprising.

If you say CHAR (or CHARACTER), then this is equivalent to CHAR(1), i.e.
a
string with exactly one character. You need to provide the length in the
CAST.

But why does it cause the result set to be empty with no error?


Well, I get a warning message:

$ db2 "values cast(decimal(12.3, 5, 3) as char) || ' '"

1
--
1
SQL0445W Value "12.300 " has been truncated. SQLSTATE=01004

1 record(s) selected with 1 warning messages printed.

Maybe your application does not handle warning messages properly or not at
all?

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Dec 16 '05 #4

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

Similar topics

9
by: Christopher Benson-Manica | last post by:
I need a smart char * class, that acts like a char * in all cases, but lets you do some std::string-type stuff with it. (Please don't say to use std::string - it's not an option...). This is my...
22
by: bvb | last post by:
Hi, while declaring/defining pointer to int/char, What is doing the compiler exactly . i'm able to get output(String) for all pointer to char definition(without line # 8&14). But when i include...
14
by: mr_semantics | last post by:
I have been reading about the practise of casting values to unsigned char while using the <ctype.h> functions. For example, c = toupper ((unsigned char) c); Now I understand that the standard...
3
by: QQ | last post by:
Hello, Here is my simple program int main() { unsigned char a =0x81; char b = 0x81; printf("unsigned char = 0x%x(%d), char = 0x%x(%d)\n",a,a,b,b); printf("cast char to unsigned...
26
by: =?gb2312?B?wNbA1rTzzOzKpg==?= | last post by:
i wrote: ----------------------------------------------------------------------- ---------------------------------------- unsigned char * p = reinterpret_cast<unsigned char *>("abcdg");...
18
by: planetzoom | last post by:
Given the following code: #include <stdio.h> int main(void) { char array = "What is your favorite car?"; void *vp = &array; printf("%s\n", vp);
33
by: Michael B Allen | last post by:
Hello, Early on I decided that all text (what most people call "strings" ) in my code would be unsigned char *. The reasoning is that the elements of these arrays are decidedly not signed. In...
11
by: john | last post by:
Hi, at first the code doesn't seem to work. Any ideas?: #include <iostream> #include <cstdlib> int main() { using namespace std;
14
by: rtillmore | last post by:
Hello, I did a quick google search and nothing that was returned is quite what I am looking for. I have a 200 character hexadecimal string that I need to convert into a 100 character string. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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,...

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.