Performance decission DECODE vs CASE
Hi Gurus,
I have a stored procedure that has to process around 2 million records. The performance is very slow at the moment.
I need advise on the following section :-)
CASE x
WHEN '1' THEN
y := 'A';
WHEN '2' THEN
y := 'B';
WHEN '3' THEN
y := 'C';
WHEN '...'
y := '...';
END CASE;
There are around 25 different cases, of course the values I put here are dummy...
Can I replace it with DECODE as its 1 to 1 comparison / return like
y := DECODE(x, '1', 'A', '2', 'B', '3', 'C', .... '...', '...');
Is it a faster executing code or CASE better? I know, CASE has its own advantages like readability, flexibility etc. but how about performance in my particular expression set?
Best Regards,
Faisal.
You could also consider the following.
declare
v_dummy VARCHAR2(1);
v_start timestamp;
v_end timestamp;
begin
v_start := systimestamp;
for i in 1..100 loop
for j in (select decode(status,'INVALID','I','VALID','V') s
FROM dba_objects) loop
v_dummy := j.s;
END LOOP;
END LOOP;
v_end := systimestamp;
dbms_output.put_line('time : '||to_char(v_end - v_start,'SSSSS.FF'));
END;
time : +000000 00:00:25.454000000
time : +000000 00:00:25.422000000
time : +000000 00:00:25.515000000
===========================================================================
declare
v_dummy VARCHAR2(1);
v_start timestamp;
v_end timestamp;
begin
v_start := systimestamp;
for i in 1..100 loop
for j in (select case status when 'INVALID' then 'I'
when 'VALID' then 'V' end s
FROM dba_objects) loop
v_dummy := j.s;
END LOOP;
END LOOP;
v_end := systimestamp;
dbms_output.put_line('time : '||to_char(v_end - v_start,'SSSSS.FF'));
END;
time : +000000 00:00:25.187000000
time : +000000 00:00:25.031000000
time : +000000 00:00:25.141000000
===========================================================================
declare
v_dummy VARCHAR2(1);
v_start timestamp;
v_end timestamp;
begin
v_start := systimestamp;
for i in 1..100 loop
for j in (select status s
FROM dba_objects) loop
SELECT decode(j.s,'INVALID','I','VALID','V')
into v_dummy
FROM dual;
END LOOP;
END LOOP;
v_end := systimestamp;
dbms_output.put_line('time : '||to_char(v_end - v_start,'SSSSS.FF'));
END;
time : +000000 00:04:07.688000000
time : +000000 00:04:06.953000000
time : +000000 00:04:07.453000000
===========================================================================
declare
v_dummy VARCHAR2(1);
v_start timestamp;
v_end timestamp;
begin
v_start := systimestamp;
for i in 1..100 loop
for j in (select status s
FROM dba_objects) loop
case j.s when 'INVALID' then v_dummy := 'I';
when 'VALID' then v_dummy := 'V';
end case;
END LOOP;
END LOOP;
v_end := systimestamp;
dbms_output.put_line('time : '||to_char(v_end - v_start,'SSSSS.FF'));
END;
time : +000000 00:00:25.187000000
time : +000000 00:00:25.343000000
time : +000000 00:00:25.172000000This on a windows dual core laptop with 10gR2
Regards
Andre
Similar Messages
-
Which is the best decode or case
Hi,
When you check performance wise which is the best one decode or case?
Thanks,> You mean CPU processor speed or oracle buffer(SGA).
Neither. CPU architecture. RISC vs CISC vs ..
On a PA-RISC1 CPU a DECODE is just a tad faster than a CASE. On an AMD64 CPU, the reverse is true.
> When I increase memory, The case and decode performance will increase?
No. A CASE and a DECODE does not need memory to work faster. It is a set of machine code instructions that needs to compare values to determine a result. It depends on just how fast the CPU can execute this set of machine code instructions.
A faster CPU will make a very significant difference. An AMD64 Opteron CPU is a couple of times faster than a PA-RISC1 CPU.
I had this exact same conversation back in 2006 on this forum - and posted [url
http://forums.oracle.com/forums/thread.jspa?messageID=1346165�]this benchmark to show that the decision of using CASE or DECODE is not a decision that should be based on raw performance. -
Hi
I need small clarification about difference between decode and case
Thanks who visit my threadAnd for those people who can't be ar$ed to follow links...
Decode allows for conditional output where the conditions are straightforward matches between values.
Case allows for regular conditions to be used such as greater than, less than etc.
Some of the things done by case can be achieved through decode as well but in a more convoluted manner than simply using case.
;) -
What will be good for proformance wise:
Decode or Case in a sql statement.?????See the following link for Tom Kyte's opinion (point #4 in his first answer):
http://asktom.oracle.com/pls/ask/f?p=4950:8:16717708356827415201::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:1243867216406 -
I have emp_allocation table. It has data as below
EMPID YEAR MONTH
X 2006 JAN
X 2006 MAR
Y 2006 JAN
Y 2006 FEB
Y 2006 MAR
I want SQL Query(Without Decode or Case) which will give output as below
EMPID YEAR JAN FEB MAR APR JUN JUL
X 2006 Y N Y
Y 2006 Y Y YWhy you'd want to do it this way I do not know, but if you insist...
SQL> ed
Wrote file afiedt.buf
1 WITH t AS (select 'X' AS EMPID, 2006 AS YEAR, 'JAN' AS MONTH FROM DUAL UNION ALL
2 select 'X', 2006, 'MAR' FROM DUAL UNION ALL
3 select 'Y', 2006, 'JAN' FROM DUAL UNION ALL
4 select 'Y', 2006, 'FEB' FROM DUAL UNION ALL
5 select 'Y', 2006, 'MAR' FROM DUAL)
6 -- END OF TEST DATA
7 SELECT EMPID, YEAR, NVL(MAX(JAN),'N') AS JAN, NVL(MAX(FEB),'N') AS FEB, NVL(MAX(MAR),'N') AS MAR, NVL(MAX(APR),'N') AS APR
8 FROM
9 (
10 SELECT EMPID, YEAR, 'Y' AS JAN, NULL AS FEB, NULL AS MAR, NULL AS APR FROM t WHERE MONTH = 'JAN' UNION ALL
11 SELECT EMPID, YEAR, NULL AS JAN, 'Y' AS FEB, NULL AS MAR, NULL AS APR FROM t WHERE MONTH = 'FEB' UNION ALL
12 SELECT EMPID, YEAR, NULL AS JAN, NULL AS FEB, 'Y' AS MAR, NULL AS APR FROM t WHERE MONTH = 'MAR' UNION ALL
13 SELECT EMPID, YEAR, NULL AS JAN, NULL AS FEB, NULL AS MAR, 'Y' AS APR FROM t WHERE MONTH = 'APR'
14 )
15 GROUP BY EMPID, YEAR
16* ORDER BY 1,2
SQL> /
E YEAR J F M A
X 2006 Y N Y N
Y 2006 Y Y Y N
SQL> -
Hi,
What is the difference between decode and case?
What are the cases in which we can use Decode and case
Thanxyou can not put Search CASE statements by using DECODE
Eg:
SELECT AVG(CASE WHEN e.salary > 2000 THEN e.salary ELSE 2000 END) "Average Salary" FROM employees e;Can't we?
select avg(decode(sign(e.salary - 2000), 1, e.salary, 2000)) "Average Salary" from employees e; -
Hi all,
select
id
,one
,two
From
(select id
, one
, two
, Max(decode(TYPE, "ER", 3*4, 4*7)
from
(select id
, sum(one) as one
, sum(two) as two
from t1
group by id)
group by id, one, two
) temp inner join t2....
The above query is just a sample structure to tell the problem that i am facing. It works fine, but i need to convert it to ANSI Standard.
Hence I need to convert the DECODE to CASE statement. but if i convert to CASE, i need to use any of the GROUP BY FUNCTIONS, but if i use the MAX of any group by functions, the result would be wrong...how to overcome it
ThanksHi,
Yes I did a silly mistake, the code I gave was for only the decode but when I converted it to case statement, there was a silly mistake, which i corrected.
Now i corrected it to
Select
COL1
, Col2
, MAX(CASE WHEN Upper(TYPE) = 'YR' THEN Round(3.43*3, 2) END) AS CALC1
, Max(CASE WHEN Upper(TYPE) = 'ZP' THEN Round(3.12*12, 2) END) AS CALC2
From
Group by....
but now when i add a sum of the calc1 & calc2, I am not getting any results the column is blank. Is there anything that i missed
Select
COL1
, Col2
, MAX(CASE WHEN Upper(TYPE) = 'YR' THEN Round(3.43*3, 2) END) AS CALC1
, Max(CASE WHEN Upper(TYPE) = 'ZP' THEN Round(3.12*12, 2) END) AS CALC2
, (MAX(CASE WHEN Upper(TYPE) = 'YR' THEN Round(3.43*3, 2) END
+ Max(CASE WHEN Upper(TYPE) = 'ZP' THEN Round(3.12*12, 2) END)) as SUM3
From
Group by....
Thanks -
I'm a beginner with Oracle SQL and I have a select statement with the following code:
max(decode(EDW.V_RECRUIT_TEST_RESULT_HIST.TEST_CD, '1000', EDW.V_RECRUIT_TEST_RESULT_HIST.TEST_RESULT_TEST_SCORE, '2000', EDW.V_RECRUIT_TEST_RESULT_HIST.TEST_RESULT_TEST_SCORE, '4000', EDW.V_RECRUIT_TEST_RESULT_HIST.TEST_RESULT_TEST_SCORE))
I've been asked to create several more columns in a similar manner. My concern is that since this relies on 'decode' which is less efficient than 'case', that adding more columns using this approach will bog down an already not efficient query. Bottom line my problem is that I don't really understand this 'decode' since all the explanations of 'decode' I've found stop at four parameters.
Could someone please show me how the expression above looks in If-then-else terms as well as comment on how to convert this 'decode' to 'case'? Thanks in advance!1) The if-then-else stmt
-- Longest way
if EDW.V_RECRUIT_TEST_RESULT_HIST.TEST_CD = '1000' then
return value of EDW.V_RECRUIT_TEST_RESULT_HIST.TEST_RESULT_TEST_SCORE;
elsif EDW.V_RECRUIT_TEST_RESULT_HIST.TEST_CD = '2000' then
return value of EDW.V_RECRUIT_TEST_RESULT_HIST.TEST_RESULT_TEST_SCORE;
elsif EDW.V_RECRUIT_TEST_RESULT_HIST.TEST_CD = '4000' then
return value of EDW.V_RECRUIT_TEST_RESULT_HIST.TEST_RESULT_TEST_SCORE;
else return null;
end if;
-- shorter way
if EDW.V_RECRUIT_TEST_RESULT_HIST.TEST_CD = '1000' or
EDW.V_RECRUIT_TEST_RESULT_HIST.TEST_CD = '2000' or
EDW.V_RECRUIT_TEST_RESULT_HIST.TEST_CD = '4000' then
return value of EDW.V_RECRUIT_TEST_RESULT_HIST.TEST_RESULT_TEST_SCORE;
else return null;
end if;
-- shortest if-then-else code
if EDW.V_RECRUIT_TEST_RESULT_HIST.TEST_CD in ('1000', '2000', '4000') then
return value of EDW.V_RECRUIT_TEST_RESULT_HIST.TEST_RESULT_TEST_SCORE;
else return null;
end if;
2) The MAX() function
The MAX function will return the greatest value of EDW.V_RECRUIT_TEST_RESULT_HIST.TEST_RESULT_TEST_SCORE in step 1 above.
2) Using CASE
select
max(case when (EDW.V_RECRUIT_TEST_RESULT_HIST.TEST_CD in('1000','2000','4000'))
then EDW.V_RECRUIT_TEST_RESULT_HIST.TEST_RESULT_TEST_SCORE end)
into ...your_item_or_local_variable
from EDW.V_RECRUIT_TEST_RESULT_HIST;
Try the code above, good luck
v/r
Vien Tran -
What is better and fast to use between decode and case
Hi friends,
i wanted to know what is better to use decode or case in sql,which gives faster result.
thks
sonal....Here's a very simple timing comparison. This table (actually it's a partition) has a little over 1 million rows.
As you can see, the timing difference is trivial. (I ran an earlier query to fetch the blocks from disk).
SQL> select sum(decode(balloon_flag
2 ,'Y',1
3 ,0
4 )
5 ) bal_count
6 from prod.loan_master
7 where report_date = to_date('31-DEC-2005');
BAL_COUNT
9036
Elapsed: 00:00:07.65
SQL> select sum(case balloon_flag
2 when 'Y' then 1
3 else 0
4 end
5 ) bal_count
6 from prod.loan_master
7 where report_date = to_date('31-DEC-2005');
BAL_COUNT
9036
Elapsed: 00:00:07.68
SQL> select sum(case
2 when balloon_flag = 'Y' then 1
3 else 0
4 end
5 ) bal_count
6 from prod.loan_master
7 where report_date = to_date('31-DEC-2005');
BAL_COUNT
9036
Elapsed: 00:00:07.46 -
How does decode and case works?
Hi,
I want to know how decode and case works? How they process the arguements. Please explain me with some examples.
Thanks,
Sarav
Edited by: 943941 on Jul 3, 2012 1:42 AMwelcome
check this link
https://forums.oracle.com/forums/ann.jspa?annID=1535
you will find everything you need
DECODE compares expr to each search value one by one. If expr is equal to a search, then Oracle Database returns the corresponding result. If no match is found, then Oracle returns default. If default is omitted, then Oracle returns null.
This example decodes the value warehouse_id. If warehouse_id is 1, then the function returns 'Southlake'; if warehouse_id is 2, then it returns 'San Francisco'; and so forth. If warehouse_id is not 1, 2, 3, or 4, then the function returns 'Non domestic'.
SELECT product_id,
DECODE (warehouse_id, 1, 'Southlake',
2, 'San Francisco',
3, 'New Jersey',
4, 'Seattle',
'Non domestic')
"Location of inventory" FROM inventories
WHERE product_id < 1775;Edited by: user 007 on Jul 3, 2012 2:40 PM -
DECODE Vs CASE Performance Issue
Hi,
The comparison is on basis of performance. There are billions of records to be processed and millions to be updated.
Please go through the folowing queried to have general idea because the actual query is 2 page long.
DECODE(EXP,1,VAL1,VAL2)
Vs
CASE WHEN EXP=1
THEN VAL1
ELSE
VAL2
END
Update table1
set column=( select query)
where (item) IN (select item from table2 )
Please give inputs in term of performance.
Regards
Nitin BajajHu... I can understand your point also but it is not
diff to find the solution in the thread, you don't
need to read the whole thread.Even if you see that there are no entries in the duplicate postings, whenever you are using the search function, those will also be shown.
but put yourself in his position, he might be in need
of desparate help right...
Think in two ways...And posting the same problem again and again solves this?
cd -
Hi,
I had a condition like
test -table
code - column
t --> True
f --> False
I had two choices of writing query
select decode(code,'t','True','False') from test;
or
select case code
when 't' then 'True'
else 'False'
end
from test;
I want to know which one is best performance wiseWrong question really.. unless you writing a very tight loop doing 100's of 1000's of iterations using that type of conditional structure. And even then performance difference will not be that significant.
The right question to ask is which one is more flexible and allows for the programmer that comes after you to read and understand and maintain your code. The CASE statement is in this regard, a lot better than a DECODE statement.
Looking just at performance (which I suggest you do not do in isolation!!), I get mixed results using 10G Enterprise on different platforms (HP-UX vs SUN AMD) and operating systems (HP-UX vs Linux).
On the former the DECODE is slightly faster. On the latter the CASE is slightly faster.
Using the construct you've specified and doing a tight loop of a 100,000 iterations, the elapsed execution times are:
HP-UX DECODE = 00:00:11.83
HP-UX CASE = 00:00:12.32
Linux/AMD DECODE =00:00:02.02
Linux/AMD CASE = 00:00:01.84
Obviosuly the CPU architecture plays a major role here. The AMD is considered as the best 64 CPU on the market. The HP-UX PARISC CPU (also 64bit), does not really compare raw performance wise. In addition this is a RISC CPU whereas the AMD CPU is I believe more CISC than RISC.
Also interesting that the faster Sun AMD/Linux server I used for this benchmark is about 10% the price of the HP-UX server.. and about 5x faster ito raw speed as this benchmark showed. :-)
An interesting exercise, but one with little real world value. Yes performance is important. But within PL/SQL, not to the level about debating whether a CASE or DECODE is faster. As I've mentioned, I believe the right question being one about readability and maintenance and not performance in this case. -
Decode Vs Case: context switching?
So I was told recently that among other reasons, CASE is "better" than Decode in SQL statements because Decode context switches to PL/SQL to perform the checks.
I can't find anything in the documentation to support this.
this site here:
http://www.dba-oracle.com/oracle_news/2005_11_23_case_decode_machinations.htm
mentions that one of the disadvantages of decode is that it's post-retrieval, but it also seems to mention that so is CASE.
anyone have any idea where someone may have got the "context switching" idea from?have often wondered why you would use CASE in PL/SQL when it has IF THEN control structures. Yes, you could, however readability would suffer. But what is more important CASE has a form where expression is evaluated only once:
SQL> SET SERVEROUTPUT ON
SQL> DECLARE
2 X NUMBER;
3 BEGIN
4 PKG1.CNT := 2;
5 X := CASE PKG1.F1
6 WHEN 1 THEN 1
7 WHEN 2 THEN 2
8 WHEN 3 THEN 3
9 END;
10 DBMS_OUTPUT.PUT_LINE('X = ' || X);
11 DBMS_OUTPUT.PUT_LINE('PKG1.CNT = ' || PKG1.CNT);
12 END;
13 /
Call to PKG1.F1
X = 3
PKG1.CNT = 3
PL/SQL procedure successfully completed.
SQL> DECLARE
2 X NUMBER;
3 BEGIN
4 PKG1.CNT := 2;
5 IF PKG1.F1 = 1
6 THEN X := 1;
7 ELSIF PKG1.F1 = 2
8 THEN X := 2;
9 ELSIF PKG1.F1 = 3
10 THEN X := 3;
11 END IF;
12 DBMS_OUTPUT.PUT_LINE('X = ' || X);
13 DBMS_OUTPUT.PUT_LINE('PKG1.CNT = ' || PKG1.CNT);
14 END;
15 /
Call to PKG1.F1
Call to PKG1.F1
Call to PKG1.F1
X =
PKG1.CNT = 5
PL/SQL procedure successfully completed.
SQL> In such case you would have to introduce a temp variable:
SQL> CREATE OR REPLACE
2 PACKAGE PKG1
3 IS
4 CNT NUMBER;
5 FUNCTION F1 RETURN NUMBER;
6 END;
7 /
Package created.
SQL> CREATE OR REPLACE
2 PACKAGE BODY PKG1
3 IS
4 FUNCTION F1 RETURN NUMBER
5 IS
6 BEGIN
7 DBMS_OUTPUT.PUT_LINE('Call to PKG1.F1');
8 CNT := CNT + 1;
9 RETURN CNT;
10 END;
11 END;
12 /
Package body created.
SQL> SET SERVEROUTPUT ON
SQL> DECLARE
2 X NUMBER;
3 BEGIN
4 PKG1.CNT := 2;
5 X := CASE PKG1.F1
6 WHEN 1 THEN 1
7 WHEN 2 THEN 2
8 WHEN 3 THEN 3
9 END;
10 DBMS_OUTPUT.PUT_LINE('X = ' || X);
11 DBMS_OUTPUT.PUT_LINE('PKG1.CNT = ' || PKG1.CNT);
12 END;
13 /
Call to PKG1.F1
X = 3
PKG1.CNT = 3
PL/SQL procedure successfully completed.
SQL> DECLARE
2 X NUMBER;
3 TMP NUMBER;
4 BEGIN
5 PKG1.CNT := 2;
6 TMP := PKG1.F1;
7 IF TMP = 1
8 THEN X := 1;
9 ELSIF TMP = 2
10 THEN X := 2;
11 ELSIF TMP = 3
12 THEN X := 3;
13 END IF;
14 DBMS_OUTPUT.PUT_LINE('X = ' || X);
15 DBMS_OUTPUT.PUT_LINE('PKG1.CNT = ' || PKG1.CNT);
16 END;
17 /
Call to PKG1.F1
X = 3
PKG1.CNT = 3
PL/SQL procedure successfully completed.
SQL> SY. -
More effecient way of using Decode and CASE
Is it possible to use both case and decode together? I feel I have too many decode and I am not sure how to write this in a more efficient way.
I would really appreciate any help.
Thank you so much in advance!!!
SELECT Person_ID,Work_ID,
CASE WHEN NBR = 1 THEN
MIN(DECODE(NBR, 1, field1)) aug_one_field1;
MIN(DECODE(NBR, 1, field2)) aug_one_field2;
MIN(DECODE(NBR, 1, field3)) aug_one_field3;
MIN(DECODE(NBR, 1, field4)) aug_one_field4;
MIN(DECODE(NBR, 1, field5)) aug_one_field5;
MIN(DECODE(NBR, 1, field6)) aug_one_field6;
CASE WHEN NBR = 2 THEN
MIN(DECODE(NBR, 2, field1)) aug_two_field1;
MIN(DECODE(NBR, 2, field2)) aug_two_field2;
MIN(DECODE(NBR, 2, field3)) aug_two_field3;
MIN(DECODE(NBR, 2, field4)) aug_two_field4;
MIN(DECODE(NBR, 2, field5)) aug_two_field5;
MIN(DECODE(NBR, 2, field6)) aug_two_field6;
CASE WHEN NBR = 3 THEN
MIN(DECODE(NBR, 3, field1)) aug_three_field1;
MIN(DECODE(NBR, 3, field2)) aug_three_field2;
MIN(DECODE(NBR, 3, field3)) aug_three_field3;
MIN(DECODE(NBR, 3, field4)) aug_three_field4;
MIN(DECODE(NBR, 3, field5)) aug_three_field5;
MIN(DECODE(NBR, 3, field6)) aug_three_field6;
CASE WHEN NBR = 4 THEN
MIN(DECODE(NBR, 4, field1)) aug_four_field1;
MIN(DECODE(NBR, 4, field2)) aug_four_field2;
MIN(DECODE(NBR, 4, field3)) aug_four_field3;
MIN(DECODE(NBR, 4, field4)) aug_four_field4;
MIN(DECODE(NBR, 4, field5)) aug_four_field5;
MIN(DECODE(NBR, 4, field6)) aug_four_field6;
END
FROM (SELECT Person_ID,Work_ID, NBR
fiel1, field2, field3,field4,field5, field6,
FROM field_rep
GROUP BY Person_ID,Work_IDThanks alot John and Frank.
John to answer your question, I just felt the 24 or more decode will slow down the systems performance, hence I was trying to find a better way to do it.
Frank
This is a sample data but I want it pivoted hence the reason for using the decode. I have oracle 10g. These are sample data
Person_id work_id NBR field1 field2 field3 field4 field5 field6
1 ao334 1 1/2/2009 1/9/2010 block_A HH 55667 1
1 ao334 2 5/2/2011 9/9/2013 block_Z HL 11111 3
1 ao334 2 1/2/2009 1/9/2010 block_A HH 22222 1
1 ao334 4 1/2/2009 1/9/2010 block_A HH zzzzz 7
1 z5521 1 10/5/2006 12/31/2012 block_C SS 33322 1
1 z5521 2 1/2/2009 1/9/2010 block_C SS 21550 1
1 z5521 3 1/2/2009 1/9/2010 block_R SS 10000 1
1 z5521 4 1/2/2009 1/9/2010 block_D SS 99100 5
1 z5521 5 1/2/2009 1/9/2010 block_P SS 88860 1
1 z5521 6 1/2/2009 1/9/2010 block_G SS 99660 8
1 ob114 1 1/2/2009 1/9/2010 block_A HH 52333 1
1 ob114 2 1/2/2009 1/9/2010 block_A HH 88888 1Output will look like this
Person_id work_id aug_one_field1 aug_one_field2 aug_one_field3 aug_one_field4 aug_one_field5 aug_one_field6 aug_two_field1 aug_two_field2 aug_two_field3 aug_two_field4 aug_two_field5 aug_two_field6
1 ao334 1/2/2009 1/9/2010 block_A HH 55667 1 5/2/2011 9/9/2013 block_Z HL 11111 3 -
DECODE OR CASE - Which is better and why
Oracle version: 11.2
Problem: We have a huge table with 10M records, which needs to be processed daily.
While loading data in table we have to handle condition if flag is =1 then '111' else '000'
To implement this which one is efficient solution? .. using CASE or DECODE and why?
Example:
SQL> select flag,case when flag='Y' then '111' else '000' end from (select 'Y' as flag from dual union all select 'N' from dual);
F CAS
Y 111
N 000
SQL> select flag,decode(flag,'Y','111','000') from (select 'Y' as flag from dual union all select 'N' from dual);
F DEC
Y 111
N 000Hi,
For this job, they're equally efficient.
For any job, where DECODE doesn't require a lot more code than CASE, they will be equally efficient.
I recommend (almost) always using CASE. It's easier to understand and debug, and, if written correctly, will never be slower than DECODE.
The only situation where I use DECODE is for very simple tasks (like the one you posted) where this is used inside a very complicated expression, and the slightly less coding needed for DECODE makes the larger statement easier to read.
Maybe you are looking for
-
How can I display an icon, instead of text string, as a validation prompt?
My validate method inside my custom validator is like this: public void validate(FacesContext context, UIComponent component, Object value) { Pattern datePattern = Pattern.compile("(\\d{2})/(\\d{2})/(\\d{4})"); Matcher dateMatcher = datePattern.m
-
Lack of response from emu/creative
I posted a request for support form about a week ago then followed this up with a contact us form both via the emu/creative website. how long is reasonable to wait for just an email acknowledgement as I have had nothing at all. Emu have no phone numb
-
Sorry I'm new to Final Cut Express. How do you make an image (jpeg file for example) move across the screen slowly as I've seen in many films.
-
How do I create a 20x30 JPEG custom photo collage in LR 5 for Mac?
Hello - I am trying to create a custom layout for a 50th anniversary collage in LR 5 for Mac. However, my page setup only includes print sizes that are compatible with my printer. I plan to save this layout in JPEG to be uploaded to a photo finishi
-
Bridge cs5 will not recognize cr2 files [mod edit: from the Canon 1DX]
I just re-installed Photoshop CS5 to a new computer, but now I see that Bridge cannot preview CR2 raw files from my camera. Do I need a special plugin for this? Bridge worked fine on my old computer, but I can't remember what I did to see the preview