Regarding case and decode.
Hi !
I need to return all the employess, and indicate with "YES" or "NO" wherther they receive a commission.
I am trying to get this by using CASE and DECODE but result is comming different.
USING DECODE:
SELECT ename,
sal,
DECODE(comm,NULL,'NO',
'YES') COMM
FROM emp;
USING CASE:
SELECT ename,
sal,
CASE comm
WHEN NULL THEN 'NO'
ELSE 'YES'
END
FROM emp;
DECODE is returning actual data(comm is NO where comm is null and comm is YES where comm is not null). Where as CASE is retunring YES for all employees commission even comm is null..
I am not able to understand where I was wrong.
Can any one help me out?
Thanks
Rajesh
Hi Rajesh,
I tried to solve your query this way, check if it serves the purpose
/***Using Decode***/
SELECT EMPLOYEE_ID, DECODE(NVL(COMMISSION_PCT, 0), 0, 'NO', 'YES')
FROM EMPLOYEES
/****Using Case***/
SELECT EMPLOYEE_ID, CASE NVL(COMMISSION_PCT, 0)
WHEN 0 THEN 'NO'
ELSE 'YES'
END CASE
FROM EMPLOYEES
/
Similar Messages
-
Difference between CASE and DECODE
Hi All,
Could you please explain me the basic differences between the CASE and DECODE, which performs fast...?
DECODE is Oracle one, and the CASE is ANSI standard.
As per my knowledge, CASE is a statement and DECODE is a function which was defined in the Standard package.
If we use DECODE, the package has to load first, so it will take a little longer than the CASE. CASE is a simple statement which is ANSI standard.
We can use the CASE in the where clause and can not use the DECODE in the where clause.
Please clarify me and correct me if anything wrong.
Thanks,IMO, the main important point is the way CASE and DECODE handles NULL
SQL> select ename,comm,
2 decode(comm,300,'A',null,'B','C') dcd,
3 case comm when 300 then 'A'
4 when null then 'B'
5 else 'C'
6 end cs
7 from emp;
ENAME COMM D C
SMITH B C --"DECODE treats NULL=NULL. But for CASE, NULL is not equal to "another" NULL
ALLEN 300 A A
WARD 500 C C
JONES B C
MARTIN 1400 C C
BLAKE B C
CLARK B C
SCOTT B C
KING B C
TURNER 0 C C
ADAMS B C
JAMES B C
FORD B C
MILLER B C
14 rows selected.
{code}
Edited by: jeneesh on Jun 3, 2013 1:13 PM
Note: in CASE, you should use IS NULL
{code}
case when comm=300 then 'A'
when comm is null then 'B'
else 'C'
end
{code} -
Hi,
I am running below statement.
create table test_abc
(cnt number,
outcome varchar2(20));
insert into test_abc values(1,'EXISTINGDOMFUELCUST');
insert into test_abc values(1,'Answer Phone');
insert into test_abc values(1,'Answer Phone');
insert into test_abc values(1,'Answer Phone');
insert into test_abc values(1,'Answer Phone');
insert into test_abc values(1,'Answer Phone');
commit;
Now I used case and decode
select count(*),ot from (
select (case when outcome ='EXISTINGDOMFUELCUST' then 'Existing Domestic Fuel Customer'
when outcome='Answer Phone' then 'Answer Phone'
when outcome='Answer Phone' then 'Answer Machine' end) ot
from test_abc)
group by ot;
select count(*),decode(outcome,'EXISTINGDOMFUELCUST','Existing Domestic Fuel Customer','Answer Phone',
'Answer Phone','Answer Phone','Answer Machine')
from test_abc
group by decode(outcome,'EXISTINGDOMFUELCUST','Existing Domestic Fuel Customer','Answer Phone',
'Answer Phone','Answer Phone','Answer Machine')
and getting same output
cnt ot
5 Answer Phone
1 Existing Domestic Fuel Customer
but I want output should be
cnt ot
5 Answer Phone
5 Answer Machine
1 Existing Domestic Fuel Customer
please suggestIndra Budiantho wrote:
/* Formatted on 8/28/2012 3:10:28 PM (QP5 v5.139.911.3011) */
SELECT CASE
WHEN outcome = 'EXISTINGDOMFUELCUST'
THEN
'Existing Domestic Fuel Customer'
WHEN outcome = 'Answer Phone'
THEN
'Answer Phone'
END
outcome,
COUNT (*)
FROM test_abc
GROUP BY outcome
union
SELECT CASE
WHEN outcome = 'EXISTINGDOMFUELCUST'
THEN
'Existing Domestic Fuel Customer'
WHEN outcome = 'Answer Phone'
THEN
'Answer Machine'
END
outcome,
COUNT (*)
FROM test_abc
where outcome = 'Answer Phone'
GROUP BY outcomeo/p
Answer Machine 5
Answer Phone 5
Existing Domestic Fuel Customer 1This can be simplified..
Also, UNION will unnecessarily do a distinct operation.
SELECT CASE
WHEN outcome = 'EXISTINGDOMFUELCUST'
THEN
'Existing Domestic Fuel Customer'
WHEN outcome = 'Answer Phone'
THEN
'Answer Phone'
END
outcome,
COUNT (*)
FROM test_abc
GROUP BY outcome
union all
SELECT 'Answer Machine'
outcome,
COUNT (*)
FROM test_abc
where outcome = 'Answer Phone'
GROUP BY outcome -
Pls tell me difference between case and decode
Hi all
pls tell me difference between case and decode
regardsWell not entirely true when you consider working with
sign and decode together. Your example could be
written with decode and sign like this:
decode(sign(sal-1000),1,sal+comm,-1,sal,0)But the case expression reads more easily, I admit.Rob it was just example you considered it special case ,BTW can you do it for me by DECODE function.
SQL> SELECT sal,comm,CASE WHEN sal>1000 AND sal<1300 THEN sal+comm ELSE 0 END
2 FROM emp
3 /
SAL COMM CASEWHENSAL>1000ANDSAL<1300THENSAL+COMMELSE0END
5000 0
2850 0
2450 0
2975 0
1250 1400 2650
1600 300 0
1500 0 0
950 0
1250 500 1750
3000 0
800 0
SAL COMM CASEWHENSAL>1000ANDSAL<1300THENSAL+COMMELSE0END
3000 0
1100
1300 0
14 rows selected.Note for OP CASE can be used within PL/SQL witing ORACLE 9i or later release
but DECODE function can only be used within SQL.
Khurram -
How to use case and decode to extract the data
Hello PL/SQL Gurus,
I am using Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production version
I have a table in following format -
drop table TT2;
create table TT2(College, Class,gender,status,fees) as select
'IITB','MBA','M','P',255600 from dual union all select
'IITK','MTech','M','P',300000 from dual union all select
'IITD','MBA','F','P',450000 from dual union all select
'IITKH','MBA','F','P',350000 from dual union all select
'IITC','MTech','F','P',420000 from dual union all select
'IITB','MTech','M','P',185000 from dual union all select
'IITC','MTech','M','P',235000 from dual union all select
'IITD','MBA','F','F',175000 from dual union all select
'IITM','MBA','M','F',257000 from dual union all select
'IITKH','MTech','F','P',335000 from dual union all select
'IITD','MBA','F','P',540335 from dual union all select
'IITC','MBA','F','F',125089 from dual union all select
'IITD','MTech','M','P',290756 from dual union all select
'IITM','MBA','M','P',200000 from dual union all select
'IITKH','MBA','F','F',534990 from dual union all select
'IITD','MBA','F','P',221000 from dual ;some of the extraction conditions are as following -
CASE CONDITION
College in 'IITB' and status='P'- 'WestRegion Passed'
College in 'IITC' and status='P'- 'SouthRegion Passed'
College in 'IITD' and 'IITK' and status='P' and Gender='F' - 'NothRegion Female Passed'
College not in 'IITK' and status='F' - 'Ex Kanpur Failed'
Expected output -
Region Statnding Fees
WestRegion Passed 440460
SouthRegion Passed 655000
NothRegion Female Passed 1386335
Ex Kanpur Failed 1092079SQL Used
I am using the following query which only make sure of case but this is not how i want the output , if i try to use the case within decode then how to work on this -
SELECT (CASE WHEN College in ('IITB') and status='P' then sum(fees) else 0 end) WP,
(case when College in ('IITC') and status='P' then sum(fees) else 0 end) SP,
(case when College in ('IITD','IITK') and gender='F' and status='P' then sum(fees) else 0 end) NFP,
(case when College in ('IITK') and status='F' then sum(fees) else 0 end) ExKF
FROM
TT2
GROUP BY College, Class,gender,statususer555994 wrote:
Thank you so much jeneesh i am really thankful to you ...vov.
one more query in case if any of the selection don't have the output data , then values will be displayed like -One way..
with t as
--"Add all your descriptions
(select 'WestRegion Passed' region_standing from dual union all
select 'SouthRegion Passed' region_standing from dual union all
select 'NothRegion Female Passed' region_standing from dual union all
select 'Ex Kanpur Failed' region_standing from dual)
select region_standing,sum(fees) fees
from (
(SELECT CASE WHEN College in ('IITB') and status='P'
then 'WestRegion Passed'
when College in ('IITC') and status='P'
then 'SouthRegion Passed'
when College in ('IITD','IITK') and gender='F' and status='P'
then 'NothRegion Female Passed'
when College in ('IITK') and status='F'
then 'Ex Kanpur Failed'
else 'Others' end region_standing,
sum(fees) fees
FROM TT2
GROUP BY CASE WHEN College in ('IITB') and status='P'
then 'WestRegion Passed'
when College in ('IITC') and status='P'
then 'SouthRegion Passed'
when College in ('IITD','IITK') and gender='F' and status='P'
then 'NothRegion Female Passed'
when College in ('IITK') and status='F'
then 'Ex Kanpur Failed'
else 'Others' end
union all
select region_standing,0
from t
group by region_standing;
REGION_STANDING FEES
Others 2567835
NothRegion Female Passed 1211335
WestRegion Passed 440600
Ex Kanpur Failed 0
SouthRegion Passed 655000
{code}
Edited by: jeneesh on Nov 5, 2012 5:07 PM -
Hi all,
could anyone would be able to tell me which statement is faster among decode and case and why?
thanx
Newbieuser531731 wrote:
The difference is in the syntax, and case statement is standards compliance and decode function is a user defined function.I guess you mean: CASE is an ANSI standard, while DECODE is an Oracle Specific function -
Case and decode - nested functions
Can i use a case statement inside a decode or nvl2 function?
eg.
decode(col_a,'ABC',
case when col_b in (1,2) then 'CCC' else when col_b in (3,4,5) then 'XXX' end
, 'NA')
Can i use a function like this basically, can i nest a case statement within a decode or nvl2 function?
I have used nested decodes and nvls and nested case statements but not combined both so far.... so need an opinion...
Thanks.
Edited by: user254668 on Apr 30, 2010 1:35 PMuser254668 wrote:
Can i use a case statement inside a decode or nvl2 function? Absolutely. Just get rid of that else:
decode(col_a,'ABC',
case when col_b in (1,2) then 'CCC' when col_b in (3,4,5) then 'XXX' end
, 'NA') SY. -
CASE vs DECODE - CASE with SUM and All in Page Item is non aggregable
Hi,
I'm using Discoverer 9.0.4.
After switching calculations from DECODE to CASE
I found out that case gives a non aggregable result when using a Page Item and selecting <All>.
The calculations
(SUM x) / (SUM y)
or
(x SUM) / (y SUM)
where x and y are variables, work fine with page item <All>.
But for example:
CASE WHEN 1=2 THEN 1 ELSE (SUM x) / (SUM y) END
gives non-aggregable.
The same code works with DECODE:
DECODE(1,2,1,(SUM x) / (SUM y))
and is aggregable.
Does anyone know a reason or a way to make it work with CASE?
Thanks,
Joao Noronha
P.S.: I wanted <= comparisons and CASE is the best in simplicity,
but now I know I can do it with DECODE, still looking ok using LEAST instead of ABS of the difference.Hi there
I think therefore you have answered your own question and determined that using CASE in aggregations is not a good idea. I only threw out the two CASE options as ideas not as solutions, just in case (pardon the pun) one of these worked in your situation.
Your comment I must say that if it worked it would give a wrong result (the sum of the divisions is not the same as the division of the sums) may give the wrong answer in your case but may be correct in others. It just depends how the items in the folder have been set up. I agree though that SUM(x) / SUM(y) will more often than not give the right answer.
This discussion about DECODE vs CASE has been going on ever since Oracle introduced CASE as a means of placating a younger breed of user who needed an IF..THEN...ELSE construct and could not get their minds around the intricacies of DECODE. The DECODE is a much more reliable function than CASE because it has been around for a long time allowing Oracle plenty of opportunity to iron the bugs out of it. If I get a chance I will always use a DECODE whenever aggregations are required. However, when no aggregations are in use then I'll use CASE, simply because it's easier for users to work with.
Unfortunately, users need to work with aggregations and so I don't see any alternative to Plus users having to learn DECODE. Whenever I teach Plus I always teach the users both CASE and DECODE but point out that DECODE has fewer issues that CASE. Oh, and talking of issues, try getting the THEN and ELSE components to return a different datatype. CASE has a fit and will not compile.
Best wishes and glad you got your issue solved - you did right?
Regards
Michael -
What is the Optional(other than Case or Decode)
Hi friends,
i need to refer an image to the corresponding blob content in my report for each and every row. i tried with case or decode but it is helpless as the case and decode does not support BLOB format, instead what is the other optional i can use inorder to solve the problem
SELECT
decode(attachment,(select attachment from it_issues where lower(name) like '%txt%') ,
'<img src="#WORKSPACE_IMAGES#Notepad.jpg">',
(select attachment from it_issues where lower(name) like '%pdf%'),
'<img src="#WORKSPACE_IMAGES#Adobe pdf.bmp">',
(select attachment from it_issues where lower(name) like '%xls%'),
'<img src="#WORKSPACE_IMAGES#Excel.png">',
(select attachment from it_issues where lower(name) like '%html%'),
'<img src="#WORKSPACE_IMAGES#Html.bmp">',
(select attachment from it_issues where lower(name) like '%sql%'),
'<img src="#WORKSPACE_IMAGES#Notepad.jpg">',
(select attachment from it_issues where lower(name) like '%ppt%'),
'<img src="#WORKSPACE_IMAGES#powerpoint.jpg">',
(select attachment from it_issues where lower(name) like '%zip%'),
'<img src="#WORKSPACE_IMAGES#rar 02.bmp">',
(select attachment from it_issues where lower(name) like '%doc%'),
'<img src="#WORKSPACE_IMAGES#word.bmp">', null) Attachment
FROM it_issuesAbove is My code which is not sufficient to use, any replacement to it.. It will be very helpful for me
Regards,
MiniHi metzguar,
Thanks for the reply my image is stored in the attachment column but that image name is stored in filename column in my table, so i cannot refer attachment = txt, because the image name(txt)is stored in another column filename.
But i need to show the image icon in my attachment column where the image is storing. That is the problem for me.
Thanks
Regards,
Mini -
CASE or DECODE - what is faster?
when i use them in select clause with varchar2 or number datatype? (Oracle 10.2 EE)
regardsHi,
This helped me in understanding the difference between case and decode
Quoting from an expert amoungst experts Billy Verreynne. here is what he says:
From what i know, in case of multiple condition checking, Case is simpler to write when compared to Decode. Also Decode can not be used in PL/SQL code where as CASE is possible.
There is very little performance difference between CASE and DECODE on the same platform. One has to run 100's of 1000's of iterations to see a difference, and even then it is debatable of whether that difference is just due to the CASE vs DECODE.
There seems to be a difference in performance between CASE and DECODE depending on the type of CPU. On some CPU architecture a DECODE will seem to be just slightly faster. On others, the CASE will seem to be slightly faster.
The performance difference is so slight that it makes very little sense in using that as primary criteria for whether to use CASE or DECODE. So unless you're calling this statement from a very tight loop doing millions of iterations, the decision should rather be which one, CASE or DECODE, best suits the need.
Wrong 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.
Hope this helps and all credit goes to the expert billy.
Edited by: Kevin CK on Aug 5, 2010 4:07 PM
Edited by: Kevin CK on Aug 5, 2010 4:08 PM -
Case or decode in select statement for comparison
Hi,
How can I do a comparison
like
if sal < 50, output 1.1 * comm
if sal > 50 and < = 100 output 1.2 * comm
else output comm
in a single select statement.
I tried using case and decode but I am not sure how to use it in comparison operations.
Please helpuse the 'case' construct:
SELECT
NORMAL_FIELD
, (CASE
WHEN (SAL < 50) THEN 1.1 * COMM
WHEN (SAL > 50) AND (SAL <= 100) THEN 1.2 * COMM
ELSE COMM
END
) AS CALCULATED_COMM
FROM
TB_xxxx
WHERE xxxx
hope this helps -
I have a table with say a column named “COLOR” with 500 different values - lets say 3 of the values are red white and blue. There are 497 others
I want insert from table with the color column into another table named "OTHER"
But everytime I hit a blue, I want to insert red instead. All the other values stay the same as they are.
I've tried CASE and DECODE but it leaves me with nulls for the other 497 values. Is there a way to do this by saying only when I hit the blue, I want it to be red, without hardcoding all the other values? For example:
Insert into OTHER table
Select
COLUMN1,
COLUMN2,
COLUMN3,
COLOR (If color is blue, insert red – then let all other colors be what they are)
COLUMN5Hi,
Sure, use an ELSE clause:
CASE
WHEN color = 'blue' THEN 'red'
ELSE color
ENDor, if you prefer DECODE, pass an even number of arguments:
DECODE ( color
, 'blue' , 'red'
, color
)Either way, the expression returns 'red' when color is 'blue', and returns color itself in all other cases. -
Regarding case statement and decode function
Hi Experts,
I have question.....regarding case statement and decode statement....
Can you please explain me that which one will be efficient,to place in insert statement...
insert statement(
(case when ........then
case when ....then
else
end)
else
end)
or
insert statement(
case when.....then
decode(....)
else
end)
Can you people explain me which one is more efficient method?
Thanks in advance.......The are major differences to talk about in case of CASE vs DECODE, but performance wise both are pretty much the same.
Have a look at Tom's thread
Ask Tom &quot;better performance - case or decode&quot;
I would suggest to use CASE whenever possible. Don't worry about the performance part. -
Case statement and Decode function both are not working in Select cursor.
I have tried both the Case statement and Decode function in Select cursor, but both the things are not working. On the other hand both the things work in just select statement.
See the first column in select (PAR_FLAG), I need to have this evaluated along with other fields. Can you please suggest some thing to make this work. And also I would like to
know the reason why decode is not working, I heard some where Case statement do not work with 8i.
Author : Amit Juneja
Date : 06/20/2011
Description:
Updates the Diamond MEMBER_MASTER table with the values from
INC.MEM_NJ_HN_MEMBER_XREF table.
declare
rec_cnt number(12) := 0;
commit_cnt number(4) := 0;
cursor select_cur is
Select DECODE(1,
(Select 1
from hsd_prov_contract R
where R.seq_prov_id = PM.seq_prov_id
and R.line_of_business = H.line_of_business
and R.PCP_FLAG = 'Y'
and R.participation_flag = 'P'
and SYSDATE between R.EFFECTIVE_DATE AND
NVL(R.TERM_DATE,
TO_DATE('31-DEC-9999', 'DD-MON-YYYY'))),
'Y',
'N') PAR_FLAG,
H.SEQ_ELIG_HIST,
H.SEQ_MEMB_ID,
H.SEQ_SUBS_ID,
H.SUBSCRIBER_ID,
H.PERSON_NUMBER,
H.EFFECTIVE_DATE,
H.TERM_DATE,
H.TERM_REASON,
H.RELATIONSHIP_CODE,
H.SEQ_GROUP_ID,
H.PLAN_CODE,
H.LINE_OF_BUSINESS,
H.RIDER_CODE_1,
H.RIDER_CODE_2,
H.RIDER_CODE_3,
H.RIDER_CODE_4,
H.RIDER_CODE_5,
H.RIDER_CODE_6,
H.RIDER_CODE_7,
H.RIDER_CODE_8,
H.MEDICARE_STATUS_FLG,
H.OTHER_STATUS_FLAG,
H.HIRE_DATE,
H.ELIG_STATUS,
H.PREM_OVERRIDE_STEP,
H.PREM_OVERRIDE_AMT,
H.PREM_OVERRIDE_CODE,
H.SEQ_PROV_ID,
H.IPA_ID,
H.PANEL_ID,
H.SEQ_PROV_2_ID,
H.SECURITY_CODE,
H.INSERT_DATETIME,
H.INSERT_USER,
H.INSERT_PROCESS,
H.UPDATE_DATETIME,
H.UPDATE_USER,
H.UPDATE_PROCESS,
H.USER_DEFINED_1,
H.SALARY,
H.PEC_END_DATE,
H.REASON_CODE,
H.PEC_WAIVED,
H.BILL_EFFECTIVE_FROM_DATE,
H.BILLED_THRU_DATE,
H.PAID_THRU_DATE,
H.SUBSC_DEPT,
H.SUBSC_LOCATION,
H.USE_EFT_FLG,
H.BENEFIT_START_DATE,
H.SEQ_ENROLLMENT_RULE,
H.MCARE_RISK_ACCRETION_DATE,
H.MCARE_RISK_DELETION_DATE,
H.MCARE_RISK_REFUSED_DATE,
H.COMMENTS,
H.USER_DEFINED_2,
H.USER_DEFINED_3,
H.RATE_TYPE,
H.PCPAA_OCCURRED,
H.PRIVACY_ON,
H.PCP_CHANGE_REASON,
H.SITE_CODE,
H.SEQ_SITE_ADDRESS_ID,
PM.seq_prov_id rendered_prov
from hsd_member_elig_history H,
INC.PCP_REASSIGN_RPRT_DATA P,
hsd_prov_master PM
where P.subscriber_id = H.subscriber_id
and P.rendered_pcp = PM.provider_ID
and H.elig_status = 'Y'
and (H.term_date is NULL or H.term_date >= last_day(sysdate))
order by H.Seq_memb_id;
begin
for C in select_cur loop
rec_cnt := rec_cnt + 1;
update hsd_member_elig_history
set term_date = TRUNC(SYSDATE - 1),
term_reason = 'PCPTR',
update_datetime = SYSDATE,
update_user = USER,
update_process = 'TD33615'
where seq_elig_hist = C.seq_elig_hist
and seq_memb_id = C.seq_memb_id;
INSERT INTO HSD_MEMBER_ELIG_HISTORY
(SEQ_ELIG_HIST,
SEQ_MEMB_ID,
SEQ_SUBS_ID,
SUBSCRIBER_ID,
PERSON_NUMBER,
EFFECTIVE_DATE,
TERM_DATE,
TERM_REASON,
RELATIONSHIP_CODE,
SEQ_GROUP_ID,
PLAN_CODE,
LINE_OF_BUSINESS,
RIDER_CODE_1,
RIDER_CODE_2,
RIDER_CODE_3,
RIDER_CODE_4,
RIDER_CODE_5,
RIDER_CODE_6,
RIDER_CODE_7,
RIDER_CODE_8,
MEDICARE_STATUS_FLG,
OTHER_STATUS_FLAG,
HIRE_DATE,
ELIG_STATUS,
PREM_OVERRIDE_STEP,
PREM_OVERRIDE_AMT,
PREM_OVERRIDE_CODE,
SEQ_PROV_ID,
IPA_ID,
PANEL_ID,
SEQ_PROV_2_ID,
SECURITY_CODE,
INSERT_DATETIME,
INSERT_USER,
INSERT_PROCESS,
UPDATE_DATETIME,
UPDATE_USER,
UPDATE_PROCESS,
USER_DEFINED_1,
SALARY,
PEC_END_DATE,
REASON_CODE,
PEC_WAIVED,
BILL_EFFECTIVE_FROM_DATE,
BILLED_THRU_DATE,
PAID_THRU_DATE,
SUBSC_DEPT,
SUBSC_LOCATION,
USE_EFT_FLG,
BENEFIT_START_DATE,
SEQ_ENROLLMENT_RULE,
MCARE_RISK_ACCRETION_DATE,
MCARE_RISK_DELETION_DATE,
MCARE_RISK_REFUSED_DATE,
COMMENTS,
USER_DEFINED_2,
USER_DEFINED_3,
RATE_TYPE,
PCPAA_OCCURRED,
PRIVACY_ON,
PCP_CHANGE_REASON,
SITE_CODE,
SEQ_SITE_ADDRESS_ID)
values
(hsd_seq_elig_hist.nextval,
C.SEQ_MEMB_ID,
C.SEQ_SUBS_ID,
C.SUBSCRIBER_ID,
C.PERSON_NUMBER,
trunc(SYSDATE),
C.TERM_DATE,
C.TERM_REASON,
C.RELATIONSHIP_CODE,
C.SEQ_GROUP_ID,
C.PLAN_CODE,
C.LINE_OF_BUSINESS,
C.RIDER_CODE_1,
C.RIDER_CODE_2,
C.RIDER_CODE_3,
C.RIDER_CODE_4,
C.RIDER_CODE_5,
C.RIDER_CODE_6,
C.RIDER_CODE_7,
C.RIDER_CODE_8,
C.MEDICARE_STATUS_FLG,
C.OTHER_STATUS_FLAG,
C.HIRE_DATE,
C.ELIG_STATUS,
C.PREM_OVERRIDE_STEP,
C.PREM_OVERRIDE_AMT,
C.PREM_OVERRIDE_CODE,
C.SEQ_PROV_ID,
C.IPA_ID,
C.PANEL_ID,
C.SEQ_PROV_2_ID,
C.SECURITY_CODE,
SYSDATE,
USER,
'TD33615',
SYSDATE,
USER,
'TD33615',
C.USER_DEFINED_1,
C.SALARY,
C.PEC_END_DATE,
C.REASON_CODE,
C.PEC_WAIVED,
C.BILL_EFFECTIVE_FROM_DATE,
C.BILLED_THRU_DATE,
C.PAID_THRU_DATE,
C.SUBSC_DEPT,
C.SUBSC_LOCATION,
C.USE_EFT_FLG,
C.BENEFIT_START_DATE,
C.SEQ_ENROLLMENT_RULE,
C.MCARE_RISK_ACCRETION_DATE,
C.MCARE_RISK_DELETION_DATE,
C.MCARE_RISK_REFUSED_DATE,
C.COMMENTS,
C.USER_DEFINED_2,
C.USER_DEFINED_3,
C.RATE_TYPE,
C.PCPAA_OCCURRED,
C.PRIVACY_ON,
C.PCP_CHANGE_REASON,
C.SITE_CODE,
C.SEQ_SITE_ADDRESS_ID);
commit_cnt := commit_cnt + 1;
if (commit_cnt = 1000) then
dbms_output.put_line('Committed updates for 1000 records.');
commit;
commit_cnt := 0;
end if;
end loop;
commit;
dbms_output.put_line('Total number of MEMBER_ELIG_HISTROY records inserted : ' ||
rec_cnt);
exception
when others then
raise_application_error(-20001,
'An error was encountered - ' || sqlcode ||
' -error- ' || sqlerrm);
end;user10305724 wrote:
I have tried both the Case statement and Decode function in Select cursor, but both the things are not working. Please define what you mean by not working even if your computer screen is near the internet we can't see it.
You should also look at the FAQ about how to ask a question
SQL and PL/SQL FAQ
Particularly *9) Formatting with {noformat}{noformat} Tags* and posting your version.
know the reason why decode is not working, I heard some where Case statement do not work with 8i.
Does this mean you are using 8i? Then scalar sub queries - selects within the select list, are not supported, along with CASE in PL/SQL.
Select DECODE(1,
* (Select 1
from hsd_prov_contract R
where R.seq_prov_id = PM.seq_prov_id
and R.line_of_business = H.line_of_business
and R.PCP_FLAG = 'Y'
and R.participation_flag = 'P'
and SYSDATE between R.EFFECTIVE_DATE AND
NVL(R.TERM_DATE,
TO_DATE('31-DEC-9999', 'DD-MON-YYYY')))*,
'Y',
'N') PAR_FLAG,
>
exception
when others then
raise_application_error(-20001,
'An error was encountered - ' || sqlcode ||
' -error- ' || sqlerrm);
http://tkyte.blogspot.com/2008/01/why-do-people-do-this.html -
Sql query usig round and decode together
can i get one sql quer for returning whole number using round and decode function
eg:
the value 47
if value=47
then
the query should return 50
if the value =44
then
the quer should return 40
pls give me sql query for above example using round and decode function
Edited by: user11368167 on Jul 9, 2009 3:35 AMA wild guess. If you want the ROUND Function to work only when your column value is 44 or 47 then you could use something like:
SQL> WITH test_tab AS
2 (SELECT 44 col_1
3 FROM DUAL
4 UNION ALL
5 SELECT 15 col_1
6 FROM DUAL
7 UNION ALL
8 SELECT 47 col_1
9 FROM DUAL
10 UNION ALL
11 SELECT 45 col_1
12 FROM DUAL)
13 -- end of test data
14 SELECT col_1,
15 DECODE (col_1,
16 44, ROUND (col_1, -1),
17 47, ROUND (col_1, -1),
18 col_1
19 ) rounded_value
20 FROM test_tab
21 /
COL_1 ROUNDED_VALUE
44 40
15 15
47 50
45 45
4 rows selected.
SQL> CASE Statement can be used as well instead of DECODE.
Good Luck,
Regards,
Jo
Maybe you are looking for
-
How can I see a running balance of my itunes spending?
Is there any way I can see my running balance of what I have spent on my account? For example if I had £10 in my account and I bought one item at 99p it would show running balance history of £9.01.
-
Iphoto 9.1.5 crashes on start up - can someone help ?
Installed Ilife 11 on an Ilife 9 - installed all updates - up to 9.1.5 - meidathek was formatted seems to Iphoto 9.1.5 format than crashes - also a new library does not help - smae issue- Report as attached Thanks in advance - Michael Process:
-
Getting Started with EJB3 - Import issues
Hello, i have a question, in the following piece of code: package cart.client; import java.util.Iterator; import java.util.List; import javax.ejb.EJB; import cart.ejb.Cart; import cart.util.BookException; public class CartClient { @EJB() private stat
-
TS1702 How can i put gina back on my iphone
I had to up date my mac for emails and i was up dating my iphone so it was compatable to my compture and everything has work expect gina iphone
-
Hi, I have installed WDS service in my dell server windows 2008 server R2. I am using WDS server and Dhcp server in different machine.I have received error "PXE:E-61 Media test failure check cable ", when I trying to install OS from my WDS serve