Wednesday, 21 February 2024

abs Function in DB2

In IBM DB2, the ABS function is also used to return the absolute value of a number. Here's the syntax for the ABS function in DB2:


ABS(numeric_expression)

Where numeric_expression is the numeric value for which you want to find the absolute value.

Here's an example:

SELECT ABS(-10) AS absolute_value FROM sysibm.sysdummy1;

This query will return the absolute value of -10, which is 10.

You can also use the ABS function in combination with other columns or expressions in your SQL queries. For example:


SELECT column1, ABS(column2) AS absolute_value

FROM your_table;

This query will return the values of column1 and the absolute values of column2 for each row in your_table.

No comments:

Post a Comment