Converting CASE st. to decode
Hi, I'm using Oracle 8.0.5, apparently it does not support the CASE function. SOmeone let me know if this is incorrect, but I can't get it to work.
My question is I'm trying to write a fairly simple decode or CASE statement that says,
SELECT e.poid_type,
et.*,
CASE WHEN et.rec_id = 840 AND e.poid_type = '/event/billing/cycle/forward/' THEN et.amount
ELSE 0
end cforward,
a.account_no
FROM ACCOUNT_T a, EVENT_T e, EVENT_TOTAL_T et
WHERE a.account_no = '0040' AND a.poid_id0=e.account_obj_id0
AND et.obj_id0(+)=e.poid_id0
AND et.rec_id = 840;
Here is my attempt at a decode statement, but it does not work.
DECODE(et.rec_id, 840,
DECODE(e.poid_type, '/event/billing/cycle/forward', et.amount, 0), 0) cycle_forward,
When I use this it prints all zero's.
Basically, what I am trying to do is say when event_total_t rec_id = 840, and event_t poid_type = '/event/billing/cycle/forward' then display the event_total_t amount. I want to do this in the select statement, without using a where clause.
Thanks for any help on this.
Your DECODE translation is fine, but you do want one more outer join indicator on your query:
AND et.rec_id (+)= 840
Similar Messages
-
How to convert the compund case statement into decode statement
(CASE
WHEN FRCST = 0 AND SALE = 0 THEN 'No transaction '
WHEN FRCST = 0 AND SALE <>0 THEN 'Sale ag. Nil Forecast : '||SALE||' Kgs'
WHEN FRCST<> 0 AND SALE = 0 THEN 'No Sale ag. Forecast : '||FRCST||' Kgs'
WHEN FRCST<>0 AND SALE<>0 AND DIFF=0 THEN 'No Variance'
ELSE TO_CHAR(ROUND((DIFF/FRCST),2))||'%'
END)VARIANCE
How to convert this tatement to decode statement ?
YogeshDecode(FRCST,0,DECODE(SALE,0,'nO TRANSACTION','SALE AGAINST NIL FORECAST'),DECODE(SALE,0,'NO SALE AGAINST FORECAST',
DECODE(|SALE-FORECAST|,0,'NO VARIANCE',TO_CHAR(ROUND((DIFF/FRCST),2))||'%')))As per me whole case can be replaced by above decode -
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 -
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. -
Lookup Code value switch automatically in case of same decode value
Hi,
We have create a simple Lookup type UDF on OIM user profile. The lookup value contains the different code value for same decode value like 1-->Project Manager, 2-->Project Manager, 3-->Project Manager. Now the issue is that if someone goes form the web console and edit the user (just click on edit and then save it back without making any change), this lookup field value switch to default code value for 'Project Manager'. Let's say if OIM internally assume 2 as default code value for 'Project Manager' (not sure how OIM maintains it internally), If we follow the edit process for a user who has '3' as code value then after save the value in the database change to '2'. The same happens for user with '1' as code value as well. Now mapping multiple code values to same decode is very common where you need to integrate OIM with legacy systems where multiple key values assigned to the Job title/positions with same description. Has anyone came across this scenerio in past and found any solution. Please help. We tried by using lookup querry as well but no luck. We are using 9102 BP02 OIM. ThanksFirst thing first
Why do you need 3 entries in the lookup for the same vaule? It's only a confusion to the end-user to select which one.
Now....
In case you have some compelling situation, just try to have some differentiation for the decode value; like 1~Project Manager, 2~Project Manager, 3~Project Manager. This way confusion may be obviated and so as the issue. -
Using CASE insted of DECODE in Control File
Hi,
I have seen a lot of examples of DECODE in a Control File. I know how to use DECODE, but I prefer CASE. Does anyone know, if it is allowed, and is the synatx the same as standard CASE statements. I am going to try it, but this is just so that I don't try all different variations and then find that it is not available.
Another thought is could you use an IN List Statement.
Something like IF :col1 IN('A', 'AB') THEN "wow".
I know the IN is going to be jsut a WISH...
--Thanks
Message was edited by:
pshah2kYep, here's an example:
LOAD DATA
INFILE '/home/ennisbi/DBLOAD/data/xxx_2000.csv'
APPEND INTO TABLE STG_VOLUME
FIELDS TERMINATED BY ','
TRAILING NULLCOLS
EFFECTIVE_DATE DATE "YYYYMM",
SSB_ID,
SEDOL_OR_CUSIP,
AVG_BID_ASK_SPREAD_DIV2,
AVG_SHARE_VOLUME,
ANNUALIZED_VOLATILITY "CASE WHEN :ANNUALIZED_VOLATILITY='NC' then 0 else TO_NUMBER(:ANNUALIZED_VOLATILITY) end" -
Help in changing plsql case when to decode
Hi,
Can anyone help me to change this sql for it to use decode function instead of case when? Below is the sql code
Thanks in advance.
SELECT
parts,
weeks,
SUM(qty) qty
FROM (
SELECT
CASE
WHEN ((is_tbd = 'yes' AND is_tbd_order = 'no') OR ex_fac_date > v_asofdate + 131) THEN 'tbd'
WHEN ex_fac_date BETWEEN v_asofdate - 1 AND v_asofdate + 5 AND is_tbd = 'no' THEN 'wk1'
WHEN ex_fac_date BETWEEN v_asofdate + 6 AND v_asofdate + 12 AND is_tbd = 'no' THEN 'wk2'
WHEN ex_fac_date BETWEEN v_asofdate + 13 AND v_asofdate + 19 AND is_tbd = 'no' THEN 'wk3'
WHEN ex_fac_date BETWEEN v_asofdate + 20 AND v_asofdate + 26 AND is_tbd = 'no' THEN 'wk4'
WHEN (ex_fac_date < v_asofdate - 1) AND is_tbd = 'no' THEN 'past_due'
END weeks,
ffdate,
parts,
SUM(qty) qty
FROM
delivery)I can't use case because my oracle is 8i,Please join 21st Century
Can you help me checnge this to if then elsif insteadSQL does does contain IF statement! -
How to convert case-sensitive to extended journal format
I have two apple computers (extended journal format) that have been backed up via a time capsule. I have just noticed that the TC is formatted as case-sensitive. I do not know why case-sensitive. In an effort to ensure consistency of file format then I seek to somehow remove case-sensitive formatting. I presume no/minimal underlying case-sensitivity issues within file names as source data is not formatted in case-sensitive manner.
I have tried SuperDuper to clone the TC to an external HDD but the application cloned the formatting in addition to the data.
I have attempted use of Disk Utility to copy content from source (TC) to destination (HDD) but this yielded error messages that noted different file format types.
It there a way to convert/remove case sensitive formatting from TC?
I appreciate that I could simply reformat TC to extended journal format but this would presumably erase all my backup data.
Any guidance most welcomed.RossM wrote:
So I guess my choice is to "leave well alone" as Pondini suggests and accept the fact that cloning TC onto HDD has now formatted my new HDD as case-sensititive.
Actually, you may have two choices, depending on how you're going to be backing-up to the new HD:
Your best bet, by far, is to back up to it directly, rather than connecting it to the TC. That's much faster and more reliable. If so:
* Leave the TC backups alone. Reformat the HD as case-ignorant and let Time Machine start fresh on it. You can always see and restore from the old ones via the Browse... option, per Time Machine - Frequently Asked Question #17.
* Format the HD as case-sensitive and copy the backups from the TC to it. But don't copy the whole sparse bundle; copy the Backups.backupdb folder from the sparse bundle to the top level of the HD. (Sparse bundles are used only for network backups.) See #18 in the FAQ; you'll need the 4th procedure (copy network backups to be used locally.
But if you're going to connect the HD to the TC and back up to it that way, it doesn't matter how you format the HD, since the backups must be in a sparse bundle, that has its own format. Two choices for that:
* Leave the TC backups alone. Connect the HD to the TC and select it as the TM destination, and Let Time Machine start fresh on it. You can always see and restore from the old ones via the Browse... option, as above. (There is a way to speed up the first backup; see the blue box in #Q2 of Using Time Machine with a Time Capsule.)
* Copy ("Archive") the TC's internal disk to the external HD, per the green box in #Q6 of the same article. Then select the external as your Time Machine destination via Time Machine Preferences.
Is this simply deferring a problem issue to another time (aagh)? Or to somehow try and remove this inconsistency and remove case-sensitive formatting from all tech items, even if this might mean reformatting and losing old backup data?
No. There's not really a problem, unless you change the case of file/folder names and try to restore the old ones to the same place via the TM browser, per the link in my earlier post. That's the only possible downside.
Does Time Machine require case-sensitive formatting on its destination drive?
No. It's the default, but case-ignorant is fine, unless you ever want to add a case-sensitive volume. Then you're in a pickle.
Or does Time Capsule only function witih case-sensitive formatting?
No. The TC's actual disk is case-ignorant; it's only the Time Machine sparse bundle that's case-sensitive by default.
The benefit of case-sensitive formatting as Apple default seems rather unclear to me
It's the default only for Time Machine backups. Everything else defaults to case-ignorant.
The advantage is, once you've been backing-up your internal HD for weeks, months, or years, and want to add a case-sensitive external HD to be backed-up, you can. If the backups are case-ignorant, you can't. -
Hi everybody,
I have column in Discoverer like this one shown bellow:
DECODE(Vrstapolise,1,'Aktivno',4,'Kapitalisano',3,DECODE(Stanjepreisteka,'Aktivno','Aktivno','Kapitalisano','Kapitalisano',NULL),NULL)
I want to make the same column with same functionality in OBI BMM. Is it possible? If it is possible, how to do that?
Thanks in advance.As Sai said use Case stmt, your code will something like this
Case Vrstapolise
When 1 then 'Aktivno'
When 4 then 'Kapitalisano'
When 3 then
Case Stanjepreisteka
when 'Aktivno' then 'Aktivno'
when 'Kapitalisano' then 'Kapitalisano'
else Null end
else Null End
Thanks,
Vino -
Hello,
I am used to using case within my select statements, I need to use decode if possible for this one. Its for a record group within in forms, and the case statement is not working. Could someone please help me write this with decode instead of case?
SELECT CASE
WHEN months_between(sysdate , c.birth_dt) BETWEEN 168 AND 216 THEN 1 --14 to 18
WHEN months_between(sysdate , c.birth_dt) BETWEEN 217 AND 252 THEN 2 --18 to 21
WHEN months_between(sysdate , c.birth_dt) BETWEEN 253 AND 780 THEN 3 --21 to 65
WHEN months_between(sysdate , c.birth_dt) > 780 then 4 --older than 65
ELSE NULL END
FROM mw_clients cThanks in advance!
Jim P.Below solution is very easy to write.
But I think that performance will be bad.Not really as dual is internal to the SQL engine so there's little difference between the two...
SQL> ed
Wrote file afiedt.buf
1 with mw_clients as (select add_months(sysdate,-200) as birth_dt from dual union
2 select add_months(sysdate,-220) from dual union
3 select add_months(sysdate,-400) from dual)
4 -- END OF TEST DATA
5 select 4+
6 decode(Least(months_between(sysdate , c.birth_dt),168),
7 168,decode(greatest(months_between(sysdate , c.birth_dt),216),
8 216,-3,0)
9 ,0)+
10 decode(Least(months_between(sysdate , c.birth_dt),217),
11 217,decode(greatest(months_between(sysdate , c.birth_dt),252),
12 252,-2,0)
13 ,0)+
14 decode(Least(months_between(sysdate , c.birth_dt),253),
15 253,decode(greatest(months_between(sysdate , c.birth_dt),780),
16 780,-1,0)
17 ,0) as result
18* from mw_clients c
SQL> /
RESULT
3
2
1
Elapsed: 00:00:00.01
Execution Plan
Plan hash value: 1277652150
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 3 | 27 | 9 (34)| 00:00:01 |
| 1 | VIEW | | 3 | 27 | 9 (34)| 00:00:01 |
| 2 | SORT UNIQUE | | 3 | | 9 (78)| 00:00:01 |
| 3 | UNION-ALL | | | | | |
| 4 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 5 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 6 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
Statistics
1 recursive calls
0 db block gets
0 consistent gets
0 physical reads
0 redo size
456 bytes sent via SQL*Net to client
396 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
3 rows processed
SQL>
SQL> ed
Wrote file afiedt.buf
1 with mw_clients as (select add_months(sysdate,-200) as birth_dt from dual union
2 select add_months(sysdate,-220) from dual union
3 select add_months(sysdate,-400) from dual)
4 -- END OF TEST DATA
5 select c.birth_dt,
6 (select 1 from dual where months_between(sysdate , c.birth_dt) BETWEEN 168 AND 216 union
7 select 2 from dual where months_between(sysdate , c.birth_dt) BETWEEN 217 AND 252 union
8 select 3 from dual where months_between(sysdate , c.birth_dt) BETWEEN 253 AND 780 union
9 select 4 from dual where months_between(sysdate , c.birth_dt) > 780
10 ) as result
11* from mw_clients c
SQL> /
BIRTH_DT RESULT
06/08/1974 10:15:39 3
06/08/1989 10:15:39 2
06/04/1991 10:15:39 1
Elapsed: 00:00:00.01
Execution Plan
Plan hash value: 706016619
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 3 | 27 | 9 (34)| 00:00:01 |
| 1 | SORT UNIQUE | | 4 | | 12 (84)| 00:00:01 |
| 2 | UNION-ALL | | | | | |
|* 3 | FILTER | | | | | |
| 4 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
|* 5 | FILTER | | | | | |
| 6 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
|* 7 | FILTER | | | | | |
| 8 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
|* 9 | FILTER | | | | | |
| 10 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 11 | VIEW | | 3 | 27 | 9 (34)| 00:00:01 |
| 12 | SORT UNIQUE | | 3 | | 9 (78)| 00:00:01 |
| 13 | UNION-ALL | | | | | |
| 14 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 15 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 16 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
Predicate Information (identified by operation id):
3 - filter(MONTHS_BETWEEN(SYSDATE@!,:B1)<=216 AND
MONTHS_BETWEEN(SYSDATE@!,:B2)>=168)
5 - filter(MONTHS_BETWEEN(SYSDATE@!,:B1)<=252 AND
MONTHS_BETWEEN(SYSDATE@!,:B2)>=217)
7 - filter(MONTHS_BETWEEN(SYSDATE@!,:B1)<=780 AND
MONTHS_BETWEEN(SYSDATE@!,:B2)>=253)
9 - filter(MONTHS_BETWEEN(SYSDATE@!,:B1)>780)
Statistics
1 recursive calls
0 db block gets
0 consistent gets
0 physical reads
0 redo size
538 bytes sent via SQL*Net to client
396 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
4 sorts (memory)
0 sorts (disk)
3 rows processed
SQL> ed -
Hi All,
I am trying to use a CASE logic inside a DECODE function while selecting data from a table. But unable to get the correct syntax. Is there something that I might be missing?
My snippet looks like -
SELECT DECODE(CASE WHEN COL2 > 10 THEN 'HIGH', WHEN COL2 < 10 THEN 'LOW' END RANGEVALUE, 'HIGH', 'YES','LOW','NO','N/A')
FROM TEST_TABLE;My table looks like -
TEST_TABLE
COL1 VARCHAR2(10),
COL2 NUMBER(8,0)Chaitanya wrote:
My snippet looks like -
SELECT DECODE(
CASE
WHEN COL2 > 10 THEN 'HIGH'
WHEN COL2 < 10 THEN 'LOW'
END,
'HIGH','YES',
'LOW','NO',
'N/A'
FROM TEST_TABLE
/But it is an overkill:
SELECT CASE
WHEN COL2 > 10 THEN 'YES'
WHEN COL2 < 10 THEN 'NO'
ELSE 'N/A'
END
FROM TEST_TABLE
/Or, if you wnat to use DECODE:
SELECT DECODE(
SIGN(COL2 - 10)
1,'YES'
-1,'NO',
'N/A'
FROM TEST_TABLE
/SY. -
With the help of the board I wrote a query using the DECODE function to display a full name correctly space with or without a middle name. Could I do that in a CASE statement? I am trying to come up with the best solution. I tried it but know I am missing something - here is what I have so far
Could I do it in a case statement? I am trying to think about the best way to approach this -
Here is what I wrote:
SELECT EMP_FNAME,
EMP_FNAME,
EMP_INITIAL,
CASE
WHEN EMP_INITIAL = null THEN
(EMP_FNAME||' '||EMP_LNAME)
ELSE CASE
WHEN EMP_INITIAL != null THEN
(EMP_FNAME||' '||EMP_INITIAL||' '||EMP_LNAME)
END
FROM EMPLOYEE
ORDER BY EMP_LNAME
I get this error - missing keyword
Any thoughts on how to correct this?SELECT (CASE WHEN EMP_INITIAL IS NULL THEN (EMP_FNAME||' '||EMP_LNAME)
WHEN EMP_INITIAL IS NOT NULL THEN (EMP_FNAME||' '||EMP_INITIAL||' '||EMP_LNAME) END
END) longName
FROM EMPLOYEE
ORDER BY EMP_LNAME -
Can't convert case after moving a GW SAN volume from NetWare
I have am just about done migrating my GroupWise 8.0.3 systems from NetWare to OES Linux and have saved my largest PO for last. This is the only PO using a SAN volume. My plan is to just move the volume from the NetWare box the my new Linux (OES) server.
To test this process:
- I created a new SAN volume on my NetWare box and made a copy of the post office.
- I moved the volume to my new Linux server.
- I ran nssmu on the Linux box and did a F4 Refresh eDirectory for the pool and volume.
All good so far. The pool and volume are accessible. When I run a dbcopy -l /<path to postoffice> to convert to lower case I get the following:
[272] Failed to rename file /media/nss/RESTORE/ZOOPO.BAK/offiles/fd12/50FFFDB7.00G to /media/nss/RESTORE/ZOOPO.BAK/offiles/fd12/50fffdb7.00g Error=8201
If I try to manually rename one of the upper case files it also fails:
zoo-msg3:/media/nss/RESTORE/ZOOPO.BAK # mv WPHOST.DB wphost.db
mv: `WPHOST.DB and `wphost.db are the same file
So is it the case that you dont need to do a case conversion if the post office and/or domain are on NSS volumes?MrSted <[email protected]> wrote:
> All good so far. The pool and volume are accessible. When I run a
> dbcopy -l /<path to postoffice> to convert to lower case I get the
> following:
>
In addition to what Massimo says about not really needing to rename the
files if you are on long namespace, the -l is a dangerous switch and
should rarely be used by a human.
http://www.caledonia.net/important-d...ercase-switch/
You actually ran it with the proper syntax. So you would not experience
data loss. But -l should be used with caution. And NEVER while the POA is
loaded. But it really should be run after the files are already the proper
case on the disk. Its real job is to make the guardian DB all lowercase and
only secondarily to attempt to rename files. I myself never use it to
attempt a file rename.
Personally I DO like to have the files all lowercase, even on NSS. You
never know when you need to pick up your data and stick it on a native
Linux volume. Search for chcase and there are a few windows utilities that
can do this for you. Just map a drive to the NSS volume. If you DO change
the case with a utility, then you can run the dbcopy -l but make sure the
POA is unloaded.
Danita - http://www.caledonia.net/register -
Help in to convert sql from CASE to DECODE in 11g
11gr2, Windows.
Can somebody help me out in re-writing below sql from CASE statement to DECODE ?
SELECT INVOICE_ID,sum(TOTAL_EXCL_VAT),LEVEL2 as descr,
sum(case when instr(LEVEL2,'Internet')>0 then SUM_QUANTITY else 0 end) as KB --- >> Here
from rator_cdr.INVOICE_DETAIL_LINE
WHERE INVOICE_ID ='000000000000000000' and CALLER='0000000000' and LEVEL1='Gesprekskosten'
group by LEVEL2,INVOICE_ID;ThanksThere is no difference in performance. CASE is a standard syntax that is relatively easy for any developer to read and follow. DECODE is an Oracle-specific function that is much less flexible (you can only use equality conditions, for example) and generally results in more cryptic code.
Justin -
What is the difference betwee decode & case function
Hi
What is the difference betwee decode & case function
1.decode can't used in pl/sql 1) case can be user
2.in decode we can't use (>,<,>=) 2) we can use
any other do u have....
thanks in advance....DECODE works with expressions which are scalar values.
CASE can work with predicates and subqueries in searchable form.
There is one more Important difference between CASE and DECODE
DECODE can be used Only inside SQL statement....
But CASE can be used any where even as a parameter of a function/procedure
Eg:-
SQL> create or replace procedure pro_01(n number) is
2 begin
3 dbms_output.put_line(' The number = '||n);
4 End;
5 /
Procedure created.
SQL> set serverout on
SQL> var a varchar2(5);
SQL> Begin
2 :a := 'ONE';
3 End;
4 /
PL/SQL procedure successfully completed.
SQL> Begin
2 pro_01(Decode(:a,'ONE',1,0));
3 End;
4 /
pro_01(Decode(:a,'ONE',1,0));
ERROR at line 2:
ORA-06550: line 2, column 9:
PLS-00204: function or pseudo-column 'DECODE' may be used inside a SQL
statement only
ORA-06550: line 2, column 2:
PL/SQL: Statement ignored
SQL> Begin
2 pro_01(case :a when 'ONE' then 1 else 0 end);
3 End;
4 /
The number = 1
PL/SQL procedure successfully completed.Message was edited by:
Avi
Message was edited by:
Avi
Maybe you are looking for
-
Trying to connect 2nd printer through Ethernet Port of AEX b/g
Hello all, Hello (maybe) Duane, I do have a 2nd Airport Express b/g on our home network, and have a normal laser printer running as a wireless bonjour printer through that 2nd AEX, which is set up as a remote base station. I do have the Ethernet port
-
Hi, I am trying to create playlist on itunes software using songs from my ipod? I can't seem to get the songs from my ipod to a playlist on my computer. Can anyone help? Thanks much, Brian
-
Getting snow leopard original dvd
Hey there. I have an old mid-2010 Macbook Pro 15" (Model MacBookPro6,2), that came with Snow Leopard preinstalled. Thing is that this particular machine is affected by the infamous Nvidia crash (example thread) leading to a really unstable system. Th
-
Unable to load swf files in flash
Hi, since creating all the animation in one flash file will produce a big file i tried to split and create small flash files and load these files in the main flash movie using the image and swf loader component. eg. main.swf, sub1.swf, sub2.swf. In t
-
Seperate MVT 521/522 from 201/202 to different number range of mate. doc
The requirement is to seperate movement type 521/522 and 201/202. SAP is set both the transaction/event type: WA. (GI, Transfer Posting,Other GR) Is there any way to seperate these two kinds of movement to different material document number range? I