Decode function involving 2 fields (urgent)
Hi .. I am trying to use the decode function involving 2 fields.
The query runs but does not produce the correct results. If
anyone knows, please reply .. Usually decode function involves
one column only but I have more
than one. The situation is : If ins_code = 2 or special_code =
MMI, put a 'Y', otherwise, it's a 'N'. Does anyone know how to
put this in a decode statement? Thanks
Thanks, Suresh ... but I have to put this condition using the
decode statement because that's how the rest of the program is
written. It's part of the script that I have to change. The
current statement is this: decode(ins_code, '2', 'Y', 'N'). I
have to change it to ins_code =2 or special_feature = MMI.
Please reply ... thanks a lot....
Similar Messages
-
hai all,
this is the query from robinson .....
I am trying to use decode function as below in PL/SQl..
DECODE(column1,a1,1,a2,2,a3,3,......a150,150,null)
i got a error as
---unhandled exception---
If this decode function is restricted to 120 values i get the
answer.
so i would like to know whether there is any restriction for the
number of arguments to be passed to the decode function.
I will be glad and grateful to receive a answer...for this query.
thanks in advance...
robinsonI'm not sure what is the limit for the decode function
arguments, but it certainly seems that you've reached it.
So, I'd recommend that you write a stored function that you will
call in your select. It should be like the following:
create
function f_decode (p in your_data_type) return your_ret_type
is
begin
if p=expr1 then
return value1;
elsif p=expr2 then
return value2;
elsif p=exprn then
return exprn;
else
return def_value;
end if;
Or, another way to handle it, even more graciously when the
number of possible values will vary pretty often may be to have
a table that you would join.
That's what I do when a have to deal with more than 10-20 values.
end; -
Decode (function) VERY URGENT ! ! !
Hi Folks,
Does any one know how can i use some thing like
if a < 25 then
else
end if;
using decode function.
Thanks in advance
D'SilvaYep use Decode in conjunction with
the sign() function.
Goes something like this...
Decode( Sign( a - 25 ),0, 'EQUAL',
1, 'GREATER',
-1, 'LESS' )
Hope this helps
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by D'Silva:
Hi Folks,
Does any one know how can i use some thing like
if a < 25 then
else
end if;
using decode function.
Thanks in advance
D'Silva<HR></BLOCKQUOTE>
null -
Using DECODE Function to change data
I am trying to use the Decode function in a SQL statement to find a field that has a specific type, and when it finds that type, I want to blank out the results in a different field.
For example:
DECODE(ADDR_TYPE,'HOME',PHONE='') HOME_PHONEsomething like:
SQL> with t as
2 (select 219 id,
3 'BUS' addr_type,
4 '505-555-5555' phone
5 from dual
6 union
7 select 219 id,
8 'HOME' addr_type,
9 null phone
10 from dual
11 union
12 select 220 id,
13 'BUS' addr_type,
14 '101-111-1111' phone
15 from dual
16 union
17 select 220 id,
18 'HOME' addr_type,
19 null phone
20 from dual
21 union
22 select 223 id,
23 'BUS' addr_type,
24 '202-222-2222' phone
25 from dual
26 union
27 select 224 id,
28 'HOME' addr_type,
29 '303-333-3333' phone
30 from dual
31 union
32 select 225 id,
33 'BUS' addr_type,
34 null phone
35 from dual
36 union
37 select 226 id,
38 'HOME' addr_type,
39 null phone
40 from dual)
41 select a.id,
42 a.addr_type,
43 decode(a.addr_type,'BUS',phone,null) phone
44 from (select id, addr_type, phone,
45 row_number() over (partition by id order by id, decode(addr_type,'BUS',1,2)) rn
46 from t) a
47 where a.rn = 1;
ID ADDR PHONE
219 BUS 505-555-5555
220 BUS 101-111-1111
223 BUS 202-222-2222
224 HOME
225 BUS
226 HOME
6 rows selected.
SQL> -
SQL*Loader and DECODE function
Hi All,
I am loading data from data files into oracle tables and while loading the data using SQL*Loader, the following requirement needs to be fulfilled.
1) If OQPR < 300, RB = $ 0-299, SC = "SC1"
2) If 300 < OQPR < 1200, RB = $ 300-1199, SC = "SC2"
3) If 1200 < OQPR < 3000, RB = $ 1200-2999, SC = "SC3"
4) If OQPR > 3000 USD, RB = > $3000, SC = "SC4"
Here OPQR is a field in the data file.
Can anyone suggest how do we handle this using DECODE function? Triggers and PL/SQL functions are not to be used.
TIA.
Regards,
Ravi.The following expression gives you different values for your different intervals and boundaries :
SIGN(:OQPR - 300) + SIGN(:OQPR - 1200) + SIGN(:OQPR - 3000) -
DECODE Function In Reports 3.0
Hi,
When I use the decode function in a query (Reports 3.0.5.8.0) I receive an error message "Bind Variable Does Not Exist" (ORA-1006). When I remove the decode function from the query, the query compiles fine. All table and column references are existing.
Also, the same query runs perfectly fine from SQL*Plus. The OS is Win 2000, SP2
Any idea if this is a bug? Is there any way out? Do get back as this is very urgent.
The database is Oracle 8i Ent, 8.1.7 on AIX 4.3
The query is as follows:
SELECT NAM_CMP , COD_CMP , COD_CMP_REG ,
DECODE(FLG_CMP_SHP,'Y','S/',' /') || DECODE(FLG_CMP_AGT,'Y','A/',' /') || DECODE(FLG_CMP_CNE,'Y','C',' ') TYPE ,
DES_ADD_STT , DES_ADD_PLC , DES_ADD_STA , DES_ADD_POS , COD_CTY , COD_cou_iso ,
DAT_LST_AST , DAT_LST_UPD,
cod_dcl_box_num, decode(cod_imp_chg_way,'C','CASH','CREDIT') cod_imp_chg_way,
decode(cod_imp_cre_way,'W','WEEKLY','F','FIFTEEN DAYS','M','MONTHLY', NULL) cod_imp_cre_way,
decode(flg_imp_prn_inv, 'N', null, flg_imp_prn_inv) flg_imp_prn_inv,
cod_bro_box_num, decode(cod_exp_chg_way,'C','CASH','CREDIT') cod_exp_chg_way,
decode(cod_exp_cre_way,'W','WEEKLY','F','FIFTEEN DAYS','M','MONTHLY', NULL) cod_exp_cre_way,
decode(flg_exp_prn_inv, 'N', null, flg_exp_prn_inv) flg_exp_prn_inv
FROM CMP
where dat_can is nullTry TO_CHAR(NULL) instead of NULL in all DECODE functions.
For example:
decode(cod_imp_cre_way,'W','WEEKLY','F','FIFTEEN DAYS','M','MONTHLY', TO_CHAR(NULL))
instead of:
decode(cod_imp_cre_way,'W','WEEKLY','F','FIFTEEN DAYS','M','MONTHLY', NULL). -
Type conflict when calling a function module (field length)
Dear All,
I am getting this following error while executing: Type conflict when calling a function module (field length)
This is piece of coding i have writern in my action button.
method SEARCH_MATERIAL .
data:
node_mat_input TYPE REF TO if_wd_context_node,
node_mat_output TYPE REF TO if_wd_context_node,
material TYPE BAPIMATDET-MATERIAL,
itab TYPE TABLE OF BAPIMATDOA.
node_mat_input = wd_context->get_child_node( 'NODE_MAT_INPUT' ).
node_mat_output = wd_context->get_child_node( 'NODE_MAT_OUTPUT' ).
node_mat_input->get_attribute( EXPORTING name = 'MATERIAL'
IMPORTING value = material ).
CALL FUNCTION 'BAPI_MATERIAL_GET_DETAIL'
EXPORTING
material = material
PLANT = plant
VALUATIONAREA =
VALUATIONTYPE =
MATERIAL_EVG =
IMPORTING
MATERIAL_GENERAL_DATA = itab
RETURN =
MATERIALPLANTDATA =
MATERIALVALUATIONDATA =
node_mat_output->bind_table( itab ).
endmethod.
Attributes are:
Node name = INPUT its structure is BAPIMATDET
INPUT attributes = MATERIAL of type BAPIMATDET-MATERIAL
Thanks,
Gopi.Hi Amit,
I have used service call to fetch records from that bapi..
The following is the code generated by service call:-
METHOD execute_bapi_material_get_deta .
declarations for context navigation
DATA:
node_bapi_material_get_de TYPE REF TO if_wd_context_node,
node_exporting TYPE REF TO if_wd_context_node,
node_material_general_dat TYPE REF TO if_wd_context_node,
node_importing TYPE REF TO if_wd_context_node,
lri_element TYPE REF TO if_wd_context_element.
declarations for fuba parameters
data:
stru_c_material_general_dat TYPE if_componentcontroller=>element_material_general_dat.
DATA:
attr_material TYPE bapimatdet-material,
attr_plant TYPE bapimatall-plant.
get all involved child nodes
node_bapi_material_get_de = wd_context->get_child_node( `BAPI_MATERIAL_GET_DE` ).
node_exporting = node_bapi_material_get_de->get_child_node( `EXPORTING` ).
node_material_general_dat = node_exporting->get_child_node( `MATERIAL_GENERAL_DAT` ).
node_importing = node_bapi_material_get_de->get_child_node( `IMPORTING` ).
get input from context
node_importing->get_attribute( EXPORTING name = `MATERIAL`
IMPORTING value = attr_material ).
node_importing->get_attribute( EXPORTING name = `PLANT`
IMPORTING value = attr_plant ).
the invocation - errors are always fatal !!!
CALL FUNCTION 'BAPI_MATERIAL_GET_DETAIL'
EXPORTING
material = attr_material
plant = attr_plant
" valuationarea = wd_This->Valuationarea
" valuationtype = wd_This->Valuationtype
" material_Evg = wd_This->Material_Evg
IMPORTING
material_general_data = stru_c_material_general_dat
" return = wd_This->Return
" materialplantdata = wd_This->Materialplantdata
" materialvaluationdata = wd_This->Materialvaluationdat
node_material_general_dat->bind_structure( stru_c_material_general_dat[] ).
ENDMETHOD.
but the problem is I am getting the following error while compiling...
" stru_c_materialplantdata " is not an internal table - the " OCCOURS n" specification is missing.
Thanks,
Gopi.
Edited by: Yegalaivan on Nov 18, 2009 8:30 AM -
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 -
Hi
I try to use decode function im the sqlldr control file it gives error
Token longer than max allowable length of 258 chars
is there is nay limitation for decode function
i am using the following decode in my control file , pls advise is there is any workaround for this
, this is the field what i am decoding in the controlfile
area position(46:47) char "decode(:key,'21','OH','22','OH','24','OH','25','OH','27','OH','29','OH','30','OH','31','OH','34','OH','35','OH','37','OH','38','OH','39','OH','41','OH','42','OH','43','OH','45','OH','47','OH','49','OH','50','OH','51','OH','54','OH','55','OH','57','OH','58','OH','59','OH',:area)"
rdshi
this is my control file
load
INFILE '/u05/insm1.txt'
append
into table t_psp
ptt position(17:33) char,
bra position(34:39) char "decode(:mbra,NULL,'XXXXXX',:bra)",
dpt position(40:41) char,
myear position(42:45) char,
area position(46:47) char "decode(:key,'21','OH','22','OH','24','OH','25','OH','27','OH','29','OH','30','OH','31','OH','34','OH','35','OH','37','OH','38','OH','39','OH','41','OH','42','OH','43','OH','45','OH','47','OH','49','OH','50','OH','51','OH','54','OH','55','OH','57','OH','58','OH','59','OH',:area)",
key position (50:51) char
rds -
Decode Function I asked this in the wrong section so I hope Im right now!
select
a11.SEQ_MEMB_ID,
a11.Auth_Number,
a11.Admit_Primary_Date,
a11.Reviewer,
Decode (a11.Reviewer,
CLC, '2',
HBR, '3',
RAB, '4')
a11.admit_primary_date
from windsoradm.auth_master a11;
I am trying to get if the Reviewer is CLC then they are code 2 HBR Code 3 etc and it does not work. I take out the decode function and the query works. I am getting ORA-00923 FROM KEYWORD NOT FOUND WHERE EXPECTED.Hi,
Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved.
Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
Simplify the problem as much as possible. Remove all tables and columns that play no role in this problem.
Always say which version of Oracle you're using.
This is the right forum for this question. Mark your question in the other forum {message:id=10266930} as "Answered", so people won't waste their time.
925518 wrote:
select
a11.SEQ_MEMB_ID,
a11.Auth_Number,
a11.Admit_Primary_Date,
a11.Reviewer,
Decode (a11.Reviewer,
CLC, '2',
HBR, '3',
RAB, '4')
a11.admit_primary_date
from windsoradm.auth_master a11;
I am trying to get if the Reviewer is CLC then they are code 2 HBR Code 3 etc and it does not work. I take out the decode function and the query works. I am getting ORA-00923 FROM KEYWORD NOT FOUND WHERE EXPECTED.That's the correct DECODE syntax, where CLC, HBR and RAB are columns, and you want to return a string (not a number) such as '2'.
If 'CLC', 'HBR' and 'RAB' are literal values, then enclose them in single-quotes. If you want to return a number, don't put it in quotes. (Anyhting inside single-quotes is a string literal.)
Perhaps you meant something like:
, DECODE ( a11.Reviewer
, 'CLC' , 1
, 'HBR' , 2
, 'RAB' , 3
) AS reviewer_codeThere's an error right after the DECODE. You can't use a11.admit_primary_date as a column alias. (This is probably what's causing the ORA-00923 error.) Either a11_admit_primary_date (with an underscore instead of a dot) or admit_primary_date would be okay. If a11.admit_priomary_date is the next column in the SELECT clause, put a comma befor it.
You need a FROM clause. -
Hi all,
I want to use decode function in RTF template.
I know i can use if statement to deal with it ,but if the conditions are over 3, if statement is not good choice.
Here is the if condition statement
<?if:answer='Y'?>Yes<?end if?> <?if:answer='N'?>No<?end if?>
how can i translate this if statement to use decode function
I tried to use the statement as below, but it doesn't work.
<?xdofx:decode(:answer,Y,'YES',N,'NO')?>
using this statement i got empty in this field.
I appreciate any responds, thanks in advance.
appcatHi,
it should work,coz there is no xsl equivalent for this function that i have seen on blogs,
the syntax that i have got it from other xmlp blogs, sounds like you put correct syntax, try to give multiple conditions to check the result
<?xdofx:decode(’xxx’,’bbb’,’ccc’,’xxx’,
’ddd’)?>
srinuk -
OWB3i - Validate with DECODE function
Hi,
in OWB 3i when I validate an expression defined inside an expression operator with DECODE() function (which is not include in default transformation) come this error:
Line 1, Col 1:
PLS-00204: function or pseudo-column 'DECODE' may be used inside a SQL statement only
but it seems only a warning because when i generate the scripts and run no other error happen and all works fine.
RegardsHi,
Welcome to the forum!
When you use a default value, the last argument to DECODE is the actual value you want as a default.
For example:
SELECT ename
, deptno
, DECODE ( deptno
, 30 , 'Sales'
, 'All others' -- Default value
) AS dname
FROM scott.emp
ORDER BY ename
;Output:
ENAME DEPTNO DNAME
ADAMS 20 All others
ALLEN 30 Sales
BLAKE 30 Sales
CLARK 10 All others
FORD 20 All others
JAMES 30 Sales
JONES 20 All others
KING 10 All others
MARTIN 30 Sales
MILLER 10 All others
SCOTT 20 All others
SMITH 20 All others
TURNER 30 Sales
WARD 30 Sales
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
If you can show the problem using commonly available tables (such as those in the scott schema) then you don't need to post any sample data; just the results and the explanation.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
I need help in decode function.
I have a scenario like if range is between 0 and 20 then display field,
if range is >20 and <40 then display field2,
if range is > 40 and <60 the display field 3
Can i do in decode ?Hi,
If you have to ask how to use DECODE, the answer is "Use CASE instead."
CASE
WHEN range_val BETWEEN 0
AND 20 THEN field
WHEN range_val BETWEEN 20
AND 40 THEN field2
WHEN range_val BETWEEN 40
AND 60 THEN field3
END "Range" is an Oracle keyword, so it's not a good idea to use it as a column name.
What do you want ot do if range_val is exactly 20 or 40?
The example above includes 20 in the 0-20 group, not the 20-40 group. That's because the WHEN clauses are evaluated in order. The condition "range_val BETWEEN 20 AND 40" would return TRUE for range_val=20, but that condition will only be evaluated if the earlier condition "range_val BETWEEN 0 AND 20" is not TRUE.
You can do this just using DECODE. The general way to check for ranges is to use the SIGN function to isolate one range, and a nested DECODE to test for the others. If the values are equally spaced, as in this example, you can get by with just FLOOR, or something similar.
Unless you're using Oracle 8.0 (or earlier) there is no reason to do this. -
Need help with DECODE function
Hello,
I am trying to use default within the decode function and every time I get a missing expression. I have searched everywhere and cant figure out what I'm doing wrong. Thanks
select decode (request_id,0,'No files found', DEFAULT)Hi,
Welcome to the forum!
When you use a default value, the last argument to DECODE is the actual value you want as a default.
For example:
SELECT ename
, deptno
, DECODE ( deptno
, 30 , 'Sales'
, 'All others' -- Default value
) AS dname
FROM scott.emp
ORDER BY ename
;Output:
ENAME DEPTNO DNAME
ADAMS 20 All others
ALLEN 30 Sales
BLAKE 30 Sales
CLARK 10 All others
FORD 20 All others
JAMES 30 Sales
JONES 20 All others
KING 10 All others
MARTIN 30 Sales
MILLER 10 All others
SCOTT 20 All others
SMITH 20 All others
TURNER 30 Sales
WARD 30 Sales
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
If you can show the problem using commonly available tables (such as those in the scott schema) then you don't need to post any sample data; just the results and the explanation.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
Can I use a group by on a decode?
I am using the sql below and get an error message when I
try to use the group by on a decode.
select decode(assignment.catcodeid,
'D', 'SERVICE REQUESTS AND MAINTENANCE',
'U', 'SERVICE REQUESTS AND MAINTENANCE',
'P', 'SERVICE REQUESTS AND MAINTENANCE',
'E', 'SERVICE REQUESTS AND MAINTENANCE',
'R', 'SERVICE REQUESTS AND MAINTENANCE',
'T', 'EDUCATION',
'O', 'OVERHEAD',
'L', 'UNPAID LEAVE',
'V', 'VACATION',
'S', 'SICK PAY',
'H', 'HOLIDAY',
'C', 'COMP TIME',
'UNKNOWN ACTIVITY') "ACTIVITY",
assignment.catcodeid, assignment.esthrs,
SUM(ASSIGNMENT.ESTHRS)
FROM ASSIGNMENT
GROUP BY ACTIVITY, catcodeid, esthrs
The error is
ORA-00904: "ACTIVITY": invalid identifier
It is understood that Activity is not a field
on the table.
But, is there a way that I can group by the result of
a decode function or what other method/advice I can use to
group by the result of this.
Thanks is advance.Hello
You just need to put the decode statement in the group by as well, you can't just use the alias...And if you just group by the catcodeid, you won't be putting all of the SERVICE REQUESTS AND MAINTENANCE rows together. But, because you are selecting the catcodeid aswell as decoding it, that will happen anyway.
HTH
Maybe you are looking for
-
Can no longer connect wirelessly to hub
Until today everything has been fine. Now I cannot connect wirelessly to my hub. I get connection time out messages. Sometimes my hub does not even show up in the list of available networks. I can connect to BT Fon though. I've tried re-booting both
-
Officejet Pro 8500 A909G Can't Scan to Network Folder - Install won't detect Printer
I have installed an 8500 on a wireless network. There are 2 PC's; 1 is XP Home, the other is XP Pro, both are Service Pack 3. The Router is a Linksys WRT54G2, Wireless adapters in both PC's are Linksys Wireless G - PCI cards. Both PC's are runnin
-
Why am I getting loads of emails from apple support
Why am I getting emails from Apple support discussions on all topics. I just had over 1300 emails. Also on my iPhone. Can anyone help? Thanks Ron
-
Concatenating to a variable more than once?
Is it possible to concat to the same variable more than once? For some reason I am thinking not. I have the following: declare v_sql VARCHAR2(2000); v_sql := 'Select blah balh Where myfield in ('; if v_show1 = 1 then v_sql := v_sql || '1,' end if; if
-
WRT54G v5/6--- the answer to d/c!!
DD-WRT v23 sp2 I went from being d/c every 1-3minutes to going over one day w/no disconnects!! I am using a v6 router, and have absolute stability and TONS of control... the setup of DD-WRT was not simple, so this will not be a viable solution for no