Error in writing case statement

i am writing this getting error in case statement
declare
v_RenewService NUMBER(10,0);
begin
Select
Case v_RenewService
when
5 >= 365 THEN
when
1=0
then
1
else
0
end
end
from dual ;
end;
Error report:
ORA-06550: line 7, column 3:
PL/SQL: ORA-00905: missing keyword
ORA-06550: line 5, column 1:
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Not clear what are you trying to do, but based on two ENDs it looks like code is missing second CASE:
Select  case v_RenewService
          when 5 >= 365 THEN CASE
                               when 1=0 then 1
                               else 0
                             end
        end
from dual ;However the above is still wrong syntax since you can't mix simple_case_expression and searched_case_expression (see CASE Expressions). So please explain in words what are you trying to do.
SY.

Similar Messages

  • Got error when use case statement in oracle stored procedure

    Hi,
    I have a query like:
    select merchant_id,
    case
    when product_type='K' then 'Production'
    when product_carrier='UC' THEN 'Shipping'
    end the_type
    from product_tbl
    where merchant_id=10114
    It works fine. But as soon as I put it into a stored procedure, I got error like:
    Encountered the symbol "CASE" when expecting one of the following:
    ( - + mod null <an identifier>
    Please help!

    Oracle 8i doesn't support CASE into PL/SQL, so as Kamal said, create a view with the CASE, and use this view into your PL/SQL.
    Nicolas.
    And an example here :
    Re: Execute Immediate doesnot work in 8i (8.1.7) and Ref Cursor not exec qu
    Sorry Kamal.
    Message was edited by:
    N. Gasparotto

  • Error in writing the CASE statement

    i am writing these lines for my procedure getting error in writing CASE Statement when i remove case give result please any suggestion
    SELECT OTServicesMapping.ServiceId,Service_mst.Service_Name,
    OTServicesMapping.DependentOn,
    CASE OTROLEID -----error in this line
    WHEN (SELECT NVL(ChiefSurgeonServiceId,0) FROM ConfigOTService) = OTServicesMapping.ServiceId THEN 1
    else 0
    end,
    OTServicesMapping.OTPercent
    FROM Service_mst INNER JOIN
    OTServicesMapping ON Service_mst.Service_ID =OTServicesMapping.ServiceId LEFT OUTER JOIN
    Service_mst Service_mst_1 ON OTServicesMapping.DependentOn = Service_mst_1.Service_ID
    ERROR
    SQL Error: ORA-00905: missing keyword
    00905. 00000 - "missing keyword"
    *Cause:   
    *Action:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Hi,
    What part does otroleid play in this problem? Why can't you say:
    CASE
         WHEN ( SELECT  NVL (ChiefSurgeonServiceId, 0)
                  FROM    ConfigOTService
              ) = OTServicesMapping.ServiceId  THEN 1
                                      ELSE 0
    END, ?
    Will there ever be more than 1 row in the ConfigOTService table? If so, you'll have a different error.
    Whenevder you have a problem, post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data. Explain how you get those results from that data.
    QAlways say what version of Oracle you're usiing.

  • Case Statement error in Obiee

    Hi All,
    I'm facing an error with my Case statement in OBIEE(using it in expression builder in RPD). Below is the statement.
    CASE WHEN"GCRMANDB".""."HIM_SRV_REQ_DIM"."ATTRIB_44" = 'Customer Demand Not In GDMS' OR GCRMANDB"."HIM_SRV_REQ_DIM"."ATTRIB_45" = 'Customer Demand Not In GDMS' THEN 1
    (WHEN "GCRMANDB".""."HIM_SRV_REQ_DIM"."ATTRIB_44" = 'Poor Behaviour / Attitude' OR GCRMANDB"."HIM_SRV_REQ_DIM"."ATTRIB_45" = 'Poor Behaviour / Attitude' THEN 1) ELSE 0 END
    Error message that i'm getting is:
    [nQSError: 27002] Near <">: Syntax error [nQSError: 26012] .
    Plaese help

    Try this
    CASE
    WHEN "GCRMANDB"."HIM_SRV_REQ_DIM"."ATTRIB_44" = 'Customer Demand Not In GDMS' OR GCRMANDB"."HIM_SRV_REQ_DIM"."ATTRIB_45" = 'Customer Demand Not In GDMS' THEN 1
    WHEN "GCRMANDB"."HIM_SRV_REQ_DIM"."ATTRIB_44" = 'Poor Behaviour / Attitude' OR GCRMANDB"."HIM_SRV_REQ_DIM"."ATTRIB_45" = 'Poor Behaviour / Attitude' THEN 1
    ELSE 0 END
    Mark if helps

  • Case statement error OBIEE

    Hi All,
    I'm getting an error with my Case statement in OBIEE. Below is the statement.
    case when @{PV_RELEASE_NAME} = 'January' then "Script Details"."Calendar Date" is between ('1/1/2012','1/31/2012') else"Script Details"."Calendar Date" end
    Please advice. Thanks for your help in advance!

    Thanks for the response , I tried with the formula u mention still I am getting the same error ..Please find the error below
    case when @{PV_RELEASE_NAME} = 'January' then "Script Details"."Calendar Date" || " is between ('1/1/2012','1/31/2012')" else"Script Details"."Calendar Date" end
    Formula syntax is invalid.
    [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 27005] Unresolved column: " is between ('1/1/2012','1/31/2012')". (HY000)
    SQL Issued: SELECT case when 0 = 'January' then "Script Details"."Calendar Date" || " is between ('1/1/2012','1/31/2012')" else"Script Details"."Calendar Date" end FROM "Test Script - Ad Hoc"
    If I use the below formula I am getting syntax error
    case when @{PV_RELEASE_NAME} = 'January' then "Script Details"."Calendar Date" is between ('1/1/2012','1/31/2012') else"Script Details"."Calendar Date" end
    Formula syntax is invalid.
    [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 27002] Near : Syntax error [nQSError: 26012] . (HY000)
    SQL Issued: SELECT case when 0 = 'January' then "Script Details"."Calendar Date" is between ('1/1/2012','1/31/2012') else"Script Details"."Calendar Date" end FROM "Test Script - Ad Hoc"

  • Case statement error

    Error:  The below case statement is throwing error when i include in the select statement for B
       CASE WHEN (AST_INV_CHF_Y <= 250000)
                      THEN 'BELOW 250K'
                      WHEN (AST_INV_CHF_Y > 250000  AND AST_INV_CHF_Y <=1000000)
                      THEN 'CHF250K-1MN'
                      WHEN (AST_INV_CHF_Y > 1000000 AND AST_INV_CHF_Y <=5000000)
                      THEN 'CHF1MN-5MN'
                      WHEN (AST_INV_CHF_Y > 5000000 AND AST_INV_CHF_Y <=10000000)
                      THEN 'CHF5MN-10MN'
                      WHEN (AST_INV_CHF_Y > 10000000)
                      THEN 'CHF10MN PLUS'
                      ELSE 'NO INV HH AST' END AS AST_SGMT_RNG_CHF_T   
    ----------- Full query                 
    SELECT       TO_CHAR(SYSDATE,'yyyy-mm-dd') AS ED_UPD_D,
                 BRN_I,
                 DVS_I,
                 A.ACC_MHH_N,
                 GPC_MAND_C,
                 GPC_DPNT_C,          
                 GPC_INDEP_C, 
                 GPC_TRST_C,             
                 ACC_AST_PRCS_D,         
                 AST_SRCE_SD_Y,
                 AST_SRCE_SD_CHF_Y,
                 CNTRY_DMCL_DESC_T,
                 AST_SGMT_RNG_CHF_T
        select * from CFO_OWNER.ASSETS_BY_DOMICILE_TEMP1 A,
                 SELECT   SYSDATE    AS ED_UPD_D,
                              ACC_MHH_N,
                 SUM(
                         CASE WHEN (AST_GMIS_LIAB_C = '20001'
                        ) THEN AST_SRCE_SD_CHF_Y
                          ELSE 0 END)
                 AS AST_INV_CHF_Y ,
       CASE WHEN (AST_INV_CHF_Y <= 250000)
                      THEN 'BELOW 250K'
                      WHEN (AST_INV_CHF_Y > 250000  AND AST_INV_CHF_Y <=1000000)
                      THEN 'CHF250K-1MN'
                      WHEN (AST_INV_CHF_Y > 1000000 AND AST_INV_CHF_Y <=5000000)
                      THEN 'CHF1MN-5MN'
                      WHEN (AST_INV_CHF_Y > 5000000 AND AST_INV_CHF_Y <=10000000)
                      THEN 'CHF5MN-10MN'
                      WHEN (AST_INV_CHF_Y > 10000000)
                      THEN 'CHF10MN PLUS'
                      ELSE 'NO INV HH AST' END AS AST_SGMT_RNG_CHF_T           
        FROM CFO_OWNER.ASSETS_BY_DOMICILE_TEMP1
        GROUP BY ACC_MHH_N
        ORDER BY ACC_MHH_N
        ) B
    where a.ACC_MHH_N = b.ACC_MHH_N   )
    below are the columns for the table ASSETS_BY_DOMICILE_TEMP1.
                 A.ACC_MHH_N,
                 A.BRN_I,
                 A.DVS_I,
                 CNTRY_DMCL_DESC_T,
                 GPC_MAND_C,
                 GPCE_DPNT_C AS GPC_DPNT_C,      
                 GPC_INDEP_C, 
                 GPC_TRST_C,             
                 ACC_AST_PRCS_D,
                 AST_GMIS_LIAB_C,         
                 AST_SRCE_SD_Y,
                 AST_SRCE_SD_CHF_Y
        

    Hi,
    It's hard to tell if you have ENDs to each CASE.
    I recommend indenting so that the END comes directly underneath CASE, with only whitespace in between.
    SELECT  ED_UPD_D,ACC_MHH_N,AST_INV_CHF_Y ,
            CASE
           WHEN (AST_INV_CHF_Y <= 250000)
                      THEN 'BELOW 250K'
                      WHEN (AST_INV_CHF_Y <=1000000)  -- No need to test for lower bound
                      THEN 'CHF250K-1MN'
                      WHEN (AST_INV_CHF_Y <=5000000)
                      THEN 'CHF1MN-5MN'
                      WHEN (AST_INV_CHF_Y <=10000000)
                      THEN 'CHF5MN-10MN'
                      WHEN (AST_INV_CHF_Y > 10000000) -- Equivalent to IS NOT NULL
                      THEN 'CHF10MN PLUS'
                      ELSE 'NO INV HH AST'
         END AS AST_SGMT_RNG_CHF_T
    FROM (
         SELECT   TO_CHAR(SYSDATE,'yyyy-mm-dd')    AS ED_UPD_D,
                  ACC_MHH_N,
                       SUM (
                           CASE
                        WHEN (AST_GMIS_LIAB_C = '20001')
                        THEN AST_SRCE_SD_CHF_Y
                               ELSE 0
                   END
                   )             AS AST_INV_CHF_Y
         FROM      CFO_OWNER.ASSETS_BY_DOMICILE_TEMP1
             GROUP BY ACC_MHH_N
    ORDER BY ACC_MHH_NSince the first WHEN clause said
    AST_INV_CHF_Y <= 250000, there's no need to check for
    AST_INV_CHF_Y > 250000 in the second one: the second WHEN clause won't even be executed if AST_INV_CHF_Y <= 250000.
    Edited by: Frank Kulash on Nov 21, 2008 2:18 PM

  • Help: Case statement Error

    Hello Folks,
    Am trying to execute a procedure but somehow its returning an error near the case statement.I am thinking whether i have written it correctly or not. Can anyone please advice.Am just posting that specific part of the code where it points. Thanks a million.
    select  @v_retained_by_client = case c.code when '50' then RETAINED_BY_CLIENT  -- Its pointing the error at this line
                                                  when '51' then RETAINED_BY_CLIENT                
                                                  when '52' then RETAINED_BY_CLIENT
                                                  else 0
                                                  end,
               @v_hriretainedfee = case c.code  when '50' then hri_fee     
                                                when  '51' then hri_fee
                                                when '52' then hri_fee
                                                else 0
                                                end,
              @v_adminretainedfee = case c.code when '50' then admin_fee    
                                                when  '51' then admin_fee
                                                when '52' then admin_fee
                                                else 0
                                               end,  
               @v_allocation_amt = case c.code       when '50' then ALLOCATION_CHECK_AMOUNT
                                                        when '51' then ALLOCATION_CHECK_AMOUNT
                                                       when '52' then ALLOCATION_CHECK_AMOUNT          
                                                 else 0
                                              end,
              @v_cur_recoveryrefund = case c.code when '96' then sum(recovery_amount)      
              end,
              @v_cur_recoveryvoid = case c.code when '95'  then sum(recovery_amount)   
              end,
              @v_cur_hrirefund = case c.code when '96' then sum(hri_fee)            
              end,
              @v_cur_hrivoid = case c.code when '95'  then sum(hri_fee)             
              end,
                @v_cur_adminrefund = case c.code when '96' then sum(admin_fee)            
              end,
              @v_cur_adminvoid = case c.code when '95'  then sum(admin_fee)              
              end,
                @v_cur_taxrefund = case c.code when '96' then sum(taxes)             
              end,
              @v_cur_taxvoid = case c.code when '95' then sum(taxes)              
              end
                 from cash_receipt b, recovery_type c
                 where case_id = @v_case_id
              and b.recovery_type_id = c.recovery_type_id
              and recovery_date between @p_startdate and @p_enddate
            end         Edited by: user11961230 on Nov 25, 2009 1:27 PM

    Hi,
    Sorry, I don't know anything about SQL Server.
    I do know you should take baby steps, especially when trying something you're not sure how to do.
    Get rid of all but one CASE expression, until you know how to make that one work.
    When you do get that to work, add one more, as much like the first as possible, to make sure you know how to do two columns in the same query.
    Get asomething working, then try adding a little bit to it. When you do have errors, you'll have a much better idea what caused the errror.
    It's suspicious that you're using aggregate functions in some places, like this
    @v_cur_recoveryrefund = case c.code when '96' then sum(recovery_amount)      
              end,but not in the first CASE expressions. You might try <tt>MAX (CASE case c.code when '50' then ... END)</tt>
    I also find it odd that you're using <tt>CASE ... SUM (...)</tt> ; in Oracle, that would be very rare. It implies that the same expression will be in the GROUP BY clause.
    It's more common to have <tt>SUM (CASE ... END)</tt> , like this:
    SUM ( CASE c.code WHEN '96' THEN recovery_amount END )

  • [8i] Case statement generates ORA-00932: inconsistent datatypes

    Note: I am working with an 8i database (yes, it is quite old), and in this situation, I have to deal with the datatypes (i.e. CHAR), I am given to work with.
    I am attempting to calculate the amount of time product waits between manufacturing steps. As I've discovered though, sometimes I get a negative value when subtracting the date the previous step completes from the date the current step starts. As it is generally impossible to start a later step before an earlier step (imagine trying to screw a cap onto a bottle that doesn't have threads cut yet--it just can't happen), what I've found is that sometimes two steps are started on the same day and finished on the same day (though not necessarily the day they started). This situation CAN happen when one person did both steps and logged on to both steps at the same time, rather than logging on to one, then the other. So, what I need to do in these situations is replace the negative number with a zero (I'll treat the later step as having no wait time).
    Here is some sample data:
    (Note: the real data set is the result of a query, and has around 200K rows and more columns, but this should be representative enough to find a solution that works on my actual application.)
    CREATE TABLE     steps
    (     item_id          CHAR(25)
    ,     ord_nbr          CHAR(10)
    ,     sub_nbr          CHAR(3)
    ,     step_nbr     CHAR(4)
    ,     start_date     DATE
    ,     finish_date     DATE
    INSERT INTO steps
    VALUES ('A','0000000001','001','0010',TO_DATE('01/01/2011','mm/dd/yyyy'),TO_DATE('01/02/2011','mm/dd/yyyy'));
    INSERT INTO steps
    VALUES ('A','0000000001','001','0020',TO_DATE('01/01/2011','mm/dd/yyyy'),TO_DATE('01/02/2011','mm/dd/yyyy'));
    INSERT INTO steps
    VALUES ('A','0000000001','001','0030',TO_DATE('01/05/2011','mm/dd/yyyy'),TO_DATE('01/06/2011','mm/dd/yyyy'));
    INSERT INTO steps
    VALUES ('A','0000000001','002','0010',TO_DATE('01/01/2011','mm/dd/yyyy'),TO_DATE('01/02/2011','mm/dd/yyyy'));
    INSERT INTO steps
    VALUES ('A','0000000001','002','0020',TO_DATE('01/04/2011','mm/dd/yyyy'),TO_DATE('01/04/2011','mm/dd/yyyy'));
    INSERT INTO steps
    VALUES ('A','0000000001','002','0030',TO_DATE('01/06/2011','mm/dd/yyyy'),TO_DATE('01/07/2011','mm/dd/yyyy'));
    INSERT INTO steps
    VALUES ('B','0000000002','001','0005',TO_DATE('01/10/2011','mm/dd/yyyy'),TO_DATE('01/12/2011','mm/dd/yyyy'));
    INSERT INTO steps
    VALUES ('B','0000000002','001','0025',TO_DATE('01/10/2011','mm/dd/yyyy'),TO_DATE('01/12/2011','mm/dd/yyyy'));Here is the query I use that returns negative values sometimes:
    SELECT     item_id
    ,     ord_nbr
    ,     sub_nbr
    ,     step_nbr
    ,     start_date - last_step_finished
    FROM     (
         SELECT     s.*
         ,     LAG (s.finish_date)     OVER     (
                                  PARTITION BY     s.item_id
                                  ,          s.ord_nbr
                                  ,          s.sub_nbr
                                  ORDER BY     s.step_nbr
                                  )     AS last_step_finished
         FROM     steps s
    Returns:
    ITEM_ID                   ORD_NBR    SUB STEP START_DATE-LAST_STEP_FINISHED
    A                         0000000001 001 0010
    A                         0000000001 001 0020                        -1.000
    A                         0000000001 001 0030                         3.000
    A                         0000000001 002 0010
    A                         0000000001 002 0020                         2.000
    A                         0000000001 002 0030                         2.000
    B                         0000000002 001 0005
    B                         0000000002 001 0025                        -2.000These are the results I want to see:
    ITEM_ID                   ORD_NBR    SUB STEP START_DATE-LAST_STEP_FINISHED
    A                         0000000001 001 0010
    A                         0000000001 001 0020                         0.000
    A                         0000000001 001 0030                         3.000
    A                         0000000001 002 0010
    A                         0000000001 002 0020                         2.000
    A                         0000000001 002 0030                         2.000
    B                         0000000002 001 0005
    B                         0000000002 001 0025                         0.000And this is what I tried to do to get those results (comment notes what line generated the error):
    SELECT     item_id
    ,     ord_nbr
    ,     sub_nbr
    ,     step_nbr
    ,     CASE
              WHEN     start_dt - last_step_finished     < 0
              THEN     0
              ELSE     start_dt - last_step_finished  -- THIS LINE GENERATES THE ORA-00932 ERROR
         END                         AS days_in_queue
    FROM     (
         SELECT     s.*
         ,     LAG (s.finish_date)     OVER     ( PARTITION BY  s.item_id
                                    ,          s.ord_nbr
                                    ,          s.sub_nbr
                                    ORDER BY     s.step_nbr
                                  )     AS last_step_finished
         FROM     steps s
         );I know I've had inconsistent datatype errors before with case statements in this particular 8i database, but I can't seem to figure out why I'm getting one this time. I think it has something to do with the NULL values that can occur for last_step_finished. Also, if I change the case statement to:
    ,     CASE
              WHEN     start_dt - last_step_finished     < 0
              THEN     NULL
              ELSE     start_dt - last_step_finished  -- THIS LINE GENERATES THE ORA-00932 ERROR
         END     the query runs just fine. But, I don't want NULL, I want 0. In the next level of this query, I will be taking averages by item_id/step_nbr, and I want the 0's to be included in the average. (NULL values, as far as I can tell, would be excluded. AVG(NULL, 1, 2) =AVG (1,2) = 1.5 NOT AVG(0,1,2) = 1).
    Thanks in advance!

    Thanks, TO_NUMBER did the trick. Since you didn't state in your post where to use TO_NUMBER, here is my final solution, in case anyone in the future looks through this thread to find an answer to their question:
    SELECT     item_id
    ,     ord_nbr
    ,     sub_nbr
    ,     step_nbr
    ,     CASE
              WHEN     start_dt - last_step_finished     < 0
              THEN     0
              ELSE     TO_NUMBER(start_dt - last_step_finished)
         END                         AS days_in_queue
    FROM     (
         SELECT     s.*
         ,     LAG (s.finish_date)     OVER     ( PARTITION BY  s.item_id
                                    ,          s.ord_nbr
                                    ,          s.sub_nbr
                                    ORDER BY     s.step_nbr
                                  )     AS last_step_finished
         FROM     steps s
         );Edited by: user11033437 on Jun 27, 2011 11:17 AM
    I see you edited your post to add TO_NUMBER to it.

  • Unable to write more than 10 case statements in an object in designer

    unable to write more than 10 case statements in an object in designer
    XI 3.0 and XI 3.1
    Please let me know, any known issues.

    Hi,
    yes this is the limitation you cant write more that 10 case statments but you can reduce the number of time you use the case in your object.
    For ex:
    If you are writing few conditions on one field then you can add the login in one case only.
    case when SAL between 100 and 1000 then 'lowsal'
            when SAL between 1000 and 2000 then 'medsal'
            when sal between 2000 and 3000 then highsal
    else
    case when ...then ....
    else
    end
    end
    by following the above ex you can solve your problem.
    But if you are writing case statement based on dofferent columns then write 10 case statements and remaining conditions you can add at the report level.
    using if else condition.
    Hope this will help you....
    Cheers,
    Ravichandra

  • Please help: Case Statement - ORA-01722: invalid number Error

    Hi All,
    I'm trying to use Case statement to recode Cancelled statuses into two groups
    'Reject' if the difference between first date and last date is less than 29 and
    'Accept' if the difference between first date and last date is greater than 30
    Here is my 'test' data:
    STATUS     FIRST_DATE     LAST_DATE
    Transfer     10/08/2011     10/09/2011
    Mover     10/08/2011     15/09/2011
    Cancel     10/08/2011     16/09/2011
    Cancel     10/08/2011     5/09/2011
    Here is the syntax
    select a.*,
    (CASE WHEN a.STATUS ='Cancel' THEN (round(a.LAST_DATE-a.FIRST_DATE))
    ELSE 0
    END) CAN_DAYS,
    (CASE WHEN 'CAN_DAYS' >29 THEN 'Reject'
    WHEN 'CAN_DAYS' <30 THEN 'Accept'
    END) Reject_Accept
    from test a
    The first CASE statement works fine and gives me this
    STATUS     FIRST_DATE     LAST_DATE     CAN_DAYS
    Transfer     10/08/2011     10/09/2011     0
    Mover     10/08/2011     15/09/2011     0
    Cancel     10/08/2011     16/09/2011     37
    Cancel     10/08/2011     5/09/2011     26
    but the second CASE produces ORA-01722: invalid number Error. It is something to do with the CAN_DAYS data type, Oracle doesn't see it as Numeric i think.
    The result i want to see would be
    STATUS     FIRST_DATE     LAST_DATE     CAN_DAYS Reject_Accept
    Transfer     10/08/2011     10/09/2011     0
    Mover     10/08/2011     15/09/2011     0
    Cancel     10/08/2011     16/09/2011     37 Accept
    Cancel     10/08/2011     5/09/2011     26 Reject
    Could someone please help me to fix the syntax?
    Thank you in advance,

    This seems to give you your desired results...
    with test as
      ( select 'Transfer' as status, to_date('10/08/2011') as first_date, to_date('10/09/2011') as last_date  from dual union all
        select 'Mover'             , to_date('10/08/2011')              , to_date('15/09/2011')               from dual union all
        select 'Cancel'            , to_date('10/08/2011')              , to_date('16/09/2011')               from dual union all
        select 'Cancel'            , to_date('10/08/2011')              , to_date('05/09/2011')               from dual
    select  status
         ,  first_date
         ,  last_date
         ,  CAN_DAYS
         ,  CASE
              WHEN CAN_DAYS =   0 THEN NULL
              WHEN CAN_DAYS <  30 THEN 'Reject'
              WHEN CAN_DAYS >= 30 THEN 'Accept'
            END  Reject_Accept
      from  ( select  status
                   ,  first_date
                   ,  last_date
                   ,  CASE
                        WHEN STATUS ='Cancel' THEN round(LAST_DATE-FIRST_DATE)
                        ELSE 0
                      END  CAN_DAYS
                from  test
    ;

  • CASE Statement error in function -- Please help!

    Hi All,
    I created a function in my report.
    It has a SQL query similar to the one below. The query works fine in SQL plus.
    It has a CASE statement. I am getting error at line4 at the select statement. Error is: "Encountered symbol 'SELECT'....."
    Can we use CASE statements like this in reports that use SELECT statements for RETURN EXPRESSIONS. Do we have to do any special?
    Can someone help me out of this trouble?
    THanks in advance.
    SELECT PARENT_id,
         CASE WHEN EXISTS (SELECT PARENT_id FROM CHILD CH1 WHERE CH1.PARENT_id = PARENT.PARENT_id AND UPPER(CH1.description) LIKE '%ABC%') THEN
              (SELECT CH2.MOD_id FROM CHILD CH2 WHERE CH2.PARENT_id = PARENT.PARENT_id AND UPPER(CH2.description) LIKE '%ABC%')
         ELSE
              (SELECT MOD_id FROM
              (SELECT MOD_id,PARENT_id FROM CHILD CH3 ORDER BY started) MOD2 WHERE MOD2.PARENT_id = PARENT.PARENT_id AND ROWNUM = 1
         END
    ) MOD_ID
    FROM PARENT;

    take out the parentheses after the PARENT_ID and see
    like below
    SELECT parent_id,
           CASE
              WHEN EXISTS (
                     SELECT parent_id
                       FROM CHILD ch1
                      WHERE ch1.parent_id = PARENT.parent_id
                        AND UPPER (ch1.description) LIKE '%ABC%')
                 THEN (SELECT ch2.mod_id
                         FROM CHILD ch2
                        WHERE ch2.parent_id = PARENT.parent_id
                          AND UPPER (ch2.description) LIKE '%ABC%')
              ELSE (SELECT mod_id
                      FROM (SELECT   mod_id, parent_id
                                FROM CHILD ch3
                            ORDER BY started) mod2
                     WHERE mod2.parent_id = PARENT.parent_id AND ROWNUM = 1)
           END AS mod_id
      FROM PARENT;       

  • Bind Variable In Case Statement Produces Error ORA-01036

    When running the following command using ODP.Net 10.1.0.301 I recieve error 1036. Statement runs fine within SQL+ and Toad.
    Dim SQL As String = "SELECT CASE WHEN EXISTS(SELECT part_nbr FROM item_master WHERE part_nbr=:part_number) THEN 1 ELSE 0 END AS RECORD_EXISTS FROM Dual"
    Dim OraConnection As New OracleConnection(connectstring)
    Dim OraCommand As New OracleCommand(SQL, OraConnection)
    OraCommand.Parameters.Add("part_number", OracleDbType.Varchar2).Value = PartNumber
    Dim Obj as Object=OraCommand.ExecuteScalar

    Hi Michael,
    I was able to get your code to work on my system by changing the SQL statement as follows:
    SELECT (CASE WHEN EXISTS(SELECT part_nbr FROM item_master WHERE part_nbr=:part_number) THEN 1 ELSE 0 END) AS RECORD_EXISTS FROM Dual
    I simply enclosed the case statement in opening and closing parenthesis...
    Hope that helps,
    - Mark

  • Creating view containing case statements received error ORA-22992

    We have a create view referencing table through dblink. The select statement in the create view has case statements, when running the Select statement alone, results are return. However, when executing the create view, it returns:
    SQL Error: ORA-22992: cannot use LOB locators selected from remote tables
    22992. 00000 - "cannot use LOB locators selected from remote tables"
    *Cause:    A remote LOB column cannot be referenced.
    *Action:   Remove references to LOBs in remote tables.
    One of the source table has LOB column but not in the select statement. The strange thing is when removing the case statement from the select, create view works fine. Can anybody tell me what caused the error and how to fix it?
    Create View Snippet:
    CREATE OR REPLACE VIEW "ABC"."XYZ" (....
    AS SELECT
    CASE
    WHEN A.OUTAGE =1
    THEN 'Y'
    ELSE 'N'
    END AS OUTAGE,
    FROM
    TABLEA@XXXX A
    LEFT JOIN TABLEB@XXXX B
    ON
    A.LOC =B.LO
    AND A.SITE =B.SITE
    WHERE
    A.CLASS ='CUSTOMER'
    AND A.PLUSSISGIS =1;

    What is your 4 digit Oracle version?
    Try rewriting the query to not use ANSI SQL92 joins. I found a link where this solved a problem similar to yours.
    DBLink problem ORA-22992
    >
    But, look at this curious thing: I re-write the query as follows:
    SELECT A.ID, A.ID_REF, A.EVENDATE, B.DESCRIPTION
    FROM A@ORCL A, B@ORCL B
    WHERE A.ID_REF = B.ID_REF;
    and it works fine... It seems like Oracle don't like the ANSI SQL92...
    >
    Several similar links by googling: 'SQL Error: ORA-22992'
    http://www.dbuggr.com/smallwei/solution-error-ora-22992-lob-locators-selected-remote-tabl/
    >
    Fixing ORA-22992 “cannot use LOB locators selected from remote tables” error
    You have migrated your Oracle 9i database to 10g and a distributed statement which worked fine in 9i now is getting error ORA-22992 “cannot use LOB locators selected from remote tables”. Even though the related remote table(s) does not contain any LOB column datatype.
    FIX:
    There is a bug on 9i,10g, and 11g that is related to this error. It is being fixed in 11.2. It can also be backported for previous 9i, 10g and 11g releases under the latest patchsets.
    You may also do a workaround as follow:
    Modify the affected SQL by adding the TO_CHAR function. For example:
    -- Original SQL:
    SELECT NVL2('a', 'b','c' ) FROM dual@remote_db;
    -- Modified SQL:
    SELECT TO_CHAR(NVL2('a','b','c')) FROM dual@remote_db;
    >
    See if that helps.

  • CASE STATEMENT ERRORS

    Hi all,
    I have created a PLSQL code which is as follows:
    create or replace procedure case_statement is
    pi constant number(9, 7) := 3.1415927;
    area number(14, 2);
    cursor rad_cursor is
    select * from radius_vals;
    rad_val rad_cursor%rowtype;
    begin
    open rad_cursor;
    loop
    fetch rad_cursor
    into rad_val;
    exit when rad_cursor%notfound;
    area := pi * power(rad_val.radius, 2);
    case
    when rad_val.radius = 3 then
    insert into areas_case values (rad_val.radius, area);
    when rad_val.radius = 4 then
    insert into areas_case values (rad_val.radius, area);
    when rad_val.radius = 10 then
    insert into areas_case values (0, 0);
    else
    raise CASE_NOT_FOUND;
    end case;
    end loop;
    close rad_cursor;
    end case_statement;
    When I execute this code I get these error messages:
    ORA - 06592: CASE not found while executing CASE statement.
    ORA - 06512: at "SCOTT.CASE_STATEMENT" line 24
    ORA - 06512: at line 3
    How do I resolve this problem?

    How do I resolve this problem? Well your code raise CASE_NOT_FOUND in the else clause. So either do something different rad_val.radius is not equal to any of the tested values or give your code an exception handler.
    Cheers, APC

  • Case Statement Error - Need help

    What's wrong with this case statement
    Case When Opportunity."Probability %" = '0' then "- Product Revenue"."Product Revenue (000)" *( Opportunity."Probability %" / 100) else "- Product Revenue"."Product Revenue (000)" *( "Opportunity - Product"."Probability %" / 100) end if
    I am getting an error when I place this in a pivot table

    Disregard, it is working now

Maybe you are looking for

  • How can i output a voltage on PCI-6229 port with visual basic 6 ?

    Hello, PCI-6229 card is using DAQmx, that not support VB 6 officially. However, members of this forum found out a way to write/read on digital port with vb6 and DAQmx. This was working well for me indeed. Then, i wanted to output a voltage on AO. I f

  • Pie chart  display error

    Hi I created pie chart using CFCHART tag. In the chart display, data values overlap on one another in the display. How to rectify this error. Kindly help me in this regard. Advance thanks

  • Data Activation with Visa Gift Card?

    Tried to activate my iPads data plan with a visa gift card and I got an email saying that it had been declined. I have checked the balance and I have sufficient funds on the gift card to cover the data plan.

  • Suddenly unable to compile glib2 for mingw32

    I maintain the mingw32-glib2-* packages in AUR and after modifying the PKGBUILD for mingw32-glib2 (conforming to MinGW PKGBUILD guidelines and properly quoting URLs/paths), I find myself unable to compile it fully, with the following error: Traceback

  • Recovering lost iTunes library

    My husband is a PC and I am a MAC. He has lost his entire iTunes music library from his PC, after making a purchase from iTunes Store. His library is still on his iPod. The message says his iPod is synched with another computer. He has never plugged