SQL query Raise error function top secrets

The RAISE_ERROR function can be used to signal application program and data problems. One situation where RAISE_ERROR may prove useful is in a CASE statement.

How to use RAISE_ERROR function in DB2 SQL. Understand and follow these secrets.

SELECT EMPNO,
  CASE WHEN SEX = ‘M’ THEN ‘MALE ‘
           WHEN SEX = ‘F’ THEN ‘FEMALE’
  ELSE RAISE_ERROR(’70SX1′, ‘INVALID DATA, SEX IS NEITHER F NOR M.’)
   END
 FROM DSN71010.EMP;

There are three arguments in RAISE_ERROR function:

  • Error to send
  • Condition
  • Requirement
Advertisements

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.