SQRT

The SQRT function returns the square root of a number.

Read syntax diagramSkip visual syntax diagramSQRT(expression)
expression
An expression that returns a value of any built-in numeric, character-string, or graphic-string data type. A string argument is converted to double-precision floating point before evaluating the function. For more information about converting strings to double-precision floating point, see DOUBLE_PRECISION or DOUBLE. The value of expression must be greater than or equal to zero.

If the data type of the argument is DECFLOAT(n), the result is DECFLOAT(n). Otherwise, the data type of the result is double-precision floating point. If the argument can be null, the result can be null; if the argument is null, the result is the null value.

Note

Results involving DECFLOAT special values: For decimal floating-point values the special values are treated as follows:
  • SQRT(NaN) returns NaN. 1
  • SQRT(-NaN) returns NaN. 1
  • SQRT(Infinity) returns Infinity.
  • SQRT(-Infinity) returns NaN. 1
  • SQRT(sNaN) and SQRT(-sNaN) return a warning or error. 1

Example

  • Assume the host variable SQUARE is a DECIMAL(2,1) host variable with a value of 9.0.
      SELECT SQRT(:SQUARE)
        FROM SYSIBM.SYSDUMMY1
    Returns the approximate value 3.00.
1 If *YES is specified for the SQL_DECFLOAT_WARNINGS query option, NaN is returned with a warning.