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 > CHAR scalar function

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-15-07, 13:34
algebun algebun is offline
Registered User
 
Join Date: Feb 2007
Posts: 1
CHAR scalar function

What are the rules when you do a CHAR(decimal-field).

I'm sorry to say read the manual, but did not understand it. I've pasted the manual below




Decimal to Character

decimal-expression
An expression that returns a value that is a built-in decimal data type. To specify a different precision and scale for the expression's value, apply the DECIMAL function before applying the CHAR function.

decimal-character
Specifies the single-byte character constant (CHAR or VARCHAR) that is used to delimit the decimal digits in the result character string. The character must not be a digit, a plus sign (+), a minus sign (-), or a blank. The default is the period (.) or comma (,). For information on what factors govern the choice, see "Decimal point representation" in topic 2.24.2.


The result is the fixed-length character string representation of the argument in the form of an SQL decimal constant. The result includes a decimal-character and p digits, where p is the precision of the decimal-expression. If the argument is negative, the first character of the result is a minus sign. Otherwise, the first character is a blank, which means that a positive value always has one leading blank.
The leading blank is not returned for CAST(decimal-expression AS CHAR(n)).

The length of the result is 2+p, where p is the precision of the decimal-expression.
Reply With Quote
  #2 (permalink)  
Old 02-16-07, 02:40
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Basically, if you have the following SQL statement, then the salary field will be returned as a character field:

select char(salary) from emp

0052750.00
0041250.00
0038250.00
etc

Note that salary is defined as DECIMAL (9,2) in the table.

If you explain what you are trying to do, then someone can suggest the appropriate function or syntax to use.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
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