Update with case statement problem.
Hi,
I have this statement
update tab_tr set col_rate =
case
when col_ern_type in ('031','035','036') then (1.5 * col_rate)
when col_ern_type in ('041','045','046') then (2 * col_rate)
end;this statement updated some 2 million rows in the table tab_tr. But the total count of rows for col_ern_type in ('031','035','036', '041','045','046') yeild only around 222642 rows.
select count(*) from tab_tr where col_ern_type in ('031','035','036', '041','045','046'); --> 222642 rowswhat is the problem with the above update statement.
Thank you,
Hi,
DBA_1976 wrote:
... I thought the case statement conditions are counted as the where condition. But ......A CASE expression just takes the place of some other expression, such as a literal, a function, or a column.
For example, which rows do you think this should update?
UPDATE tab_tr
SET col_rate = 100;It would update all rows, of course.
How about this statement?
UPDATE tab_tr
SET col_rate = column_x;Will it only change the rows where column_x are a certain value, or not NULL, or in any way depend on column_x? No, of course not. It will update all rows.
How about this statement?
UPDATE tab_tr
SET col_rate = function_y (col_ern_type);Will it only change the rows where the fucntion returns a certain value? Will it depend on the value in col_ern_type? No, of course not. It calls the function for each row, and whatever the function returns (even if the function returns NULL), that's what goes into col_rate on each row.
A CASE expression is just something that you can substitute in place of any other expression, such as the literal 100, or the column column_x, or the function function_y in the statements above. Naturally, the value that gets put into col_rate will depend on what the CASE expression returns, but the behavior of the UPDATE statement as a whole will not.
Similar Messages
-
Hello,
I want to use case in update statement.
For example I have a table whose name is Item. There are 20 fields in this table. StockHoldType, Quantity and Amount are three of them.
I want to update quantity or amount fields according to stockholdtype fields value. If stockholdtype is 1 , I will update quantity field,
if stockholdtype field is 2 I will update amount field.
How can I do this?upadte table_name
set Quantity = decode(stockholdtype,1,+new_value+,quantity),
amount = decode(stockholdtype,2,+new_value+,amount)
where stockholdtype in (1,2) -
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.. -
Update statement with case statement
Hi
The following code is thorwing an error like
=====CODE==========
BEGIN
UPDATE emp SET SAL = CASE
WHEN ENAME = 'SCOTT' THEN SAL = 300
ELSE NULL;
END CASE;
END;
=====ERROR=======
ORA-06550: line 3, column 32:
PL/SQL: ORA-00905: missing keyword
ORA-06550: line 2, column 2:
PL/SQL: SQL Statement ignored
ORA-06550: line 5, column 6:
PLS-00103: Encountered the symbol "CASE" when expecting one of the following:
; 1.
2. BEGIN
3. UPDATE emp SET SAL = CASE
4. WHEN ENAME = 'SCOTT' THEN SAL = 300
5. ELSE NULL;
Any suggession?
Regards
BalajiHi,
Yes you are right, but it is not working for the multiple case statement like the following code
BEGIN
UPDATE emp SET SAL = CASE
WHEN ENAME='JONES' THEN '4';
WHEN ENAME='BLAKE' THEN '5'
WHEN ENAME='CLARK' THEN '6'
WHEN ENAME='TURNER' THEN '7'
WHEN ENAME='MILLER' THEN '8'
WHEN ENAME='MARTIN' THEN '9'
WHEN ENAME='WARD' THEN '10'
WHEN ENAME='ADAMS' THEN '11'
WHEN ENAME='JAMES' THEN '12'
WHEN ENAME='SMITH' THEN '13'
ELSE NULL END;
END;
The above code show the following error
===========ERROR==========
ORA-06550: line 3, column 29:
PL/SQL: ORA-00905: missing keyword
ORA-06550: line 2, column 2:
PL/SQL: SQL Statement ignored
ORA-06550: line 4, column 2:
PLS-00103: Encountered the symbol "WHEN" 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
1. BEGIN
2. UPDATE emp SET SAL = CASE
3. WHEN ENAME='JONES' THEN '4';
4. WHEN ENAME='BLAKE' THEN '5'
5. WHEN ENAME='CLARK' THEN '6'
Regards
Balaji
Edited by: 904493 on Jan 13, 2012 4:18 AM -
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? -
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 -
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 -
Hi
I have two tables
employee
empid empname empaddress valid
Employeedetails
empid empname manager
I would like to validate empname from both the tables using case statement and empid as join and update 'valid' column in employee table to y/n.
Please help me with the syntaxHi,
Depending on your requirements:
UPDATE employee e
SET valid = (
SELECT CASE
WHEN COUNT (*) = 0
THEN 'n'
ELSE 'y'
END
FROM employeedetails
WHERE empname = e.empname
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.
If you're asking about a DML statement, such as UPDATE, the sample data will be the contents of the table(s) before the DML, and the results will be state of the changed table(s) when everything is finished.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
Case statement problems in oracle forms 6i
Hello,
Any one can help me that how to use case statment in Oracle forms 6i.
i have read one thread and there was no proper solution so could any one please let me know to use case statement.
Please also let me know which category i should search for FORMS 6i.
when i'm using below code with cursor then i'm getting error 103
database:=11g
application := forms 6i
operating system:= win Xp
code is given below :-
cursor c1 is
select nc.nomenclature_id,
nvl(nc.category_value, 0) master,
nvl(nc2.category_value, 0) case,
nvl(nc3.category_value, 0) bundle,
case
when nvl(nc.category_value, 0) > 0 and
nvl(nc2.category_value, 0) > 0 and
nvl(nc3.category_value, 0) > 0 then
'A' --All packouts Master, Case, Bundle
when nvl(nc.category_value, 0) > 0 and
nvl(nc2.category_value, 0) > 0 and
nvl(nc3.category_value, 0) = 0 then
'B' --Both Master and Case
when nvl(nc2.category_value, 0) = 0 and
nvl(nc3.category_value, 0) = 0 then
'C' --Master Case Only
else
'N'
end code
from nomn_category nc, --master case
(select nc2.nomenclature_id,
nc2.category_value
from nomn_category nc2
where nc2.category_id = '230732') nc2,
(select nc3.nomenclature_id,
nc3.category_value
from nomn_category nc3
where nc3.category_id = '236566') nc3
Edited by: Rahul on Feb 3, 2012 7:18 PM
Edited by: Rahul on Feb 3, 2012 7:20 PMhello Andreas,
It is ok but i dont have to use view there.
i need to use without view, because this code has to be use in FORMS6i.
But Forms6i doesn't support to case function. i'm newbie in Forms.
If you can convert to below bold one portion(case) into decode then please help me or
if you have any idea about Forms6i then please send me any link where is given explanation about excel report that how to make excel report through Forms6i step by step and that excel report should be generate on any dynamic path which is given by user:-
cursor c1 is
select nc.nomenclature_id,
nvl(nc.category_value, 0) master,
nvl(nc2.category_value, 0) case,
nvl(nc3.category_value, 0) bundle,
case
when nvl(nc.category_value, 0) > 0 and
nvl(nc2.category_value, 0) > 0 and
nvl(nc3.category_value, 0) > 0 then
*'A'*
when nvl(nc.category_value, 0) > 0 and
nvl(nc2.category_value, 0) > 0 and
nvl(nc3.category_value, 0) = 0 then
*'B' --Both Master and Case*
when nvl(nc2.category_value, 0) = 0 and
nvl(nc3.category_value, 0) = 0 then
*'C'*
else
*'N'*
end "code"
from nomn_category nc,
(select nc2.nomenclature_id,
nc2.category_value
from nomn_category nc2
where nc2.category_id = '230732') nc2,
(select nc3.nomenclature_id,
nc3.category_value
from nomn_category nc3
where nc3.category_id = '236566') nc3
thanks -
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 -
Hi All,
I am trying to come up with a case statement for the below provided sql but i am not able to do that can you guys help me out
(SELECT NO_OF_DAYS.id_person
FROM NO_OF_DAYS
WHERE NO_OF_DAYS.STATUS = 'Y'
AND NO_OF_DAYS.ID_PERSON = PERSON.ID_PERSON
HAVING (SUM( NO_OF_DAYS.DT_STAT_END
- NO_OF_DAYS.DT_STAT_START)) > 180)
the case statement i am trying to come up with is if the person status start - end date is greater than 180 days then 'y' else 'n' endHi.
If you have two tables: NO_OF_DAYS and PERSON and PERSON is a parent table of NO_OF_DAYS this could work:
WITH NO_OF_DAYS AS
SELECT 1 id_person,TO_DATE('2012-01-01','YYYY-MM-DD') DT_STAT_START, TO_DATE('2012-01-31','YYYY-MM-DD') DT_STAT_END,'Y' status FROM dual UNION
SELECT 1 id_person,TO_DATE('2012-02-01','YYYY-MM-DD') DT_STAT_START, TO_DATE('2012-02-20','YYYY-MM-DD') DT_STAT_END,'Y' status FROM dual UNION
SELECT 2 id_person,TO_DATE('2012-01-01','YYYY-MM-DD') DT_STAT_START, TO_DATE('2012-03-31','YYYY-MM-DD') DT_STAT_END,'Y' status FROM dual UNION
SELECT 2 id_person,TO_DATE('2012-04-01','YYYY-MM-DD') DT_STAT_START, TO_DATE('2012-10-01','YYYY-MM-DD') DT_STAT_END,'Y' status FROM dual
PERSON AS
SELECT 1 id_person FROM DUAL UNION
SELECT 2 id_person FROM DUAL
SELECT
NO_OF_DAYS.id_person,
CASE WHEN (SUM(NO_OF_DAYS.DT_STAT_END- NO_OF_DAYS.DT_STAT_START)) > 180 THEN 'Y'
ELSE 'N'
END y_n
FROM
NO_OF_DAYS,
PERSON
WHERE
NO_OF_DAYS.ID_PERSON = PERSON.ID_PERSON AND
NO_OF_DAYS.STATUS = 'Y'
GROUP BY NO_OF_DAYS.id_person;
--results
ID_PERSON Y_N
1 N
2 YHope this helps.
Regards. -
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. -
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. -
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
Maybe you are looking for
-
Error in a formula function (routine ROUTINE_0002 ), record 1
Dear Guru's I am trying to load data into a ODS and i am facing the following problem in the PSA maintance it self. *@5C@ Error in a formula function (routine ROUTINE_0002 ), record 1 RSAU 510 * So any one please give me some suggest
-
Help:Embedding flashapaper, resizing problem
I am working on a cd with interactive menus linked mostly to pdfs. I've converted the pdfs to swf thru flashpaper. I've embedded the file successfully into director. I need the swf to be 1024 x 768 at least but everytime i change the member property
-
Get the time stamp when the user is enabled in the report.
Hi, I need to create a report to show the list of user who has been enabled for a given period with time stamp. please suggest a way to achive that.. thanks....
-
Doubt in Regular Expressions : java.util.regex
I want to identify words starting with capital letters in a sentence and I want to replace the matched word with "#" added in front of it.... For example, if my input sentence is "Christopher Williams asked Mike Muller a question" my output should be
-
How do I get artwork into itunes, I have photes in iphoto but they will not transfer. The highlighting & get info stuff does not work or does changing the type of copy into itunes