Home

CASE should be used rather than DECODE

Rule description

  • CASE should be used rather than DECODE

 

Non-compliant Code Example

SELECT Id,
DECODE (statecode, 101, 'New York', 
    201, 'New Jersey', 
    301, 'Seattle', 
    401, 'San Francisco',
    'Unknown') 
"Service Center Location"
FROM cars
WHERE cars.Id < 1000; 

Compliant Code Example

SELECT Id,
       CASE statecode
			WHEN 101 THEN 'New York' 
			WHEN 201 THEN 'New Jersey' 
			WHEN 301 THEN 'Seattle' 
			WHEN 401 THEN 'San Francisco'
			Else 'Unknown'
		END
FROM cars
WHERE Id < 1000;
Visual Expert 2020
 VEPLSQLRULE87