IsNull Function in PeopleSoft MetaSQL

In MS SQL Server, sometimes we will use queries like this to avoid the NULL value to be populated

   1: SELECT ISNULL(TABLE1.COLUMN1,'IT IS NULL')
   2: FROM TABLE1

Similarly, in Oracle Database, we can use this:

   1: SELECT NVL(TABLE1.COLUMN1,'IT IS NULL')
   2: FROM TABLE1

However, in PeopleSoft Meta-SQL, we shall use the function %COALESCE to do the same thing

   1: SELECT %COALESCE(TABLE1.COLUMN1,'IT IS NULL')
   2: FROM TABLE1

Below is the syntax explanation from People Book.

Click to jump to top of pageClick to jump to parent topic
%COALESCE

Syntax

%COALESCE(expr1, expr2, ...)

Description

Use the %COALESCE function to return the first non-null argument provided to the function.

Note. This meta-SQL function is not implemented for COBOL.

Parameters

expr1. . .exprn

Specify the expressions to check.

Note. You cannot specify bind parameters using these expressions.

Example

The following example uses the PRODUCT_INFO table to organize a clearance sale of products. It gives a 10 percent discount to all products with a list price. If there is no list price, the sale price is the minimum price. If there is no minimum price, the sale price is 10.

SELECT product_id, list_price, min_price, %COALESCE(0.9*list_price, min_price, 10)⇒ "Sale" from PRODUCT_INFO where SUPPLIER_ID = 6009;

原文地址:https://www.cnblogs.com/lei1016cn/p/2475964.html