Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2007
    Posts
    1

    Unanswered: 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.

  2. #2
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    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

Posting Permissions

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