Help with case statement
Can any one whats wrong in below sql....Error is missing expression ...?
SELECT CASE WHEN A.STG_RECEIVER_MODEL_COUNT = 0 THEN 'STAGING RECEIVER MODEL CAPABILITY CONSISTS OF 0 RECORDS'
WHEN A.STG_RECEIVER_MODEL_CAP > 0 THEN
CASE WHEN ( B.ERROR_COUNT_FOR_4 = 90 * ( A.STG_RECEIEVER_MODEL_CAP_COUNT / 100) ) THEN 'MORE WARNING ERRORS FOR STG_PACKAGE'
ELSE 'WARNING ERRORS ARE LESS THAN 90 PERCENT'
END CASE
END AS WARNING_COUNT
FROM
SELECT COUNT(*) AS STG_RECEIVER_MODEL_COUNT FROM STG_RECEIVER_MODEL_CAPABILITY
) A,
SELECT count(*)AS ERROR_COUNT_FOR_4 FROM STG_ERROR_DETAIL
WHERE ERROR_CAT_ID = 4
AND MAP_NAME = 'STG_RECEIVER_MODEL_CAPABILITY'
AND CREATE_DT = (SELECT CREATE_DATE FROM QA_CREATE_DATE)
) B
;
If you rewrite properly yourquery, it could be easier to find out the error :<br>
SELECT CASE WHEN A.STG_RECEIVER_MODEL_COUNT = 0
THEN 'STAGING RECEIVER MODEL CAPABILITY CONSISTS OF 0 RECORDS'
WHEN A.STG_RECEIVER_MODEL_CAP > 0
THEN CASE WHEN ( B.ERROR_COUNT_FOR_4 = 90 * ( A.STG_RECEIEVER_MODEL_CAP_COUNT / 100) )
THEN 'MORE WARNING ERRORS FOR STG_PACKAGE'
ELSE 'WARNING ERRORS ARE LESS THAN 90 PERCENT'
END <s>CASE</s>
END AS WARNING_COUNT
FROM (SELECT COUNT(*) AS STG_RECEIVER_MODEL_COUNT FROM STG_RECEIVER_MODEL_CAPABILITY) A,
(SELECT count(*)AS ERROR_COUNT_FOR_4
FROM STG_ERROR_DETAIL
WHERE ERROR_CAT_ID = 4
AND MAP_NAME = 'STG_RECEIVER_MODEL_CAPABILITY'
AND CREATE_DT = (SELECT CREATE_DATE FROM QA_CREATE_DATE)) B<br>
<br>
Nicolas.
Similar Messages
-
Need help on case statements to validate records
Hi Experts ,
My table :
seq_num
col2
col3
col4
1
A
12345
P
2
B
1
123%23
3
C
1
23AB
4
D
1
20131001
5
E
1
6
A
13245
Q
7
B
1
12345
8
C
2
1234*AB
9
D
5
20140112
10
E
1
00020
my output
seq_num
col2
col3
col4
Status
Reason
1
A
12345
P
Valid
2
B
1
123%23
invalid
Special Character for col4
3
C
1
23AB
Valid
4
D
1
20131001
Valid
5
E
1
invalid
null for col4
6
A
13245
Q
invalid
Invalid character col4 || invalid number for col3
7
B
1
12345
Valid
8
C
2
1234*AB
Invalid
Special Character col4 ||invalid col3
9
D
5
20140112
invalid
Future dates col4 ||invalid col3
10
E
1
00020
Valid
Sql :
with t as
( select 1 as seq_num,'A' as col2 ,12345 as col3 ,'P' as col4 from dual
union all
select 2 ,'B',1,'123%23' from dual
union all
select 3,'C',1,'23AB' from dual
union all
select 4,'D',1,'21-02-2013' from dual
union all
select 5,'E',1,null from dual
union all
select 6,'A,13245,'Q' from dual
union all
select 7,'B',1,12345 from dual
union all
select 8,'C',2,'1234*AB' from dual
union all
select 9,'D',5,'25-01-2014' from dual
union all
select 10,'E',1,20 from dual
I am applying rules on col3 and col4 for each records row-wise.
I need case statements to populate status and reason columns after applying below rules
Rules
Col3 :
For A record ,it should be 12345 always .
For B,C,D,E , record should be always 1
col4
For A record , it should be either P or R
No null values for all A, B,C,D,E records
for B record , it dont contain special charecters
for C RECORD , it dont contain special charecters
for D record ,it should not contain future dates (dates are in yyyymmdd format and less than sysdates are valid )
I have other columns as well ,as i not included here
.It would be great if you Could help on case statements
Thanks and Regards,
SumanthI've adjusted Gregs nice example a bit. This should work:
with w_base as (
select seq_num, col2, col3, col4,
case when (col2 = 'A' AND col3 = 12345 )
OR (col2 in ('B','C','D','E') AND col3 = 1)
then '' else '||invalid col3' end ||
case when (col2 = 'A' AND col4 not IN ( 'P', 'R' ) )
then '||invalid col4' else '' end ||
case when (col2 IN ( 'B', 'C' ) AND col4 != translate(col4, 'a!@#$%^*()','a') )
then '||special character for col4' else '' end ||
case when (col2 = 'D' AND col4 >= to_char(sysdate,'yyyymmdd') )
then '||future dates col4' else '' end
reason
from ( select 1 as seq_num, 'A' as col2, 12345 as col3, 'P' as col4 from dual union all
select 2, 'B', 1, '123%23' from dual union all
select 3, 'C', 1, '23AB' from dual union all
select 4, 'D', 1, '20130212' from dual union all
select 5, 'E', 1, null from dual union all
select 6, 'A', 13245, 'Q' from dual union all
select 7, 'B', 1, '12345' from dual union all
select 8, 'C', 2, '1234*AB' from dual union all
select 9, 'D', 5, '20140125' from dual union all
select 10, 'E', 1, '20' from dual )
Select seq_num, col2, col3, col4,
case when reason is null then 'Valid' else 'Invalid' end status,
substr(reason, 3 ) reason
from w_base
It returns
SEQ_NUM
COL2
COL3
COL4
STATUS
REASON
1
A
12345
P
Valid
2
B
1
123%23
Invalid
special character for col4
3
C
1
23AB
Valid
4
D
1
20130212
Valid
5
E
1
Valid
6
A
13245
Q
Invalid
invalid col3||invalid col4
7
B
1
12345
Valid
8
C
2
1234*AB
Invalid
invalid col3||special character for col4
9
D
5
20140125
Invalid
invalid col3||future dates col4
10
E
1
20
Valid
edited some bugs :) now it should be fine! really -
11g outer join with case statement - strange results.
Hello All,
I am experiencing a strange issues in 11g while using case statement.
I am not able to reproduce this using sample data. Not sure what is wrong.
I am not narrowing it to say the usage of case statemnt is giving wrong results, but that is my observation when I am doing trail and error testing.
Here are the details.
My Version
SQL> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE 11.2.0.2.0 Production
TNS for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
SQL> My Query
SELECT *
FROM (SELECT DISTINCT mf.schedule,
mf.cptcode,
NVL (mf.modifier, '00') modifier2,
CASE
WHEN mf.feetype = 'H'
AND mf.multiplier IS NOT NULL THEN
' 0.00'
WHEN (mf.feetype != 'H'
OR mf.feetype IS NULL)
AND mf.rbrvsvalue IS NOT NULL
AND mf.multiplier IS NOT NULL THEN
LPAD ( TRIM (TO_CHAR ( (mf.rbrvsvalue * mf.multiplier) / 100, 9999999.99)), 10)
ELSE
NULL
END
fee
FROM provider.mpifee mf, mpi_udffee.udffeeactivecptcodes vld
WHERE mf.schedule = 'SAPG1'
AND mf.cptcode = vld.cptcode
AND NVL (mf.modifier, 'NULL') = NVL (vld.modifier, 'NULL')) inline_fee,
(SELECT arc.schedule col1, arc.procedurecode col2, NVL (arc.modifier, '00') AS col3
FROM mpi_udffee.udffeeancfeedata arc
WHERE monthofextract = '201202'
AND arc.schedule = 'SAPG1'
AND TRUNC (SYSDATE - 10) BETWEEN arc.recordeffectivedate AND arc.recordterminationdate) inline_data
WHERE inline_fee.schedule = inline_data.col1(+)
AND inline_fee.cptcode = inline_data.col2(+)
AND inline_fee.modifier2 = inline_data.col3(+);
In the above query the inline view inline_data returns zero rows. but NVL is still getting applied for col3 and I am getting 00 in the results( strange ).
Results:
SCHEDULE CPTCO MODIFIER2 FEE COL1 COL2 COL3
SAPG1 49590 00 667.32 00
SAPG1 49611 00 781.03 00
SAPG1 49905 00 443.79 00
SAPG1 50205 00 883.56 00
SAPG1 50220 00 1315.15 00
SAPG1 50230 00 1638.74 00
SAPG1 50234 00 1666.16 00
SAPG1 50250 00 1566.14 00
SAPG1 50327 00 262.04 00
SAPG1 50541 00 1183.31 00
SAPG1 50620 00 1156.88 00
SAPG1 50650 00 1321.96 00
497 rows selected.
Just the inline view inline_data,
SQL> SELECT arc.schedule col1, arc.procedurecode col2, NVL (arc.modifier, '00') AS col3
2 FROM mpi_udffee.udffeeancfeedata arc
3 WHERE monthofextract = '201202'
4 AND arc.schedule = 'SAPG1'
5 AND TRUNC (SYSDATE - 10) BETWEEN arc.recordeffectivedate AND arc.recordterminationdate;
no rows selectedMuch unusual thing is when I just remove the case statement from the inline view "inline_fee", I am getting right results,
SELECT *
FROM (SELECT DISTINCT mf.schedule,
mf.cptcode,
NVL (mf.modifier, '00') modifier2 <-- Removed Case statement here
FROM provider.mpifee mf, mpi_udffee.udffeeactivecptcodes vld
WHERE mf.schedule = 'SAPG1'
AND mf.cptcode = vld.cptcode
AND NVL (mf.modifier, 'NULL') = NVL (vld.modifier, 'NULL')) inline_fee,
(SELECT arc.schedule col1, arc.procedurecode col2, NVL (arc.modifier, '00') AS col3
FROM mpi_udffee.udffeeancfeedata arc
WHERE monthofextract = '201202'
AND arc.schedule = 'SAPG1'
AND TRUNC (SYSDATE - 10) BETWEEN arc.recordeffectivedate AND arc.recordterminationdate) inline_data
WHERE inline_fee.schedule = inline_data.col1(+)
AND inline_fee.cptcode = inline_data.col2(+)
AND inline_fee.modifier2 = inline_data.col3(+);
SCHEDULE CPTCO MODIFIER2 COL1 COL2 COL3
SAPG1 46730 00
SAPG1 46735 00
SAPG1 46748 00
SAPG1 46760 00
SAPG1 46942 00
SAPG1 46945 00
SAPG1 47015 00
SAPG1 47125 00
SAPG1 47350 00
SAPG1 47505 00
SAPG1 47553 00interestingly explain plan for both the statements are exactly same,
SELECT STATEMENT ALL_ROWSCost: 138 Bytes: 1,078,274 Cardinality: 11,471
9 HASH JOIN RIGHT OUTER Cost: 138 Bytes: 1,078,274 Cardinality: 11,471
2 PARTITION RANGE EMPTY Cost: 2 Bytes: 150 Cardinality: 3
1 TABLE ACCESS FULL TABLE MPI_UDFFEE.UDFFEEANCFEEDATA Cost: 2 Bytes: 150 Cardinality: 3
8 VIEW MPI_UDFFEE. Cost: 135 Bytes: 504,724 Cardinality: 11,471
7 HASH UNIQUE Cost: 135 Bytes: 539,137 Cardinality: 11,471
6 HASH JOIN Cost: 134 Bytes: 539,137 Cardinality: 11,471
3 TABLE ACCESS FULL TABLE MPI_UDFFEE.UDFFEEACTIVECPTCODES Cost: 13 Bytes: 177,345 Cardinality: 25,335
5 PARTITION LIST SINGLE Cost: 120 Bytes: 600,600 Cardinality: 15,015 Partition #: 8
4 INDEX RANGE SCAN INDEX (UNIQUE) REPRICE.PK_MPIFEE Cost: 120 Bytes: 600,600 Cardinality: 15,015 Partition #: 9 Partitions accessed #11Is there anything wrong with the query? If not have anyone come across this issue or posted it as a bug or is there a patch?
Update:
when I set the parameter "_complex_view_merging"=false I am getting the right results even with case statement. But I don want to do some thing unsupported.
Are there any other viable solutions?
I appreciate the help.
Thanks,
G.
Edited by: Ganesh Srivatsav on Apr 10, 2012 12:37 PMHi Tubby,
Right, the query transformation is going wrong. Following is from trace,
SELECT "INLINE_FEE"."SCHEDULE" "SCHEDULE",
"INLINE_FEE"."CPTCODE" "CPTCODE",
"INLINE_FEE"."MODIFIER2" "MODIFIER2",
"INLINE_FEE"."FEE" "FEE",
"ARC"."SCHEDULE" "COL1",
"ARC"."PROCEDURECODE" "COL2",
CASE
WHEN "ARC".ROWID IS NOT NULL THEN NVL ("ARC"."MODIFIER", '00')
ELSE NULL
END
"COL3"
FROM (SELECT DISTINCT "MF"."SCHEDULE" "SCHEDULE",
"MF"."CPTCODE" "CPTCODE",
NVL ("MF"."MODIFIER", :B2) "MODIFIER2",
CASE
WHEN ("MF"."FEETYPE" = :B3
AND "MF"."MULTIPLIER" IS NOT NULL) THEN
:B4
WHEN ( ("MF"."FEETYPE" <> :B5
OR "MF"."FEETYPE" IS NULL)
AND "MF"."RBRVSVALUE" IS NOT NULL
AND "MF"."MULTIPLIER" IS NOT NULL) THEN
LPAD ( TRIM (TO_CHAR ( "MF"."RBRVSVALUE" * "MF"."MULTIPLIER" / :B6, :B7)), :B8)
ELSE
NULL
END
"FEE"
FROM "PROVIDER"."MPIFEE" "MF", "MPI_UDFFEE"."UDFFEEACTIVECPTCODES" "VLD"
WHERE "MF"."SCHEDULE" = 'SAPG1'
AND "MF"."CPTCODE" = "VLD"."CPTCODE"
AND NVL ("MF"."MODIFIER", 'NULL') = NVL ("VLD"."MODIFIER", 'NULL')) "INLINE_FEE",
"MPI_UDFFEE"."UDFFEEANCFEEDATA" "ARC"
WHERE "INLINE_FEE"."SCHEDULE" = "ARC"."SCHEDULE"(+)
AND "INLINE_FEE"."CPTCODE" = "ARC"."PROCEDURECODE"(+)
AND "INLINE_FEE"."MODIFIER2" = CASE
WHEN ("ARC".ROWID(+) IS NOT NULL) THEN NVL ("ARC"."MODIFIER"(+), '00')
ELSE NULL
END
AND "ARC"."MONTHOFEXTRACT"(+) = '201202'
AND "ARC"."SCHEDULE"(+) = 'SAPG1'
AND TRUNC (SYSDATE-10) >= "ARC"."RECORDEFFECTIVEDATE"(+)
AND TRUNC (SYSDATE-10) <= "ARC"."RECORDTERMINATIONDATE"(+)Does this refer to a specific bug?
Thanks,
G. -
Using Presentation variables..along with case statements..
Hi All.
I have a issue using presentation variable along with CASE statements. My approach is
1) I have a dashboard prompt, which is being set as Presentation variable.
Based on the value selected in prompt, for ex the values of prompt can be 'ABC' and 'DEF'.
I have a calculated column, the calculation goes this way...
The forumal is
CASE WHEN @{Presentation Variable Name} = 'ABC' THEN xxxxxxxxxx ELSE IF @{Presentation Variable Name} = 'DEF' END. It gives error of "no table being referenced"..
Is this is the right approach??
Can i get the values of variable in a column formula, so that a column can have values selected in prompt?
Can anybody pls help me here..
Thanks in advance...Hi
Thanks for the quick response..
I agree to ur point..
But the requirement is
Based on the value of the prompt I need to switch the calculation in one of the formula area of one column..
If Prompt value is ABC then one kind of calculation in Fx and If the prompt value is DEF then one kind of calculation in the same Fx..
How can I acheive this?
Thanks in advance.. -
Help with if statement in cursor and for loop to get output
I have the following cursor and and want to use if else statement to get the output. The cursor is working fine. What i need help with is how to use and if else statement to only get the folderrsn that have not been updated in the last 30 days. If you look at the talbe below my select statement is showing folderrs 291631 was updated only 4 days ago and folderrsn 322160 was also updated 4 days ago.
I do not want these two to appear in my result set. So i need to use if else so that my result only shows all folderrsn that havenot been updated in the last 30 days.
Here is my cursor:
/*Cursor for Email procedure. It is working Shows userid and the string
You need to update these folders*/
DECLARE
a_user varchar2(200) := null;
v_assigneduser varchar2(20);
v_folderrsn varchar2(200);
v_emailaddress varchar2(60);
v_subject varchar2(200);
Cursor c IS
SELECT assigneduser, vu.emailaddress, f.folderrsn, trunc(f.indate) AS "IN DATE",
MAX (trunc(fpa.attemptdate)) AS "LAST UPDATE",
trunc(sysdate) - MAX (trunc(fpa.attemptdate)) AS "DAYS PAST"
--MAX (TRUNC (fpa.attemptdate)) - TRUNC (f.indate) AS "NUMBER OF DAYS"
FROM folder f, folderprocess fp, validuser vu, folderprocessattempt fpa
WHERE f.foldertype = 'HJ'
AND f.statuscode NOT IN (20, 40)
AND f.folderrsn = fp.folderrsn
AND fp.processrsn = fpa.processrsn
AND vu.userid = fp.assigneduser
AND vu.statuscode = 1
GROUP BY assigneduser, vu.emailaddress, f.folderrsn, f.indate
ORDER BY fp.assigneduser;
BEGIN
FOR c1 IN c LOOP
IF (c1.assigneduser = v_assigneduser) THEN
dbms_output.put_line(' ' || c1.folderrsn);
else
dbms_output.put(c1.assigneduser ||': ' || 'Overdue Folders:You need to update these folders: Folderrsn: '||c1.folderrsn);
END IF;
a_user := c1.assigneduser;
v_assigneduser := c1.assigneduser;
v_folderrsn := c1.folderrsn;
v_emailaddress := c1.emailaddress;
v_subject := 'Subject: Project for';
END LOOP;
END;
The reason I have included the folowing table is that I want you to see the output from the select statement. that way you can help me do the if statement in the above cursor so that the result will look like this:
emailaddress
Subject: 'Project for ' || V_email || 'not updated in the last 30 days'
v_folderrsn
v_folderrsn
etc
[email protected]......
Subject: 'Project for: ' Jim...'not updated in the last 30 days'
284087
292709
[email protected].....
Subject: 'Project for: ' Kim...'not updated in the last 30 days'
185083
190121
190132
190133
190159
190237
284109
286647
294631
322922
[email protected]....
Subject: 'Project for: Joe...'not updated in the last 30 days'
183332
183336
[email protected]......
Subject: 'Project for: Sam...'not updated in the last 30 days'
183876
183877
183879
183880
183881
183882
183883
183884
183886
183887
183888
This table is to shwo you the select statement output. I want to eliminnate the two days that that are less than 30 days since the last update in the last column.
Assigneduser....Email.........Folderrsn...........indate.............maxattemptdate...days past since last update
JIM......... jim@ aol.com.... 284087............. 9/28/2006.......10/5/2006...........690
JIM......... jim@ aol.com.... 292709............. 3/20/2007.......3/28/2007............516
KIM......... kim@ aol.com.... 185083............. 8/31/2004.......2/9/2006............. 928
KIM...........kim@ aol.com.... 190121............. 2/9/2006.........2/9/2006.............928
KIM...........kim@ aol.com.... 190132............. 2/9/2006.........2/9/2006.............928
KIM...........kim@ aol.com.... 190133............. 2/9/2006.........2/9/2006.............928
KIM...........kim@ aol.com.... 190159............. 2/13/2006.......2/14/2006............923
KIM...........kim@ aol.com.... 190237............. 2/23/2006.......2/23/2006............914
KIM...........kim@ aol.com.... 284109............. 9/28/2006.......9/28/2006............697
KIM...........kim@ aol.com.... 286647............. 11/7/2006.......12/5/2006............629
KIM...........kim@ aol.com.... 294631............. 4/2/2007.........3/4/2008.............174
KIM...........kim@ aol.com.... 322922............. 7/29/2008.......7/29/2008............27
JOE...........joe@ aol.com.... 183332............. 1/28/2004.......4/23/2004............1585
JOE...........joe@ aol.com.... 183336............. 1/28/2004.......3/9/2004.............1630
SAM...........sam@ aol.com....183876.............3/5/2004.........3/8/2004.............1631
SAM...........sam@ aol.com....183877.............3/5/2004.........3/8/2004.............1631
SAM...........sam@ aol.com....183879.............3/5/2004.........3/8/2004.............1631
SAM...........sam@ aol.com....183880.............3/5/2004.........3/8/2004.............1631
SAM...........sam@ aol.com....183881.............3/5/2004.........3/8/2004.............1631
SAM...........sam@ aol.com....183882.............3/5/2004.........3/8/2004.............1631
SAM...........sam@ aol.com....183883.............3/5/2004.........3/8/2004.............1631
SAM...........sam@ aol.com....183884.............3/5/2004.........3/8/2004............ 1631
SAM...........sam@ aol.com....183886.............3/5/2004.........3/8/2004............ 1631
SAM...........sam@ aol.com....183887.............3/5/2004.........3/8/2004............ 1631
SAM...........sam@ aol.com....183888.............3/5/2004.........3/8/2004............ 1631
PAT...........pat@ aol.com.....291630.............2/23/2007.......7/8/2008............ 48
PAT...........pat@ aol.com.....313990.............2/27/2008.......7/28/2008............28
NED...........ned@ aol.com.....190681.............4/4/2006........8/10/2006............746
NED...........ned@ aol.com......95467.............6/14/2006.......11/6/2006............658
NED...........ned@ aol.com......286688.............11/8/2006.......10/3/2007............327
NED...........ned@ aol.com.....291631.............2/23/2007.......8/21/2008............4
NED...........ned@ aol.com.....292111.............3/7/2007.........2/26/2008............181
NED...........ned@ aol.com.....292410.............3/15/2007.......7/22/2008............34
NED...........ned@ aol.com.....299410.............6/27/2007.......2/27/2008............180
NED...........ned@ aol.com.....303790.............9/19/2007.......9/19/2007............341
NED...........ned@ aol.com.....304268.............9/24/2007.......3/3/2008............ 175
NED...........ned@ aol.com.....308228.............12/6/2007.......12/6/2007............263
NED...........ned@ aol.com.....316689.............3/19/2008.......3/19/2008............159
NED...........ned@ aol.com.....316789.............3/20/2008.......3/20/2008............158
NED...........ned@ aol.com.....317528.............3/25/2008.......3/25/2008............153
NED...........ned@ aol.com.....321476.............6/4/2008.........6/17/2008............69
NED...........ned@ aol.com.....322160.............7/3/2008.........8/21/2008............4
MOE...........moe@ aol.com.....184169.............4/5/2004.......12/5/2006............629
[email protected]/27/2004.......3/8/2004............1631
How do I incorporate a if else statement in the above cursor so the two days less than 30 days since last update are not returned. I do not want to send email if the project have been updated within the last 30 days.
Edited by: user4653174 on Aug 25, 2008 2:40 PManalytical functions: http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/functions2a.htm#81409
CASE
http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96624/02_funds.htm#36899
http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96624/04_struc.htm#5997
Incorporating either of these into your query should assist you in returning the desired results. -
Hi All,
I have 2 tables like below. now i have a requirement which i need to do it in CASE OR DECODE. because i have to implement this logic IN SELECT STATEMENT for a column.
In table T1 if Lang = 1 and State = 'P' then display Lang = 'english' in table T2(which is Lang=2 in table T1) Or else display null.
Can we do this logic using CASE or DECODE? pls help
T1
Lang State
1 P
2 N
T2
Lang Dscr
1 central
2 englishSomething like this ?
SQL> ed
Wrote file afiedt.buf
1 WITH t1 AS (SELECT 1 lang, 'P' STATE FROM DUAL UNION ALL
2 SELECT 2 lang, 'N' STATE FROM DUAL
3 )
4 , t2 AS (SELECT 1 lang, 'central' dscr FROM DUAL UNION ALL
5 SELECT 2 lang, 'english' dscr FROM DUAL
6 )
7 SELECT t1.lang,t1.state,CASE
8 WHEN t1.lang=1 AND t1.state='P'
9 THEN (SELECT t2.lang FROM t2 WHERE dscr='english')
10 ELSE NULL
11 END "lang"
12* FROM t1
SQL> /
LANG S lang
1 P 2
2 N -
Help with Switch statements using Enums?
Hello, i need help with writing switch statements involving enums. Researched a lot but still cant find desired answer so going to ask here. Ok i'll cut story short.
Im writing a calculator program. The main problem is writing code for controlling the engine of calculator which sequences of sum actions.
I have enum class on itself. Atm i think thats ok. I have another class - the engine which does the work.
I planned to have a switch statement which takes in parameter of a string n. This string n is received from the user interface when users press a button say; "1 + 2 = " which each time n should be "1", "+", "2" and "=" respectively.
My algorithm would be as follows checking if its a operator(+) a case carry out adding etc.. each case producing its own task. ( I know i can do it with many simple if..else but that is bad programming technique hence im not going down that route) So here the problem arises - i cant get the switch to successfully complete its task... How about look at my code to understand it better.
I have posted below all the relevant code i got so far, not including the swing codes because they are not needed here...
ValidOperators v;
public Calculator_Engine(ValidOperators v){
stack = new Stack(20);
//The creation of the stack...
this.v = v;
public void main_Engine(String n){
ValidOperators v = ValidOperators.numbers;
*vo = vo.valueOf(n);*
switch(v){
case Add: add(); break;
case Sub: sub(); break;
case Mul: Mul(); break;
case Div: Div(); break;
case Eq:sum = stack.sPop(); System.out.println("Sum= " + sum);
default: double number = Integer.parseInt(n);
numberPressed(number);
break;
//default meaning its number so pass it to a method to do a job
public enum ValidOperators {
Add("+"), Sub("-"), Mul("X"), Div("/"),
Eq("="), Numbers("?"); }
Notes*
It gives out error: "No enum const class ValidOperators.+" when i press button +.
It has nothing to do with listeners as it highlighted the error is coming from the line:switch(v){
I think i know where the problem is.. the line "vo = vo.valueOf(n);"
This line gets the string and store the enum as that value instead of Add, Sub etc... So how would i solve the problem?
But.. I dont know how to fix it. ANy help would be good
Need more info please ask!
Thanks in advance.demo:
import java.util.*;
public class EnumExample {
enum E {
STAR("*"), HASH("#");
private String symbol;
private static Map<String, E> map = new HashMap<String, E>();
static {
put(STAR);
put(HASH);
public String getSymbol() {
return symbol;
private E(String symbol) {
this.symbol = symbol;
private static void put(E e) {
map.put(e.getSymbol(), e);
public static E parse(String symbol) {
return map.get(symbol);
public static void main(String[] args) {
System.out.println(E.valueOf("STAR")); //succeeds
System.out.println(E.parse("*")); //succeeds
System.out.println(E.parse("STAR")); //fails: null
System.out.println(E.valueOf("*")); //fails: IllegalArgumentException
} -
Insert data with Case Statement
Good Morning,
I created table:
CREATE TABLE DWG_LOG
( DL_ID_PK NUMBER NOT NULL ENABLE,
DL_DRWNG_ID_FK"NUMBER,
DL_REQUESTOR VARCHAR2(400 BYTE),
DL_PHONE VARCHAR2(40 BYTE),
DL_DATE_COPIED DATE,
DL_APPROVER VARCHAR2(400 BYTE),
DL_NOTES VARCHAR2(100 BYTE),
DL_REQ_EMAIL VARCHAR2(60 BYTE),
DL_DATE_DUE DATE,
DL_PAST_DUE VARCHAR2(400 BYTE))
The goal is to populate the DL_PAST_DUE field with a 1 if the date is greater than 90 days else leave NULL. With the help of other more senior developers from OTN I have narrowed my logic to using a CASE Statement instead of a FUNCTION. Below is the projected CASE statement that I am trying to use:
DECLARE
v_copied_date DWG_LOG.DL_DATE_COPIED%TYPE;
v_curr_date SYSDATE;
BEGIN
SELECT DL_DATE_COPIED INTO v_copied_date
FROM DWG_LOG
CASE
WHEN (v_curr_date - v_copied_date) > 90 THEN
INSERT INTO DWG_LOG (DL_PAST_DUE) VALUES ('1');
ELSE
INSERT INTO DWG_LOG (DL_PAST_DUE) VALUES ('0');
END CASE;
END;
I am getting the following errors when I run this code in SQL*PLus:
ERROR at line 10:
ORA-06550: line 10, column 4:
PL/SQL: ORA-00933: SQL command not properly ended
ORA-06550: line 7, column 4:
PL/SQL: SQL Statement ignored
ORA-06550: line 12, column 4:
PLS-00103: Encountered the symbol "ELSE" when expecting one of the following:
begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimite
ORA-06550: line 14, column 8:
PLS-00103: Encountered the symbol "CASE" when expecting one of the following:
if
PLEASE, point me in the right direction I know my syntax is off I just don't know where. I will continue to research and refine my script.
HUMBLY SUBMITTED
MarkusI APOLOGIZE
Good Morning, I created table:
CREATE TABLE DWG_LOG (
DL_ID_PK NUMBER NOT NULL ENABLE,
DL_DRWNG_ID_FK"NUMBER,
DL_REQUESTOR VARCHAR2(400 BYTE),
DL_PHONE VARCHAR2(40 BYTE),
DL_DATE_COPIED DATE,
DL_APPROVER VARCHAR2(400 BYTE),
DL_NOTES VARCHAR2(100 BYTE),
DL_REQ_EMAIL VARCHAR2(60 BYTE),
DL_DATE_DUE DATE,
DL_PAST_DUE VARCHAR2(400 BYTE))
[pre/]
The goal is to populate the DL_PAST_DUE field with a 1 if the date is greater than 90 days else leave NULL. With the help of other more senior developers from OTN I have narrowed my logic to using a CASE Statement instead of a FUNCTION. Below is the projected CASE statement that I am trying to use:
DECLARE
v_copied_date DWG_LOG.DL_DATE_COPIED%TYPE;
v_curr_date SYSDATE;
BEGIN
SELECT DL_DATE_COPIED INTO v_copied_date
FROM DWG_LOG;
CASE
WHEN (v_curr_date - v_copied_date) > 90 THEN
INSERT INTO DWG_LOG (DL_PAST_DUE) VALUES ('1');
ELSE
INSERT INTO DWG_LOG (DL_PAST_DUE) VALUES ('0');
END CASE;
END;
I am getting the following errors when I run this code in SQL*PLus: ERROR at line 10: ORA-06550: line 10, column 4: PL/SQL: ORA-00933: SQL command not properly ended ORA-06550: line 7, column 4: PL/SQL: SQL Statement ignored ORA-06550: line 12, column 4: PLS-00103: Encountered the symbol "ELSE" when expecting one of the following: begin case declare end exception exit for goto if loop mod null pragma raise return select update while with <an identifier> <a double-quoted delimite ORA-06550: line 14, column 8:
PLS-00103: Encountered the symbol “CASE” when expecting one of the following:
if -
100*ifnull(x,1)/case when ifnull(yagox,1)=0 then 1 else yagox end)
based on above condition my result should be like below
99.8
101.1
99.4
97.7
Current displaying result like below
99.8
1,22,345,000
99.4
97.7
2,34,567,400
i need to display those two values also in %
it may be happen denominater(yagox value is 1)
could please give the proper case statement for resolving the issue
betham
Edited by: 961992 on Oct 22, 2012 10:15 PMDear betham,
welcome to the forum, could you please share the table structure and some sample data and also what your select statement is. This will help people come up with solution faster and also it would avoid going in loops. -
Hi,
First Special thanks to Kglad for the help with the AS1 to AS3 conversion.
I've been able to link up my buttons to play a different frames of the movie. this was my novice way of finally getting the programming to work.
In frame 95 I have
var myLoader:Loader = new Loader();
addChild(myLoader); var url:URLRequest = new URLRequest("page1.swf");
myLoader.load(url);
in frame 165:
var myLoader1:Loader = new Loader();
addChild(myLoader1); var url1:URLRequest = new URLRequest("page1.swf");
myLoader1.load(url1);
My buttons link to 116 which plays a frame and loads ^
in frame 226: removeChild(myLoader).
But if the user has looped back into home from another part in the movie clip then it would need to remove myLoader1 instead of myLoader.
I'm guessing there is some really dynamic way to solve the programatic nightmare i'm developing, but I'm really novice.
So what i need is an if statement for frame 226
That would do something:
if(myLoader <> null
removeChild(myLoader)
else(
removechild(myLoader1)
Anyone have a method for this?yes, you can use the same urlrequest but just change its url property:
// initialize, for example in frame 1. this is done once and never again:
var loader:Loader=new Loader();
var urlR:URLRequest=new URLRequest();
// then in frame 2, for example:
urlR.url="page1.swf";
loader.load(urlR);
// in frame 20, for example:
urlR.url="page2.swf";
loader.load(urlR);
// in frame 30, for example:
urlR.url="page3.swf";
loader.load(urlR);
//etc. if you're loading any swfs that play streams (sound or video), you'll want to add some code to this. -
SQL Expression Field - Combine Declared Variable With Case Statement
Hello All, I have been using Crystal & Business Objects for a few months now and have figured out quite a bit on my own. This is the first real time I have struggled with something and while I could do this as a Formula Field I would like to know how to do this as a SQL Expression. Basically I want to create a SQL Expression that uses a CASE statement but I wanted to make the code a little more efficient and employ a variable to hold a string and then use the variable in the CASE statement. The expression editor accepts the CASE statement OK but I don't know how to declare the variable. Please assist with the syntax?
This is what I have:
CASE
WHEN u201CDatabaseu201D.u201DFieldu201D = u2018Hu2019 THEN u2018Hedgeu2019
WHEN u201CDatabaseu201D.u201DFieldu201D = u2018Pu2019 THEN u2018PVIu2019
ELSE u2018Noneu2019
END
This is what I want:
DECLARE strVar AS VARCHAR(25)
strVar = u201CDatabaseu201D.u201DFieldu201D
CASE
WHEN strVar = u2018Hu2019 THEN u2018Hedgeu2019
WHEN strVar = u2018Pu2019 THEN u2018PVIu2019
ELSE u2018Noneu2019
ENDHi Todd,
Please use the following for loop; your problem will be solved.
Local StringVar str := "";
Local NumberVar strLen := Length ({Database.Field});
Local NumberVar i;
For i := 1 To strLen Do
if {Database.Field} <i> = "H" then str := "Hedge"
else if {Database.Field} <i> = "P" then str := "PVI"
else str := "None"; exit for
str
Let me know once done!
Thank you,
Ashok -
I friends,
I am using a case statement for a number field like this
case when (customer_no is null or customer_no ='') then t.customer_no else gv.customer_no end as customer_no
When i complie this i get an errror ORa-00932 inconsistent data types expected char got number....
when i remove the case statement the query runs fine so i am sure its the case statement thats wrong here..Am i checking it the wrong way...
Thank you in advance874167 wrote:
I friends,
I am using a case statement for a number field like this
case when (customer_no is null or customer_no ='') then t.customer_no else gv.customer_no end as customer_no
When i complie this i get an errror ORa-00932 inconsistent data types expected char got number....
when i remove the case statement the query runs fine so i am sure its the case statement thats wrong here..Am i checking it the wrong way...
Thank you in advancewith Oracle strings are enclosed in single quote marks
so Oracle is confused & unhappy with line below
customer_no =''
since CUSTOMEER_NO is a NUMBER
why do you compare number to a string? -
CLOB with case statement not working getting error
Can anyone help on this
I write this sql
select Case when to_clob(PROPERTY) = 'is_intradesk=Y' then 'Internal' end
from JPM_CP;
Where PROPERTY column is clob column and its giving the error "ORA-00932: inconsistent datatypes: expected - got CLOB"
Is it not possible to use clob columns with case or decode !Its working but it does not fulfill my purpose
In you answer it is looking for position right! means, does the column contain the value('Intradesk=Y' ) or not. means
I am looking for exact match with CLOB column values, that is Clob column(PROPERTY) contains the exact value that value which I am comparing with i.e 'Intradesk=Y'
I need this
select * from table where clob_column = 'value' (exact).
Edited by: sajalkdas on Feb 4, 2011 3:28 PM -
Handling Exceptions with case statement - convert Exception to int value
Hi,
I'm developing a web app, with servlets.
I'm catching Exceptions in my servlets, for example I would like a user to insert data into a form. If the data cannot be converted into a integer value a java.lang.NumberormatException is thrown.
I would like to catch this and then create a message giving a more specific clue to what happened. Unfortunatly it's possible that other exceptions could be caught, so I want to be able to check which type of Exception has been caught.
I started writing a getErrorMessage(int Code) class. The method has a case statement which just checks the code and return the appropriate message.
This worked well for SQL exceptions as they provide a getErrorCode method. But I was wondering is there any way to convert other Exceptions such as
java.lang.NumberormatException into an integer value?
CheersExceptions have their types (classes) and messages (and maybe an embedded exception). That is, they have much richer internal status then an integer.
Why should they be "converted" to integers?
FLAME on
Gone are the days of good old errno.
FLAME off -
How to use Substring function with Case statement.
Hello Everyone,
I have one requirement where I have to use substring function on the field for report criteria.
E.G.
I have Branch Name Field where I have all branch names information, Now some of the branch names are too big with some extension after the name .
now i want to substing it but the character length varies for each branch.
so is there any way where we can use case statement where we can define that if branch name character are exceeding some value then substing it with this length.Try something like this:
CASE WHEN LENGTH(tablename.Branch_Name) > n THEN SUBSTRING(...) ELSE tablename.Branch_Name END
where n is the number of characters you want to start the break.
Maybe you are looking for
-
My Itunes won't open after a failed attempt at upgrading.
My ITunes won't open after a failed attempt at upgrading. Keep getting the error message...Failed to start because MSVCR80.dll was not found. I have tried uninstalling and reinstalling and notheing works. Help!
-
Is anyone aware of functionality, that would allow us to group a list of NB purchase orders, onto one document, before transmitting to the vendor? We have common purchasing orgs and purchasing groups, across multiple company codes. We would like to g
-
Thunderbolt dock fails to initialize video after update
Yosemite continues to be the buggiest OS X upgrade I've used in quite some time, if not ever. After this most recent update my 2560x1440 display does not come up when I get to the office and plug in my 2012 Macbook Pro Retina and Belkin's original Th
-
How to attach a smartform in to an e-mail
Hi All, My scenario is i wants to send a quotation details to customer for acceptance for this i prepared a smartform which contains quotation details. I wants to send this information to Customer for this i created a Outgoing email activity can
-
Modify control record and send out to external (TAMA) system using ALE
Hi All, I have a scenario to send idoc from ECC 5.0 to 3.1R/3 and then to TAMA system (external system-through TRFC) In the inbound process code of 3.1R/3, I have to write a custom FM to modify the control record and point to TAMA system and then sen