Difference between SCALAR and COLUMN function

DB2DatabaseBig Data Analytics

The DB2 SCALAR functions take a single column value and returns a single result. The COLUMN function takes the column value from multiple rows of a DB2 table and returns a single result. In case of SCALAR function only one row is involved.

SCALAR FUNCTION
DESCRIPTION
LENGTH
Gives the length of the column value
REPLACE
Used to replace a string with another string
CONCAT
Used to combine two or more column values
INTEGER
Gives the integer equivalent of the column value
CHAR
Gives the character equivalent of the column value

For example, if we have an ORDERS DB2 table and we want to return only the integer value of the ORDER_TOTAL for all the orders placed on 15-08-2020. We will use the below query.

Example

SELECT ORDER_ID, INTEGER(ORDER_TOTAL) FROM ORDERS
   WHERE ORDER_DATE = ‘15-08-2020’

In this case, if any ORDER_ID Z55641 is having the ORDER_TOTAL as 3422.89, then we will get the following result.

ORDER_ID
ORDER_TOTAL
Z55641
3422
raja
Published on 30-Nov-2020 09:15:46
Advertisements