Can we write case statement

Hi,
Can we write CASE statement in Where clause of select statement...
I searched on net, i found that case statement can be written in the having clause..
But how about in the where clause....

You could have easily tried it.
sql> with mytab as
  2  (select 1 col1, 'one' col2 from dual
  3  union all
  4  select 2 col1, 'two' col2 from dual
  5  )
  6  select * from mytab
  7  where (case when col1 = 1 then col2
  8             else 'dummy' end) = 'one';
      1 one

Similar Messages

  • Can I use case statements in triggers?

    I created this trigger, it works BUT I don't like those parentheses at the begining, I would like
    to change those parentheses for case statements, well that is my question, can you use case statements in triggers, how you would translate the following in case statement?
    FOR EACH ROW
    WHEN ( (new.sgbstdn_levl_code = 'UG')
    and
    ( (NEW. SGBSTDN_STST_CODE NOT IN ('GR','SA','AS','IS') )
    OR
    ( (NEW. SGBSTDN_STST_CODE = 'IS' ) AND
    (NEW. SGBSTDN_STYP_CODE IN ('N' , 'T' )) AND
    (OLD. SGBSTDN_STST_CODE = 'AS' ) ) ) )
    ==================================================================================================
    CREATE OR REPLACE TRIGGER CC_STUD_WITHDRAWAL
    AFTER UPDATE OR INSERT ON SATURN . SGBSTDN
    FOR EACH ROW
    WHEN ( (new.sgbstdn_levl_code = 'UG')
    and
    ( (NEW. SGBSTDN_STST_CODE NOT IN ('GR','SA','AS','IS') )
    OR
    ( (NEW. SGBSTDN_STST_CODE = 'IS' ) AND
    (NEW. SGBSTDN_STYP_CODE IN ('N' , 'T' )) AND
    (OLD. SGBSTDN_STST_CODE = 'AS' ) ) ) )
    DECLARE
    v_params gokparm.t_parameterlist;
    event_code gtveqnm.gtveqnm_code%TYPE;
    firstname spriden.spriden_first_name%TYPE;
    lastname spriden.spriden_last_name%TYPE;
    middlename spriden.spriden_mi%TYPE;
    id spriden.spriden_id%TYPE;
    CURSOR get_stud_name IS
    SELECT
    spriden_id ,
    spriden_last_name ,
    spriden_first_name ,
    spriden_mi
    FROM
    saturn.spriden
    WHERE spriden_pidm = :NEW.SGBSTDN_PIDM
    AND spriden_change_ind IS NULL;
    BEGIN
    IF goksyst . f_isSystemLinkEnabled ( 'WORKFLOW' ) THEN
    event_code := SUBSTR ( gokevnt.F_CheckEvent ( 'WORKFLOW' ,'CC_STUDENT_WITHDRAW' ),1,20);
    OPEN get_stud_name ;
    FETCH get_stud_name INTO id , lastname , firstname , middlename ;
    CLOSE get_stud_name ;
    ----pass parameters to the event
    v_params ( 1 ).param_value := 'CC_STUDENT_WITHDRAW' ;
    v_params ( 2 ).param_value := '' ;
    v_params ( 3 ).param_value := 'Student Withdrawal:' || lastname || ',' || firstname || ' ' ||
    middlename ;
    v_params ( 4 ).param_value := :NEW.sgbstdn_pidm ;
    v_params ( 5 ).param_value := id ;
    v_params ( 6 ).param_value := lastname ;
    v_params ( 7 ).param_value := firstname ;
    v_params ( 8 ).param_value := middlename ;
    v_params ( 9 ).param_value := :NEW.sgbstdn_term_code_eff ;
    v_params ( 10 ).param_value := :NEW.SGBSTDN_STST_CODE ;
    v_params ( 11 ).param_value := :NEW.SGBSTDN_STYP_CODE ;
    gokparm.Send_Param_List ( event_code , v_Params );
    END IF;
    END;
    /

    You could delete a fair number of extraneous parentheses.
    CREATE OR REPLACE TRIGGER cc_stud_withdrawal
      AFTER UPDATE OR INSERT
      ON saturn.sgbstdn
      FOR EACH ROW
      WHEN     NEW.sgbstdn_levl_code = 'UG'
           AND (   NEW.sgbstdn_stst_code NOT IN ('GR', 'SA', 'AS', 'IS')
                OR (    NEW.sgbstdn_stst_code = 'IS'
                    AND NEW.sgbstdn_styp_code IN ('N', 'T')
                    AND OLD.sgbstdn_stst_code = 'AS'))

  • Need help to write case statement

    Hi Guys,
    I have dashboard in which its has pprompt called PROPMT1 in that prompt it has three values A,B,C
    but iwant the full abbreviation of those values like A=APPLE B=BOY and C=Cindy
    and also in the report i have the coloumn is prompted by PROMPT1 which has again A,B,C values that need to be modified as A=APPLE B=BOY and C=Cindy
    how can i do it with case statement.

    For the prompt, write this in the Show window>SQL Results:
    1) CASE WHEN 1=0 THEN char_columnname ELSE 'A = APPLE' END FROM "your subject area" UNION ALL CASE WHEN 1=0 THEN char_columnname ELSE 'B = BOY' END FROM "your subject area" UNION ALL CASE WHEN 1=0 THEN char_columnname ELSE 'C = Cindy' END FROM "your subject area"
    2) Save the prompt to a presentation variable, pv_choice
    This will give you your three values. Make sure you use a CHAR column, doesnt matter what column, though.
    For the report,
    1) Create a BINS column on the column that contains the A, B, C values and make the BINS A = APPLE, B = BOY, C = Cindy just like the prompt values.
    2) Now put a filter on this BINS column and set it equal to your pv_choice presentation variable.
    That's it.
    NOTE: Obviously, if you want the prompt values to just say "APPLE," "BOY," and "Cindy," then take off the 'A = ', 'B = ' and 'C = ' appropriately. Same for the BINS in your report.
    Edited by: David_T on Jun 8, 2011 10:57 AM

  • Can we write function in select statement?

    i have function and it has Out parameter,so in this case can i write select statement for my function to retrieve the value?

    Or, you could use pipelined function - i guess.
    Like ->
    satyaki>
    satyaki>select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    PL/SQL Release 10.2.0.1.0 - Production
    CORE    10.2.0.1.0      Production
    TNS for Linux: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>create or replace type a_obj as object
      2    (
      3       e_nm  varchar2(30),
      4       e_sal number(7,2)
      5    )
      6  /
    Type created.
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>
    satyaki>create or replace type a_rec as table of a_obj;
      2  /
    Type created.
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>create or replace function multi_return(e_cd in number)
      2  return a_rec
      3  pipelined
      4  is
      5    cursor c1
      6    is
      7      select a_obj(ename, sal) as a_det_rec
      8      from emp
      9      where empno = e_cd;
    10     
    11      r1 c1%rowtype;
    12  begin
    13    for r1 in c1
    14    loop
    15      pipe row(r1.a_det_rec);
    16    end loop;
    17  
    18    return ;
    19  end;
    20  /
    Function created.
    Elapsed: 00:00:00.01
    satyaki>
    satyaki>
    satyaki>select * from table(cast(multi_return(&e_no) as a_rec));
    Enter value for e_no: 7369
    old   1: select * from table(cast(multi_return(&e_no) as a_rec))
    new   1: select * from table(cast(multi_return(7369) as a_rec))
    no rows selected
    Elapsed: 00:00:00.02
    satyaki>
    satyaki>
    satyaki>select * from emp;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO JOB1      DOB
          7521 WARD       SALESMAN        7698 22-FEB-81     226.88        500         30 SALESMAN
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1815       1400         30 SALESMAN
          7788 SCOTT      ANALYST         7566 19-APR-87     598.95                    20 ANALYST
          7839 KING       PRESIDENT            17-NOV-81       7260                    10 PRESIDENT
          7844 TURNER     SALESMAN        7698 08-SEP-81       2178          0         30 SALESMAN
          7876 ADAMS      CLERK           7788 23-MAY-87     159.72                    20 CLERK
          7900 JAMES      CLERK           7698 03-DEC-81     1379.4                    30 CLERK
          7902 FORD       ANALYST         7566 03-DEC-81    5270.76                    20 ANALYST
          7934 MILLER     CLERK           7782 23-JAN-82     1887.6                    10 CLERK
          7566 Smith      Manager         7839 23-JAN-82       1848          0         10 Manager   23-JAN-89
          7698 Glen       Manager         7839 23-JAN-82       1848          0         10 Manager   23-JAN-89
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO JOB1      DOB
          7599 BILLY      ANALYST         7566 10-JUN-09       4500                    30
    12 rows selected.
    Elapsed: 00:00:00.01
    satyaki>
    satyaki>select * from table(cast(multi_return(&e_no) as a_rec));
    Enter value for e_no: 7698
    old   1: select * from table(cast(multi_return(&e_no) as a_rec))
    new   1: select * from table(cast(multi_return(7698) as a_rec))
    E_NM                                E_SAL
    Glen                                 1848
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>/
    Enter value for e_no: 7599
    old   1: select * from table(cast(multi_return(&e_no) as a_rec))
    new   1: select * from table(cast(multi_return(7599) as a_rec))
    E_NM                                E_SAL
    BILLY                                4500
    Elapsed: 00:00:00.00
    satyaki>Regards.
    Satyaki De.

  • Can CR 2008 with XML ODBC driver using SQL CASE statement?

    Hi:
    when i use SQL Command to provide data to the report from XML file connection. I can not use CASE statement , CR always has error message about "CASE" word.
    I test the same Statement in SQL client connected to Oracle, it runs fine.
    So.. Is it driver's limitation that XML datasource can not use CASE statement inside SQL command window?
    Thanks anyone's reply in advance.
    Johnnychi

    Hi Johnny,
    CR supports what every the ODBC driver supports. The error you are getting is from the XML driver, CR is just passing it through.
    Try using an ODBC to XML driver and then a stand-alone ODBC test tool to see if your SQL works.
    If not you'll have to find another way to use the CASE statement.
    Thank you
    Don

  • Problem to identify values in a case statement.

    Hi Friends,
    Total number of records in my report should be divided by 5 and to be alloted into 5 grades in Grade column.
    This is what I have done so far in my report with following layout.
    S.No - Col A - Col B - Col C - Grade ( Colums A,B,C will be hidden in Report)
    *****Column C will have only 5 values at max ( 0.0, 0.2, 0.4, 0.6, 0.8).The below example is for 6 records in a report.The same will be applied for 7,8,9,10 records.
    In column A: MAX(cast(RCOUNT(1) AS DOUBLE))/5 ( Ex : 6/5 = 1.2)
    In Column B: Truncate(MAX(cast (RCOUNT(1) as double)/5), 0) ( Ex : 6/5 = 1.0)
    In Column C: Col A- Col B ( EX:1.2 - 1.0 =0.2)
    (MAX(cast(RCOUNT(1) AS DOUBLE))/5 - Truncate(MAX(cast (RCOUNT(1) as double)/5), 0))
    Now In Grade coulum I want to use this column C to Grade the records with case statements in it.
    I am trying to use the following case statement for Grade Coulmn
    Case
    when (MAX(cast(RCOUNT(1) AS DOUBLE))/5 - Truncate(MAX(cast (RCOUNT(1) as double)/5), 0)) = 0.0 then .........
    when (MAX(cast(RCOUNT(1) AS DOUBLE))/5 - Truncate(MAX(cast (RCOUNT(1) as double)/5), 0)) = 0.2 then .............
    when (MAX(cast(RCOUNT(1) AS DOUBLE))/5 - Truncate(MAX(cast (RCOUNT(1) as double)/5), 0)) = 0.4 then .............
    when (MAX(cast(RCOUNT(1) AS DOUBLE))/5 - Truncate(MAX(cast (RCOUNT(1) as double)/5), 0)) = 0.6 then ........
    when (MAX(cast(RCOUNT(1) AS DOUBLE))/5 - Truncate(MAX(cast (RCOUNT(1) as double)/5), 0)) = 0.8 then .....
    end
    Case statement works gud for 0.0 but not for other 4 values.
    It is unable to identify other 4values.
    Please tell me, how can I make case statement work for all values in above scenario.
    Thanks in Advance,
    Varsha.
    Edited by: Varsha on Nov 28, 2010 6:23 PM

    In column A: MAX(cast(RCOUNT(1) AS DOUBLE))/5 ( Ex : 6/5 = 1.2)
    In Column B: Truncate(MAX(cast (RCOUNT(1) as double)/5), 0) ( Ex : 6/5 = 1.0)
    In Column C: Col A- Col B ( EX:1.2 - 1.0 =0.2)
    (MAX(cast(RCOUNT(1) AS DOUBLE))/5 - Truncate(MAX(cast (RCOUNT(1) as double)/5), 0))Change the formula a bit by adding the by dim value for the MAX column.
    Column A: MAX(cast(RCOUNT(1) AS DOUBLE) by DimTable.Column)/5
    Column B: Truncate(MAX(cast (RCOUNT(1) as double) by DimTable.Column)/5, 0)
    Column C: MAX(cast(RCOUNT(1) AS DOUBLE) by DimTable.Column)/5 - Truncate(MAX(cast (RCOUNT(1) as double) by DimTable.Column)/5, 0)
    now write a case statement on top column c, based on your logic every 5th record will have a value 0.0
    Note: Dimtable.column is the table.column for which the row count is taken.
    Thanks,
    Vino

  • ODI - Huge case statement in the join

    Hi all,
    In my main I$ Insert query I have this huge case statement that goes for few pages, I am posting a small sample here. Is there a way I can put this case statement in to some other place like a table or procedure etc., and call it in the main interface, as this makes the query too big and difficult to analyze. Please give me some ideas. Thanks for your time and help.
    FROM MAIN.PERSONS PERSONS
    LEFT JOIN DIM_ONE as DIM_ONE ON (CASE WHEN PERSONS.AGE<21 THEN 35
    WHEN PERSONS.AGE<22 And PERSONS.AGE>=21 THEN 34
    WHEN PERSONS.AGE<23 And PERSONS.AGE>=22 THEN 33
    WHEN PERSONS.AGE<24 And PERSONS.AGE>=23 THEN 32
    WHEN PERSONS.AGE<25 And PERSONS.AGE>=24 THEN 31
    WHEN (PERSONS.AGE<26 And PERSONS.AGE>=25 And PERSONS.YRS_OF_SERVICE>=0) THEN 30
    WHEN (PERSONS.YRS_OF_SERVICE>=0 And PERSONS.YRS_OF_SERVICE<1 And PERSONS.AGE<30 And PERSONS.AGE>=26)THEN 30
    WHEN (PERSONS.AGE>=30 And PERSONS.AGE<31 And PERSONS.YRS_OF_SERVICE<1) THEN 30
    = DIM_ONE.YEARS_CODE

    You can do that in an oracle function with 2 parameters : age and yrs_of_service.
    Then you have to grant "execute" privileges to the schema used to connect to this database (see your dataserver connection in the physical part of the topology).
    Then write your join like this : SCHEMA.MY_FUNCTION(PERSONS.AGE, PERSONS.YRS_OF_SERVICE)
    = DIM_ONE.YEARS_CODE

  • Using Case statement to insert,update,delete  the tables

    Hi All,
    I have to check the databse ,
    if it is developement then
    insert/update/delete values in tables;
    if it staging then
    insert/update/delete values in tables;
    if it is production then
    insert/update/delete values in tables;
    thers is function available to check the current database
    For doing the about i am trying to write CASE statement like this
    SELECT function,
    case
    when fun = 'developement' then insert into table1 values ('abcd','1234')
    when fun = 'staging' then insert into table1 values ('abcd','1234')
    when fun= 'production' then insert into table1 values ('abcd','1234')
    else null
    from dual
    its throughing me an error
    please help
    Thanks,

    Hi,
    You can use CASE staement any place where an expression is expected.
    For example, in:
    UPDATE  table_a
    SET     col1 = exp1
    ,       col2 = exp2
    WHERE   exp3 = exp4;all the expressions are labled lke expn.
    Note that table_a, col1 and col2 are not expressions: you must hard-code these names, or use dynamic SQL.
    So it's okay to say:
    UPDATE  table_a
    SET     col1 = CASE
                       WHEN  db = 'development'  THEN  0
                       WHEN  db = 'staging'      THEN  1
                   END
    ,       col2 = CASE
                       WHEN  db = 'development'  THEN  NULL
                       WHEN  db = 'staging'      THEN  col2
                   END
    WHERE   db != 'production';In this example:
    in the development database, col1 is set to 0 and col2 is set to NULL
    in the staging database, col1 is set to 1 and col2 is unchanged (that is, set to what it already was)
    in the production database, nothing is changed (the WHERE condition is always FALSE)

  • Case statement on Variable SSIS

    Hi friends,
    I have a small issue in my package I would like to write a case statement on Variable or Column in derived column Transformation
    I was using forloop container that pulls the data from different database so the database names also loading into table under one of the column but I wanna load with integer value instead database name
    for example
    Database A -- 1
    Database B -- 2
    so I would like to write a case statement on variable or column but It was not allowing me to write when I tried.
    what I have tried was I took one derived transformation and added one new column and passed that variable to that new column.
    then again I took another derived transformation here I was trying to write case statement on the colum which is belongs to previous derived column.
    Derived Column Tran 1:
    Derived Column Name         Expression                        DataType
    RegionID                           @[User::InitialDB]        Unicodestring[DT_WSTR]
    Derived Column Tran2:
    Can anyone please check and guide me the solution please.
    Thanks for your help

    Hi BandSr,
    You were close, just missing the false part in your second conditional operator.
    [RegionID] == "KAPS" ? "1" : [RegionID] == "LAPS"? "2" : ""
    In fact, I won't call that a Case statement but rather a nested conditional expression.
    Hope this helps.
    ~ J.

  • What is the syntax for a CASE statement in Crystal XI

    I'm having difficulty locating documentation for the use of CASE statements in Crystal syntax. My database administrator does not allow me to write SQL expressions so I need to covert the SQL below to Crystal Syntax. Can anyone help me? Thank you very much!!
    Select
       CASE
             WHEN projects.ProjType like 'S%' then 'Shopping Center'
             WHEN projects.ProjType like 'I%' then 'Industrial'
             WHEN projects.ProjType like 'O%' then 'Office Building'
             ELSE 'Other'
       END
    from projects

    Let's assume column XYZ has both numbers (1), and letters (any alphabet).
    I have a case statement on SQL to turn any value that's not 1 into 0, then I am getting a sum of that column.
    I am also grouping by Row A, B etc to get aggregated sum of column XYZ for those group.
    Now on Crystal Reports function, I need to sum up values under column XYZ for all the groups.
    If I try using sum function like below, I get an error stating:
    "A number field or currency amount field is required here"
    (sum({Command.XYZ}))
    So I thought if I can use a case statement to change the non-numbers to 0 prior to sum that will probably resolve it. But I could not get the below case statement to work either (Error: A string is required). 
    SELECT {Command.XYZ}
       Case 1:
          1 
       Default:
          0;

  • Can possible write as a insert without update

    Hi,
    I'm inserting values of first 5 coulmns like below
    INSERT INTO SS_ITEM_STAT_OPN(
            REP_ID, ITEM_ID, REPORT_COLUMN_DISPLAY, REPORT_COLUMN_SEQ_NO, BEGIN_VALUE, END_VALUE)
            SELECT
            LN_SEQ_REP_ID, ITEM_ID, REPORT_COLUMN_DISPLAY, REPORT_COLUMN_SEQ_NO, BEGIN_VALUE, END_VALUE
            FROM VW_SCALE_SCORE_CONFIG CROSS JOIN REP_ITEM_STAT_OPN
            WHERE REP_ID = LN_SEQ_REP_ID;and i'm updating next 3 columns based on below statement.Can i write insert statement without update.
    FOR LN_SSI_OPN IN NVL(TV_SS_ITEM_STAT_OPN.FIRST,1)..NVL(TV_SS_ITEM_STAT_OPN.LAST,0)
            LOOP
                UPDATE SS_ITEM_STAT_OPN SET
                (TOT_STUD_ITEM_SS,TOT_STUD_CORR_ANS_ITEM_SS ) =  (SELECT COUNT(*) TOT_STUD_ITEM_SS ,
                                                                 Count(Case When RESPONSE_IS_CORRECT = 1 Then 1 End) As TOT_STUD_CORR_ANS_ITEM_SS
                                                                 FROM PSYCHOMETRIC_ITEM_STAT_OPN A, VW_SCALE_SCORE_CONFIG B
                                                                 WHERE    SS_ITEM_STAT_OPN.ITEM_ID=TV_SS_ITEM_STAT_OPN(LN_SSI_OPN).ITEM_ID
                                                                 AND     (SS_ITEM_STAT_OPN.BEGIN_VALUE=TV_SS_ITEM_STAT_OPN(LN_SSI_OPN).BEGIN_VALUE
                                                                 AND    SS_ITEM_STAT_OPN.END_VALUE=TV_SS_ITEM_STAT_OPN(LN_SSI_OPN).END_VALUE)
                                                                  AND     SS_ITEM_STAT_OPN.ITEM_ID = A.ITEM_ID
                                                                  AND SS_ITEM_STAT_OPN.END_VALUE = B.END_VALUE
                                                                  AND ROUND(A.SCALE_SCORE) > BEGIN_VALUE
                                                                  AND ROUND(A.SCALE_SCORE) <= END_VALUE
                                                                  AND CONDITION_COLUMN= 'SCALE_SCORE'
                                                                  GROUP BY ITEM_ID,END_VALUE
                TOT_STUD_SS                 =  NVL((SELECT COUNT(*) FROM
                                                (SELECT A.TEST_SESSION_DETAIL_ID
                                                FROM PSYCHOMETRIC_ITEM_STAT_OPN A, VW_SCALE_SCORE_CONFIG B,SS_ITEM_STAT_OPN
                                                WHERE SS_ITEM_STAT_OPN.ITEM_ID=TV_SS_ITEM_STAT_OPN(LN_SSI_OPN).ITEM_ID
                                                AND     (SS_ITEM_STAT_OPN.BEGIN_VALUE=TV_SS_ITEM_STAT_OPN(LN_SSI_OPN).BEGIN_VALUE
                                                AND    SS_ITEM_STAT_OPN.END_VALUE=TV_SS_ITEM_STAT_OPN(LN_SSI_OPN).END_VALUE)
                                                AND SS_ITEM_STAT_OPN.END_VALUE = B.END_VALUE
                                                AND ROUND(A.SCALE_SCORE) >B.BEGIN_VALUE
                                                AND ROUND(A.SCALE_SCORE) <= B.END_VALUE
                                                AND CONDITION_COLUMN= 'SCALE_SCORE'
                                                AND A.TEST_DETAIL_ID=TV_TEST_DET(LN_TEST_CNT).TEST_DETAIL_ID
                                                GROUP BY A.TEST_SESSION_DETAIL_ID),VW_SCALE_SCORE_CONFIG
                                                WHERE END_VALUE=TV_SS_ITEM_STAT_OPN(LN_SSI_OPN).END_VALUE
                                                GROUP BY END_VALUE),0)
                WHERE    TEST_DETAIL_ID = TV_TEST_DET(LN_TEST_CNT).TEST_DETAIL_ID
                AND     SS_ITEM_STAT_OPN.ITEM_ID=TV_SS_ITEM_STAT_OPN(LN_SSI_OPN).ITEM_ID
                AND     (SS_ITEM_STAT_OPN.BEGIN_VALUE=TV_SS_ITEM_STAT_OPN(LN_SSI_OPN).BEGIN_VALUE
                        AND    SS_ITEM_STAT_OPN.END_VALUE=TV_SS_ITEM_STAT_OPN(LN_SSI_OPN).END_VALUE);
               -- COMMIT;
    end loop;

    have a look at the MERGE statement!
    P;

  • Case statement in where clause ??

    Hello gurus,
    Can we use case statements in where clause ?? Any example will be great!
    And also i would like to know, besides CASE and DECODE statements, Is there any way we can use IF ELSE statements in SELECT clause or in WHERE clause ?
    Thank you!!

    Hi,
    user642297 wrote:
    Hoek,
    Thanks for the reply
    Whatever you return from 'then' should match your criteria.I didnt get this part...can you elaborate this part ?? Thank you!!Remember what a CASE expression does: it returns a single value in one of the SQL data types (or NULL).
    You're probably familiar with conditions such as
    WHERE   col = 1Inthe example above, col could be replaced by any kind of expression: a function call, and operation (such as "d * 24") or a CASE expression, which is exactly what Hoek posted:
    where  case
             when col = 6 then 1
             when col = 9 then 1
           end = 1;I think what Hoek meant about mnatching was this: since the CASE expression is being compared to a NUMBER, then every THEN clause (as well as the ELSE, if there is one) should return the same data type. You can't have one THEN clause return a NUMBER, and another one in the same CASE expression return a DATE, like this:
    where  case
             when col = 6 then 1
             when col = 9 then SYSDATE     -- WRONG! Raises ORA-00932: inconsistent datatypes
           end = 1; 
    By the way, it's rare when a CASE expression really helps in a WHERE clause. CASE is great for doing conitional stuff in places where you otherwise can't (in the ORDER BY clause, for example), but the WHERE clause was designed for conditions.
    Hoek was just trying to give a simple example. If you really wanted those results, it would be simpler to say:
    where  col = 6
    or     col = 9and simpler still to say
    where  col  IN (6, 9)

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

  • How to write select statement directly in java file instead of using vo

    Hi,
    I have written the following code in my java file:
    if(empvo==null)
    empvo=worklistamimpl2.createViewObject("InvoiceVO", "xxetfc.oracle.apps.icx.icatalog.shopping.server.InvoiceVO");
    if(empvo!=null){
    OAViewObject oaviewobject2 = (OAViewObject)worklistamimpl2.findViewObject("InvoiceVO");
    OAViewObjectImpl oaviewobjectimpl = (OAViewObjectImpl)oapagecontext.getApplicationModule(oawebbean).findViewObject("InvoiceVO");
    oaviewobject2.setWhereClause("Invoice_num="+" ' " + s + " ' ");
    oaviewobjectimpl.executeQuery();
    String abc = (String)oaviewobjectimpl.first().getAttribute("Invoice_id");
    It is giving me error as
    oracle.apps.fnd.framework.OAException: oracle.jbo.SQLStmtException: JBO-27122: SQL error during statement preparation. Statement: SELECT * FROM (select invoice_id from ap_invoices_all) QRSLT WHERE (Invoice_num='ERS15022012_3')
    1. Why is this error coming.. how to solve this
    2. Instead of using vo how can i write select statement directly in the above code
    Thanks,
    Edited by: user10873676 on Apr 9, 2012 1:18 AM
    Edited by: user10873676 on Apr 9, 2012 1:21 AM

    it says java.sql.SQLSyntaxErrorException: ORA-00904: "INVOICE_NUM": invalid identifier
    where as invoice_num column is present in my table

  • Evaluation of condition clause in whehe clause using case statement

    Hi,
    I have a scenario where in I have to evaluate two different conditions based on the parameter value. Is it possible to evaluate the conditiond based on the parameter value with case statement in where clause.
    Example:
    select A,B,C,D from X,Y,Z
    where
    cond1 and
    cond2 and
    case when param='T' then cond3 else cond4 end
    Here param is an external parameter passed to the query.
    cond3 is something like Y.deptno in(10,30,50,70)
    cond4 is something like Y.deptno in (20,40,60,70,80,90)
    Your responce will be appriciated.
    Regards,
    Varma

    You can place the case statement as a condition, however it depends what context you want it in, for example;
    this will work:
    1* select 1 from dual where (case when 1=1 then 1 end) = 1 and 2=2
    QL> /
            1
            1but this will not;
    SQL> select 1 from dual where case when 1=1 then 1 end and 2=2;
    select 1 from dual where case when 1=1 then 1 end and 2=2
    ERROR at line 1:
    ORA-00920: invalid relational operatorSo, if you're expecting the condition to evaluate to a true/false, so if you mean soemthing like
    when TRUE, then it won't work!
    P;

Maybe you are looking for

  • I can't see my ipod on desktop or itunes PLEASE HELP!!

    I had to reset my ipod mini and now when I connect it to the computer a pop up message comes up saying "DISK INSERTION, The disk you inserted was not readable by this computer" The options I have are "Initialize" "Ignore" or "Eject" I have itunes ver

  • How to load thousands of data files?

    My database is installed on windows, and I have thousands of data files that I need to load. Trying to figure out how to do it without manually editing my CTL file every time I load one data file. Can you specifiy your control file to load directorie

  • LSMW Error - You have not fully maintained the descriptions

    Hi Experts, I was trying to Extend the materials to plant by using Direct input menthod where prog - RMDATIND. When I execute final step i.e "Start Direct Input Program" I faced with an error " You have not fully maintained the descriptions". I know

  • Custom cell rendering

    I have got a JList. And I am going to create my custom cell renderer which can show a label and a pic inline. How can I do it?

  • Updated to iso 7 now no slide show?

    iPhone 4 updated to ios 7 now there is no slideshow triangle in the photos app. Went to - Settings > Photos & Camera > Slideshow > Play Each Slide For > time is gayed out. I can change the play time 3 to 20 seconds showing blue check mark but time re