Numeric to real
>>-REAL--(--numeric-expression--)------------------------------><
String to real
>>-REAL--(--string-expression--)-------------------------------><
The REAL function returns a single-precision
floating-point representation of either:
- A number
- A string representation of a number
Numeric to real
- numeric-expression
- An expression that returns a value of any built-in numeric data
type.
The result is the same number that would
occur if the argument were assigned to a single-precision floating-point
column or variable. If the numeric value of the argument is not within
the range of single-precision floating-point, an error is returned
(SQLSTATE 22003).
String to real
- string-expression
- An expression that returns a value that is character-string
or Unicode graphic-string representation of a number. The data type
of string-expression must not be a CLOB or a DBCLOB (SQLSTATE 42884).
The
result is the same number that would result from CAST(string-expression
AS REAL). Leading and trailing blanks are eliminated and the resulting
string must conform to the rules for forming a valid numeric constant
(SQLSTATE 22018). If the numeric value of the argument is not within
the range of single-precision floating-point, an error is returned
(SQLSTATE 22003).
The result of the function is a single-precision
floating-point number. If the argument can be null, the result can
be null; if the argument is null, the result is the null value.
Note: The CAST specification should be used to increase
the portability of applications. For more information, see "CAST
specification".
Using the EMPLOYEE table, find the ratio of salary to
commission for employees whose commission is not zero. The columns
involved (SALARY and COMM) have DECIMAL data types. The result is
desired in single-precision floating point. Therefore, REAL is applied
to SALARY so that the division is carried out in floating point (actually
double-precision) and then REAL is applied to the complete expression
to return the result in single-precision floating point.
SELECT EMPNO, REAL(REAL(SALARY)/COMM)
FROM EMPLOYEE
WHERE COMM > 0