Updated on 2024-09-19 GMT+08:00

Other Functions

Description

SQL functions also support some conversion types and logical operations such as CASE and WHEN. For details, see Table 1.

Syntax

SELECT CAST(fieldname1 AS VARCHAR) AS fieldname1_str

Other Function Statements

Table 1 Other function statements

Keyword

Description

Example

CAST(value AS TYPE)

Converts the data type. Data types can be converted only to varchar or float.

SELECT fieldname1, CAST(fieldname1 AS VARCHAR)

CASE WHEN boolean_expr1 THEN result1 \[ WHEN boolean_expr2 THEN result2 ... \] \[ ELSE resultN \] END

Simple CASE function.

SELECT CASE WHEN httpStatus = 200 THEN 1 ELSE 0 END

NULLIF(value1, value2)

If value1 is equal to value2, null is returned. Otherwise, value1 is returned.

SELECT fieldname1, fieldname2, NULLIF(fieldname1, fieldname2)

NVL(expr,expr-for-null)

If expr is null or an empty string, this function returns expr-for-null.

SELECT NVL(str1, 'expr-for-null')