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?
Cheers

Exceptions 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

Similar Messages

  • 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 PM

    Hi 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.

  • SQL Exception with the message "executeQuery, Exception = null"

    Hi ,
    Iam getting an SQL Exception with the message "executeQuery, Exception = null". Other thing is, the SQLException.getErrorCode gives me 0. Below is the stack trace. Could you please help me, why Iam getting this message:
    com.ups.ops.dm.dao.DAOSevereDataBaseException: Return Code from Database :0
    at com.ups.ops.dm.dao.DAOAction.run(Unknown Source)
    at com.ups.ops.dm.dao.DAOAgent.doWork(Unknown Source)
    at com.ups.ops.dm.dao.service.DAOActionServiceModule.service(Unknown Source)
    at com.ups.ops.dm.command.CommandManager.doCommand(Unknown Source)
    at com.ups.ops.dm.dao.DataAcessObjectManager.execute(Unknown Source)
    at com.ups.ops.dm.edc.db.EDCDataAccessObjectManager.lookups(Unknown Source)
    at com.ups.ops.dm.edc.business.EDCVoidBusinessLogic.checkPackageScan(Unknown Source)
    at com.ups.ops.dm.edc.service.VoidShipmentServiceModule.service(Unknown Source)
    at com.ups.ops.dm.command.CommandManager.doCommand(Unknown Source)
    at com.ups.ops.dm.edc.service.OPLDRequestDispatcherServiceModule.dispatchCommandMessage(Unknown Source)
    at com.ups.ops.dm.edc.service.OPLDRequestDispatcherServiceModule.service(Unknown Source)
    at com.ups.ops.dm.command.CommandManager.doCommand(Unknown Source)
    at com.ups.ops.dm.edc.control.EDCReceiver.onReceive(Unknown Source)
    at com.ups.ops.dm.edc.receiver.OPLDReceiverMDB.onMessage(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor97.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocati
    on.java:187)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:
    154)
    at com.bea.core.repackaged.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.ja
    va:89)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:
    176)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInt
    erceptor.java:126)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterc
    eptor.java:114)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:
    176)
    at com.bea.core.repackaged.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
    at $Proxy67.onMessage(Unknown Source)
    at weblogic.ejb.container.internal.MDListener.execute(MDListener.java:466)
    at weblogic.ejb.container.internal.MDListener.transactionalOnMessage(MDListener.java:371)
    at weblogic.ejb.container.internal.NewJMSMessagePoller.processOneMessage(NewJMSMessagePoller.java:245)
    at weblogic.ejb.container.internal.NewJMSMessagePoller.run(NewJMSMessagePoller.java:121)
    at weblogic.ejb.container.internal.NewJMSMessagePoller.timerExpired(NewJMSMessagePoller.java:204)
    at weblogic.timers.internal.TimerImpl.run(TimerImpl.java:273)
    at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:516)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
    com.ups.ops.dm.dao.DAOSevereDataBaseException: Return Code from Database :0
    at com.ups.ops.dm.dao.DAOAction.run(Unknown Source)
    at com.ups.ops.dm.dao.DAOAgent.doWork(Unknown Source)
    at com.ups.ops.dm.dao.service.DAOActionServiceModule.service(Unknown Source)
    at com.ups.ops.dm.command.CommandManager.doCommand(Unknown Source)
    at com.ups.ops.dm.dao.DataAcessObjectManager.execute(Unknown Source)
    at com.ups.ops.dm.edc.db.EDCDataAccessObjectManager.lookups(Unknown Source)
    at com.ups.ops.dm.edc.business.EDCVoidBusinessLogic.checkPackageScan(Unknown Source)
    at com.ups.ops.dm.edc.service.VoidShipmentServiceModule.service(Unknown Source)
    at com.ups.ops.dm.command.CommandManager.doCommand(Unknown Source)
    at com.ups.ops.dm.edc.service.OPLDRequestDispatcherServiceModule.dispatchCommandMessage(Unknown Source)
    at com.ups.ops.dm.edc.service.OPLDRequestDispatcherServiceModule.service(Unknown Source)
    at com.ups.ops.dm.command.CommandManager.doCommand(Unknown Source)
    at com.ups.ops.dm.edc.control.EDCReceiver.onReceive(Unknown Source)
    at com.ups.ops.dm.edc.receiver.OPLDReceiverMDB.onMessage(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor97.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocati
    on.java:187)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:
    154)
    at com.bea.core.repackaged.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.ja
    va:89)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:
    176)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:
    176)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInt
    erceptor.java:126)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterc
    eptor.java:114)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:
    176)
    at com.bea.core.repackaged.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
    at $Proxy67.onMessage(Unknown Source)
    at weblogic.ejb.container.internal.MDListener.execute(MDListener.java:466)
    at weblogic.ejb.container.internal.MDListener.transactionalOnMessage(MDListener.java:371)
    at weblogic.ejb.container.internal.NewJMSMessagePoller.processOneMessage(NewJMSMessagePoller.java:245)
    at weblogic.ejb.container.internal.NewJMSMessagePoller.run(NewJMSMessagePoller.java:121)
    at weblogic.ejb.container.internal.NewJMSMessagePoller.timerExpired(NewJMSMessagePoller.java:204)
    at weblogic.timers.internal.TimerImpl.run(TimerImpl.java:273)
    at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:516)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)

    Could you please help me, why Iam getting this message:You have bug in your software

  • 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..

  • 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
    Markus

    I 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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • 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
    Balaji

    Hi,
    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

  • Code Error with Case Statement

    Hi everyone,
    I'm new to PL/SQL and APEX and I'm trying to get this code to work. It is supposed to insert an sysdate if the named fields are changed and then update the fields.
    This is the code:
    BEGIN
    SELECT ATS_CLS_NAME, ATS_CEL_NAME, ATS_END_DATE,
    CASE
    WHEN
    ATS_CLS_NAME <> :P6_ATS_CLS_NAME
    AND ATS_CLS_NAME <> :P6_ATS_CEL_NAME
    AND ATS_END_DATE is Null
    THEN
    UPDATE ATS_ALLOCATION
    SET
    ATS_ALLOCATION_ID = :P6_ATS_ALLOCATION_ID,
    ATS_START_DATE = :P6_ATS_START_DATE,
    ATS_END_DATE = SYSDATE,
    ATS_CLS_NAME = :P6_ATS_CLS_NAME,
    ATS_CEL_NAME = :P6_ATS_CEL_NAME,
    ATS_EMP_ID = :P6_EMP_EMP_ID
    ELSE
    UPDATE ATS_ALLOCATION
    SET
    ATS_ATS_ALLOCATION = :P6_ATS_ALLOCATION,
    ATS_START_DATE = :P6_ATS_START_DATE,
    ATS_END_DATE = :P6_ATS_END_DATE,
    ATS_CLS_NAME = :P6_ATS_CLS_NAME,
    ATS_CEL_NAME = :P6_ATS_CEL_NAME,
    ATS_EMP_ID = :P6_EMP_EMP_ID
    FROM ATS_ALLOCATION
    END CASE;
    END;
    And I get this error:
    1 error has occurred
    ORA-06550: line 12, column 7: PL/SQL: ORA-00936: missing expression ORA-06550: line 5, column 1: PL/SQL: SQL Statement ignored

    BEGIN
    UPDATE ATS_ALLOCATION
    SET
    ATS_ATS_ALLOCATION = :P6_ATS_ALLOCATION,
    ATS_START_DATE = :P6_ATS_START_DATE,
    ATS_END_DATE = CASE
         WHEN ATS_CLS_NAME <> :P6_ATS_CLS_NAME
         AND ATS_CLS_NAME <> :P6_ATS_CEL_NAME
         AND ATS_END_DATE is Null
         THEN SYSDATE
         ELSE :P6_ATS_END_DATE
    END,
    ATS_CLS_NAME = :P6_ATS_CLS_NAME,
    ATS_CEL_NAME = :P6_ATS_CEL_NAME,
    ATS_EMP_ID = :P6_EMP_EMP_ID
    END;
    1 error has occurred
    ORA-06550: line 18, column 3: PL/SQL: ORA-00933: SQL command not properly ended ORA-06550: line 4, column 1: PL/SQL: SQL Statement ignored ORA-06550: line 21, column 21: PLS-00103: Encountered the symbol "end-of-file" 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

  • [Oracle 8i] Handling null in case statement

    The following bit of my query is causing the error 'inconsistent datatypes':
    CASE
         WHEN b.days_diff < 0
         THEN plan_start
         ELSE plan_start + b.days_diff
    ENDThe problem is that b.days_diff can be null.
    I've tried to work around this, by using the NVL statement and by nesting 2 case statements to try to deal with the null, but can't seem to work around it.
    Does anyone have anything else I can try?

    Apologies...internet server went down yesterday...
    I've had this issue before with my database. When I look at user_tab_columns, it says plan_start is a date. However, I have had to use TO_DATE in the past with it to get some things to work. It's very odd, and I have no idea why it's like that.
    Anyway, below, I have provided some sample data, and the full query I'm trying to run:
    CREATE TABLE     ord (
    ord_nbr          char(10)
    ord_stat     char(2)
    INSERT INTO     ord
    VALUES          ('0000012345', 'OP');
    INSERT INTO     ord
    VALUES          ('0000012346', 'OP');
    INSERT INTO     ord
    VALUES          ('0000012347', 'CL');
    INSERT INTO     ord
    VALUES          ('0000012348', 'OP');
    CREATE TABLE     op (
    ord_nbr          char(10)
    operation     char(4)
    op_status     char(2)
    plan_start     date
    pln_due          date
    dt_complete     date
    INSERT INTO     op
    VALUES          ('0000012345', '0001', 'CL', {ts '2009-01-01 00:00:00'}, {ts '2009-01-02 00:00:00'}, {ts '2009-01-04 00:00:00'});
    INSERT INTO     op
    VALUES          ('0000012345', '0002', 'CL', {ts '2009-01-02 00:00:00'}, {ts '2009-01-03 00:00:00'}, {ts '2009-01-06 00:00:00'});
    INSERT INTO     op
    VALUES          ('0000012345', '0003', 'CL', {ts '2009-01-03 00:00:00'}, {ts '2009-01-04 00:00:00'}, {ts '2009-01-09 00:00:00'});
    INSERT INTO     op
    VALUES          ('0000012345', '0004', 'WK', {ts '2009-01-04 00:00:00'}, {ts '2009-01-05 00:00:00'}, {ts '1900-12-31 00:00:00'});
    INSERT INTO     op
    VALUES          ('0000012345', '0005', 'OP', {ts '2009-01-05 00:00:00'}, {ts '2009-01-06 00:00:00'}, {ts '2009-01-02 00:00:00'});
    INSERT INTO     op
    VALUES          ('0000012346', '0001', 'CL', {ts '2009-01-01 00:00:00'}, {ts '2009-01-02 00:00:00'}, {ts '2009-01-01 00:00:00'});
    INSERT INTO     op
    VALUES          ('0000012346', '0002', 'OP', {ts '2009-01-02 00:00:00'}, {ts '2009-01-04 00:00:00'}, {ts '1900-12-31 00:00:00'});
    INSERT INTO     op
    VALUES          ('0000012346', '0003', 'OP', {ts '2009-01-04 00:00:00'}, {ts '2009-01-06 00:00:00'}, {ts '1900-12-31 00:00:00'});
    INSERT INTO     op
    VALUES          ('0000012347', '0001', 'CL', {ts '2009-01-01 00:00:00'}, {ts '2009-01-02 00:00:00'}, {ts '2009-01-03 00:00:00'});
    INSERT INTO     op
    VALUES          ('0000012347', '0002', 'CL', {ts '2009-01-02 00:00:00'}, {ts '2009-01-05 00:00:00'}, {ts '2009-01-06 00:00:00'});
    INSERT INTO     op
    VALUES          ('0000012348', '0001', 'OP', {ts '2009-01-15 00:00:00'}, {ts '2009-01-17 00:00:00'}, {ts '1900-12-31 00:00:00'});
    INSERT INTO     op
    VALUES          ('0000012348', '0002', 'OP', {ts '2009-01-17 00:00:00'}, {ts '2009-01-20 00:00:00'}, {ts '1900-12-31 00:00:00'});Full query:
    SELECT     ord.ord_nbr
    ,     ord.ord_stat
    ,     op.operation
    ,     op.op_status
    ,     op.plan_start
    ,     //where I want to return plan_start + days_diff if days_diff is not null or negative
         //otherwise, I want to return just plan_start
         AS adjusted_start
    ,     op.dt_complete
    ,     b.max_cl_op
    ,     b.pln_due
    ,     b.dt_complete
    ,     b.days_diff
    FROM     ord
    ,     op
         SELECT     a.ord_nbr
         ,     a.max_cl_op
         ,     op.pln_due
         ,     op.dt_complete
         ,     (op.dt_complete-op.pln_due)     AS days_diff
         FROM     (
              SELECT          op.ord_nbr
              ,          MAX(TO_NUMBER(op.operation))     AS max_cl_op
              FROM          ord
              ,          op
              WHERE          ord.ord_nbr     = op.ord_nbr
              AND          ord.ord_stat     != 'CL'
              AND          op.op_status     ='CL'
              GROUP BY     op.ord_nbr
              ) a
         WHERE     op.ord_nbr     = a.ord_nbr
         AND     op.operation     = a.max_cl_op
         ) b
    WHERE     ord.ord_nbr     = op.ord_nbr
    AND     op.ord_nbr     = b.ord_nbr (+)
    AND     ord.ord_stat     != 'CL'
    AND     op.op_status     != 'CL'
    AND     op.plan_start     <= ADD_MONTHS(sysdate, 12)The results I want to get:
    ord.ord_nbr     ord.ord_stat     op.operation     op.op_status     op.plan_start     adjusted_start     op.dt_complete     b.max_cl_op     b.pln_due     b.dt_complete     b.days_diff
    '0000012345'     'OP'          '0004'          'WK'          1/4/2009     1/9/2009     12/31/1900     '0003'          1/4/2009     1/9/2009     5     
    '0000012345'     'OP'          '0005'          'OP'          1/5/2009     1/10/2009     12/31/1900     '0003'          1/4/2009     1/9/2009     5
    '0000012346'     'OP'          '0002'          'OP'          1/2/2009     1/2/2009     12/31/1900     '0001'          1/2/2009     1/1/2009     -1
    '0000012346'     'OP'          '0003'          'OP'          1/4/2009     1/4/2009     12/31/1900     '0001'          1/2/2009     1/1/2009     -1
    '0000012348'     'OP'          '0001'          'OP'          1/15/2009     1/15/2009     12/31/1900                                   
    '0000012348'     'OP'          '0002'          'OP'          1/17/2009     1/17/2009     12/31/1900     

  • 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
    END

    Hi 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

  • Problem with Case statement

    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 advance

    874167 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?

  • 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.

  • 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.

  • Issue with case statement

    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 PM

    Dear 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

  • Exception thrown trying to convert string to int

    Hey Guys,
    i imported a csv file into my app which i divide using the split() method and put into an array then I divided the array into variables;
    fruit = piece[0];
    price = piece[1];
    unit = piece[2];Now since price has to be a double i converted it into a double;
    price2 = Double.parseDouble(price);which worked grand
    but when i try to convert unit to an integer
    unit2 = Integer.parseInt(unit);i got error
    Exception in thread "main" java.lang.NumberFormatException: For input string: "3
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    so i tried removing white spaces as follows
    target = unit.replace(" ", "");which worked and displayed grand, then i tried converting to int again but the same exception was thrown, can anyone help me with this problem, thanks
    mark

    sorry for the messed up format previously.
    Like you said the unit.replaceAll(" ", ""); did not do the trick, when displayed as a string it looked like 3 was on its own but still did not convert to int. I assume line break or something existed in the csv file like you mentioned earlier as unit was the last word in the csv file.
    when i used unit.trim(); and tried to convert to integer it worked perfectly.
    thanks all for your help,
    Mark

Maybe you are looking for

  • How can I detect a certain text within a field within CASE using IF

    Dear all, for a transformation / generation of values receiving from R/3 into BW I try to manupulate three fields. I have a problem detecting a string in a field. I am using a CASE with several WHEN clauses on one field. Depending on the value, an IF

  • Is there a software program that automatically save stills from a QT video?

    Just wondering if there's any software out there that will automatically save stills from a QT video? There's a program called Image Grabber by Cliprex that does this but it only works on PC's. You run it and it makes like 100 imge captures from the

  • Materialized view on a Partitioned Table (Data through Exchange Partition)

    Hello, We have a scenario to create a MV on a Partitioned Table which get data through Exchange Partition strategy. Obviously, with exchange partition snap shot logs are not updated and FAST refreshes are not possible. Also, this partitioned table be

  • Code to produce .txt file from asp

    Hi, Does anyone have or know where I can get some asp code that will write a recordset to a text file or csv file. I need this functionality for a project I am working on and I cannot find this anywhere. Thanks.

  • App-v 4.6: new version of package?

    Hi, I have this App-v 4.6 package I need to change/upgrade. I can see in the app-v management server there are already some versions (1.1, 1.2 and now I need to make 1.3). Not sure howto though. The package is on a dfs-share \\ourcompany\share\. What