Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: CASE WHEN or DECODE - any efficiency differences
> -----Original Message----- > From: Nicoll, Iain (Calanais) [mailto:iain.nicoll_at_calanais.com] > > I've just been asked whether there are any efficiency > differences between > CASE WHEN and DECODE. I'd imagined that they would use the > same underlying > code but perhaps not. Does anyone know which is more > efficient (I realise > that CASE is SQL-92 compliant and allows use of IN but > excluding this is > there any efficiency difference)
This is not the test I originally ran, but you could try this in your database (uses dba_objects). I just ran this script on one of our development databases with a large number of objects. The version with case took approx. 27 seconds, the version with decode approx. 24 seconds (time displayed by "set timing on").
set timing on
set autotrace traceonly statistics
select
case
then 'Object Name starts with A'
then 'Object Name starts with B'
then 'Object Name starts with C'
then 'Object Name starts with D'
then 'Object Name starts with E'
then 'Object Name starts with F'
then 'Object Name starts with G'
then 'Object Name starts with H'
then 'Object Name starts with I'
then 'Object Name starts with J'
then 'Object Name starts with K'
then 'Object Name starts with L'
then 'Object Name starts with M'
then 'Object Name starts with N'
then 'Object Name starts with O'
then 'Object Name starts with P'
then 'Object Name starts with Q'
then 'Object Name starts with R'
then 'Object Name starts with S'
then 'Object Name starts with T'
then 'Object Name starts with U'
then 'Object Name starts with V'
then 'Object Name starts with W'
then 'Object Name starts with X'
then 'Object Name starts with Y'
then 'Object Name starts with Z'
decode (substr (object_name, 1, 1), 'A', 'Object Name starts with A', 'B', 'Object Name starts with B', 'C', 'Object Name starts with C', 'D', 'Object Name starts with D', 'E', 'Object Name starts with E', 'F', 'Object Name starts with F', 'G', 'Object Name starts with G', 'H', 'Object Name starts with H', 'I', 'Object Name starts with I', 'J', 'Object Name starts with J', 'K', 'Object Name starts with K', 'L', 'Object Name starts with L', 'M', 'Object Name starts with M', 'N', 'Object Name starts with N', 'O', 'Object Name starts with O', 'P', 'Object Name starts with P', 'Q', 'Object Name starts with Q', 'R', 'Object Name starts with R', 'S', 'Object Name starts with S', 'T', 'Object Name starts with T', 'U', 'Object Name starts with U', 'V', 'Object Name starts with V', 'W', 'Object Name starts with W', 'X', 'Object Name starts with X', 'Y', 'Object Name starts with Y', 'Z', 'Object Name starts with Z', 'Object Name doesn''t start with capital letter' ) as object_name_first_letter
![]() |
![]() |