Newbie Can I have an "IF Statement" in a WHERE clause?

Example
Select T.name,T.District,T.Dept
from table T
where IF myUnit=9998 THEN
T.District='OZ'
ELSIF myUnit=9997 THEN
T.District='DE'
ELSE
T.Dept=myUnit
END IF;
( myUnit is a variable selected by the user)
TIA
Steve

test@ora>
test@ora> --
test@ora> with t as (
  2    select 'a0' name, '0Z' district, 9990 dept, 9998 myunit from dual union all
  3    select 'a1', 'XX', 9999, 9998 myunit from dual union all
  4    select 'a2', 'DE', 9998, 9997 myunit from dual union all
  5    select 'a3', 'YY', 9997, 9997 myunit from dual union all
  6    select 'a4', 'YY', 9999, 9999 myunit from dual union all
  7    select 'a5', 'YY', 9992, 9999 myunit from dual)
  8  --
  9  Select
10    T.name,
11    T.District,
12    T.Dept,
13    t.myunit
14  from T
15  where
16    case myUnit
17      when 9998 then T.District
18      when 9997 then T.District
19      else to_char(myUnit)
20    end =
21    case myUnit
22      when 9998 then '0Z'
23      when 9997 then 'DE'
24      else to_char(T.Dept)
25    end
26  ;
NAME                           DI       DEPT     MYUNIT
a0                             0Z       9990       9998
a2                             DE       9998       9997
a4                             YY       9999       9999
test@ora>
test@ora>isotope

Similar Messages

  • I have 3 i phones.  Can I have multiple accounts on one computer where it keeps the contacta and calendar for each?

    I have 3 i phones.  Can I have multiple accounts on one computer where it keeps the contacta and calendar for each?

    My daughter and I both have iphones. I created an account (not separate itunes) for her on my computer so she could sync her phone/itunes but not have it interfere with mine since we have WAY different taste in music. Creating a different computer profile should work if you have separate itunes accounts, too.
    If you all use the same itunes account, you can turn on Home Sharing. That way you can all download the same content without having to pay for it again. Not sure how or if that works with separate itunes accounts.
    Hope that helps!

  • Query Tuning - using CASE statement in the WHERE clause

    Hi All,
    My query has been modified to use a CASE statement in the WHERE clause to consider data from certain columns based on a parameter value. This modified query is doing a full table scan and running endlessly. Please suggest what may be done to improve its performance:
    Query:
    SELECT LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))) AS summary_date,
    os.acctnum,
    os.avieworigin_refid,
    COUNT(1) cnt_articleview,
    SUM(NVL(autocompletedterm,0)) cnt_autocompletedterm
    FROM TABLE1 os
    WHERE os.acctnum IS NOT NULL
    AND os.avieworigin_refid IS NOT NULL
    AND os.requestdatetime IS NOT NULL
    AND UPPER(os.success_ind) = 'S'
    AND CASE WHEN
    Param_ValueToCheck  = 'FULL' AND get_date_timestamp(os.requestdatetime)  BETWEEN
    TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
    TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    THEN 1
    WHEN
    Param_ValueToCheck  = 'INCR' AND os.entry_createddate  BETWEEN
    TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
    TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    THEN 1
    END = 1
    AND CASE WHEN
    Param_ValueToCheck  = 'FULL' AND os.entry_CreatedDate BETWEEN
    TO_DATE('01-APR-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
    TO_DATE('07-JUN-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    THEN 1
    WHEN
    Param_ValueToCheck  = 'INCR' THEN 1
    END = 1
    GROUP BY LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))), os.acctnum,os.avieworigin_refid;Table Description:
    (Number of rows : approx > 600,000,000)
    Name                           Null     Type      
    ARTICLEID                      NOT NULL NUMBER(20)
    USERKEY                                 NUMBER(10)
    AVIEWORIGIN_REFID                       VARCHAR2(10)
    SUCCESS_IND                             VARCHAR2(2)
    ENTRY_CREATEDDATE                       DATE      
    CREATED_BY                              VARCHAR2(10)
    FILENUMBER                              NUMBER(10)
    LINENUMBER                              NUMBER(10)
    ACCTNUM                                 VARCHAR2(10)
    AUTOCOMPLETEDTERM                       NUMBER(2) 
    REQUESTDATETIME                         VARCHAR2(19)Explain Plan
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 2224314832
    | Id  | Operation            | Name              | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT     |                   |   590 | 33040 |  2501K  (1)| 08:20:15 |       |       |
    |   1 |  HASH GROUP BY       |                   |   590 | 33040 |  2501K  (1)| 08:20:15 |       |       |
    |   2 |   PARTITION RANGE ALL|                   |   590 | 33040 |  2501K  (1)| 08:20:15 |     1 |1048575|
    |*  3 |    TABLE ACCESS FULL | TABLE1 |   590 | 33040 |  2501K  (1)| 08:20:15 |     1 |1048575|
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
       3 - filter(UPPER("OS"."SUCCESS_IND")='S' AND CASE  WHEN ('FULL'='FULL' AND
                  "OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-04-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
                  "OS"."ENTRY_CREATEDDATE"<=TO_DATE(' 2011-06-07 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN
                  'FULL'='INCR' THEN 1 END =1 AND "OS"."REQUESTDATETIME" IS NOT NULL AND CASE  WHEN ('FULL'='FULL'
                  AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")>=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd
                  hh24:mi:ss') AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")<=TO_DATE(' 2011-05-31 00:00:00',
                  'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN ('FULL'='INCR' AND "OS"."ENTRY_CREATEDDATE">=TO_DATE('
                  2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE('
    PLAN_TABLE_OUTPUT
                  2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 END =1 AND "OS"."ACCTNUM" IS NOT NULL AND
                  "OS"."AVIEWORIGIN_REFID" IS NOT NULL)Edited by: Chaitanya on Jun 9, 2011 2:44 AM
    Edited by: Chaitanya on Jun 9, 2011 2:47 AM

    Hi Dom,
    Modified Query:
    SELECT LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))) AS summary_date,
    os.acctnum,
    os.avieworigin_refid,
    COUNT(1) cnt_articleview,
    SUM(NVL(autocompletedterm,0)) cnt_autocompletedterm
    FROM TABLE1 os
    WHERE os.acctnum IS NOT NULL
    AND os.avieworigin_refid IS NOT NULL
    AND os.requestdatetime IS NOT NULL
    AND UPPER(os.success_ind) = 'S'
    AND (('FULL'  = 'FULL'
    AND  (get_date_timestamp(os.requestdatetime)  BETWEEN TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
                   AND TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    AND   os.entry_CreatedDate BETWEEN TO_DATE('01-APR-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
                   AND TO_DATE('07-JUN-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    OR ('FULL'  = 'INCR'
    AND os.entry_createddate  BETWEEN TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
                   AND TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') ))
    GROUP BY LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))), os.acctnum,os.avieworigin_refid;Execute Plan:
    PLAN_TABLE_OUTPUT
    Plan hash value: 3615447714
    | Id  | Operation                 | Name              | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT          |                   | 25125 |  1374K|       |   407K  (1)| 01:21:36 |       |       |
    |   1 |  HASH GROUP BY            |                   | 25125 |  1374K|  3768K|   407K  (1)| 01:21:36 |       |       |
    |   2 |   PARTITION RANGE ITERATOR|                   | 25125 |  1374K|       |   407K  (1)| 01:21:32 |    29 |    31 |
    |*  3 |    TABLE ACCESS FULL      | TABLE1 | 25125 |  1374K|       |   407K  (1)| 01:21:32 |    29 |    31 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
       3 - filter("OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-04-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
                  UPPER("OS"."SUCCESS_IND")='S' AND "OS"."REQUESTDATETIME" IS NOT NULL AND
                  "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")>=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
                  "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")<=TO_DATE(' 2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
                  "OS"."ACCTNUM" IS NOT NULL AND "OS"."AVIEWORIGIN_REFID" IS NOT NULL AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE('
                  2011-06-07 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))Edited by: Chaitanya on Jun 9, 2011 4:51 AM

  • Query Tuning - using CASE statement in the WHERE clause - Duplicate Post

    Duplicate Post by mistake.
    Please check
    Query Tuning - using CASE statement in the WHERE clause
    Edited by: Chaitanya on Jun 9, 2011 2:45 AM
    Edited by: Chaitanya on Jun 9, 2011 2:46 AM

    Duplicate Post by mistake.
    Please check
    Query Tuning - using CASE statement in the WHERE clause
    Edited by: Chaitanya on Jun 9, 2011 2:45 AM
    Edited by: Chaitanya on Jun 9, 2011 2:46 AM

  • Forums module can you have a logging user return to where they were?

    If a non-logged in user is looking at forums topics and finds one they want to comment on. They are asked to log in but are jumped into the general secure zones user area. How can you have them return to the forum topic they were on? I have used a hack to give them a button to return to the page they were on but it only works 50-50 as the trick goes back to a page in a state before they were logged in so the browser doesn't always see them as logged in.
    My litte button script is below that just uses the browser history.  Any help would be great.
    I heard there is a tutorial in bcgurus i might look at later but if there is anything out there besides that I am all ears.    Retun to the Page I was at.                     Go BackGo back to where you were when you logged in.

    Does anyone have any advice for this? So far not having any luck.

  • Case Statement in a Where clause help

    Oracle Database 11g Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    "CORE     11.2.0.1.0     Production"
    TNS for Linux: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    Hello,
    I have an APEX application that I need to build a SQL statement for a LOV (List of Values). I have a hidden filed that contains the customer type which can be an 'R' or 'B'. The query needs to be able to display two different result sets based on the customer type of 'R' or 'B'.
    If the customer type is 'R' then:
    SELECT drg_descr d, drg_code r
    FROM distance_ranges
    WHERE  drg_min_miles IN (0,5)
    ORDER BY drg_min_milesIf the customer type is 'B' then:
    SELECT drg_descr d, drg_code r
    FROM distance_ranges
    WHERE  drg_min_miles IN (0,5,10,15,20)
    ORDER BY drg_min_milesCan someone help me with what I think needs to be a case statement?
    Thanks,
    Joe

    Hi,
    You can try CASE statement with WHERE clause
    SELECT drg_descr d, drg_code r
    FROM distance_ranges
    WHERE (CASE param_cust_type
    WHEN(param_cust_type='R') THEN (drg_min_miles IN (0, 5)
    WHEN (param_cust_type='B') THEN (drg_min_miles IN (0,5,10,15,20)
    END;
    Please try and let me know if anything wrong.
    Anyone from the forum comment my code if there is any wrong.
    Thanks!
    Naresh

  • Can pipelined functions' return values be used in WHERE clause?

    If I have function MY_FUNC that returns a REFCURSOR with columns COL1, COL2, COL3
    can I use the values returned in the output cursor in my WHERE clause as well as in the SELECT clause?
    e.g.
    SELECT COL1, COL2, COL3
    FROM TABLE(MY_FUNC(param1, param2))
    WHERE COL1 = 24 AND COL2=25
    Would that be proper SQL?

    Hi,
    SQL> Create OR Replace Package Pkg_Test_ Is
      2 
      3     Type my_typ Is Table Of Number;
      4 
      5     Function fnc_test Return my_typ Pipelined;
      6 
      7  End;
      8  /
    Package created
    SQL> Create OR Replace Package Body Pkg_Test_ Is
      2 
      3     Function fnc_test Return my_typ
      4        Pipelined Is
      5        va_typ my_typ := my_typ();
      6     Begin
      7        For i IN 1 .. 10 Loop
      8           va_typ.Extend;
      9           va_typ(va_typ.Count) := i;
    10           Pipe Row(va_typ(va_typ.Count));
    11        End Loop;
    12        Return;
    13     End;
    14 
    15  End;
    16  /
    Package body created
    SQL> SELECT *
      2    FROM Table(PKG_TEST_.FNC_TEST)
      3   WHERE COLUMN_VALUE > 5
      4  /
    COLUMN_VALUE
               6
               7
               8
               9
              10Regards,
    Christian Balz

  • [Beginer] How can I have follow the stat of rsync

    Dear All,
    I working hard to make my firts backup script with Apple script.
    I have a rsync command which copy the file from a place toenother one.
    While the rsync process is running, I would like to have the % of the process in order to let the user to know where is the state.
    Is there a way to do it and how?
    I can use somethink else than rsync, but be aware that I ahev to use smb protocole because my data are synchronized from Apple to Linux or Windows server.
    Any suggestion?
    Cheers
    Pierre

    There's no direct way to get the progress of your rsync command - once AppleScript calls the do shell script command it has no visibility into what that command is doing until it's finished.
    There is one workaroud, but it takes some effort. You can execute the shell command in the background - this passes control back to your AppleScript while the shell command is still running. In addition, you can redirect the output of the shell command to a file and your AppleScript can read that file to determine the progress of the command. It's not trivial to do, but it's about the only option you have.
    -- run the command
    set thePID to do shell script "/path/to/lengthy/process &> /var/tmp/my.out & echo $!"
    -- grab its ID
    set processIsRunning to true
    -- repeat while it's running
    repeat until processIsRunning is false
              tell application "System Events"
                        try
      -- if this works, the process is still running
                                  do shell script "ps -p " & thePID
      -- so grab the last line of the output file
                                  set progress to last paragraph of (read POSIX file "/private/var/tmp/my.out")
                        on error
      -- if we get here the process isn't running, so clean up
                                  set processIsRunning to false
                                  do shell script "rm /var/tmp/my.out"
                        end try
              end tell
      -- show the output
      display dialog progress
    end repeat

  • Can I have a SQL statement in a Custom Function in Crystal Reports 2008

    I'd like to create a custom Crystal Reports function which does a database lookup. Is this possible? In the pseudo code below "v_le_afe_xref" is a dataource in the report.  A syntax check fails on the select.
    Function legal_entity_co (old_co AS number) AS number
    SELECT v_le_afe_xref.NEW_BURKS FROM v_le_afe_xref WHERE old_co = v_le_afe_xref.OLD_BURKS
    END FUNCTION
    Thanks.

    Hi David,
    Not sure where you are trying to use the function but CR doesn't support Functions directly, this changes so try Service PAck 3 to see if it's been added. Try using a SQLExpression, and do not include a SELECT in the SQL or using a Command Object.
    You may be able to define it on the server and then call it from CR using a Command also.
    Thank you
    DOn

  • How can i use the internal table as a WHERE clause ?

    Dear Support ,
    I have one internal table that save the material information ...
    data : begin of itab ,
              matnr like mara-matnr ,
    end of itab .
    And now i want to fetch the material desription text base on this internal table .
    As i know that the "FOR ALL ENTRIES" statement is not allowed us to use "IN" this keyword ....
    So , Has another solution for this case ? I don't want to use "LOOP AT ...." this way ...
    Many thanks .
    Carlos

    Why can't you do
    SELECT MATNR MAKTX INTO TABLE ITAB2 FROM MAKT FOR ALL ENTRIES IN ITAB WHERE MATNR = ITAB-MATNR.

  • How do I use the CASE statement  in the where clause?

    Hello Everyone,
    I have 2 queries that do what I need to do but I am trying to learn how to use the CASE statement.
    I have tried to combine these 2 into one query using a case statement but don't get the results I need.
    Could use some help on how to use the case syntax to get the results needed.
    thanks a lot
    select segment_name,
    product_type,
    count (distinct account_id)
    FROM NL_ACCT
    where
    ind = 'N'
    and
    EM_ind = 'N'
    and product_type in ('TAX','PAY')
    and acct_open_dt between (cast('2006-01-17' as date)) and (cast('2006-01-17' as date) + 60)
    GROUP BY 1,2
    order by product_type
    select segment_name,
    product_type,
    count (distinct account_id)
    FROM NL_ACCT
    where
    ind = 'N'
    and
    EM_ind = 'N'
    and product_type not in ('TAX','PAY')
    and acct_open_dt between (cast('2006-01-17' as date)) and (cast('2006-01-17' as date) + 30)
    group by 1,2
    order by product_type

    Something like:
    SELECT segment_name, product_type,
           SUM(CASE WHEN account_id IN ('TAX','PAY') and
                         acct_open_dt BETWEEN TO_DATE('2006-01-17', 'yyyy-mm-dd') and
                               TO_DATE('2006-01-17', 'yyyy-mm-dd') + 60 THEN 1
                    ELSE 0 END) tax_pay,
           SUM(CASE WHEN account_id NOT IN ('TAX','PAY') and
                         acct_open_dt BETWEEN TO_DATE('2006-01-17', 'yyyy-mm-dd') and
                               TO_DATE('2006-01-17', 'yyyy-mm-dd') + 30 THEN 1
                    ELSE 0 END) not_tax_pay
    FROM NL_ACCT
    WHERE ind = 'N' and
          em_ind = 'N' and
          acct_open_dt BETWEEN TO_DATE('2006-01-17', 'yyyy-mm-dd') and
                               TO_DATE('2006-01-17', 'yyyy-mm-dd') + 60
    GROUP BY segment_name, product_type
    ORDER BY product_typeNote: You cannor GROUP BY 1,2, you need to explicitly name the columns to group by.
    HTH
    John

  • ITunes 10 how can I have iTunes recognise an external harddrive

    iTunes 10 how can I have iTunes recognise an external harddrive, where all my music is already. I did the option, selecting extenal HD but some reason the iTunes does not alow me to select the .xml file (grayed out)

    Use Migration Assistant in the Utitiies folder to return the deleted user account back to the machine, I don't know exactly how to go about this as I don't  use TimeMachine as it's so limiting, but Pondini can help
    http://pondini.org/TM/Troubleshooting.html
    You might have to create the account with the same name, but I don't know if it will access the user files on the TM drive or not.
    Once the account is back onto the machine you can log into it and transfer files between accounts on the same machine using the Finder > Go to Computer > Macintosh HD > Users > other account > Public > DropBox and drop files/folders in there, the permissions will change to the other user and the files/folders will be there when you log into the other user account.
    Next time consider bootable clones, you can access them directly and even boot directly from them, update them when your ready and make as many as you need, create clones from clones even.
    Most commonly used backup methods

  • Using if logic in the where clause of a select statement

    I have a select clause. And in the select clause there is a variable all_off_trt that can be 'Y' or 'N'.
    In the where clause I want to make it so that if a form variable is checked and all_off_trt is 'Y' then
    exclude it else if the form variable isn't checked then select it no matter what all_off_trt is.
    Is there any way to include either and if statement or a case statement within the where clause to acheive this? If not is there another way of doing it?
    Basically I am looking for a case statement like this
    case
    when all_off_trt = 'Y' and mail_para.code = 'Y' then false
    else true
    end
    Message was edited by:
    Tugnutt7

    Ok, so that really doesn't solve my problem. I have 3 different fields that I need to do that with. Each combining in a select statement to print an email list, as well as other thing limiting the where clause.
    This is currently what I have, tested and working 100%.
    cursor email_cur is
         select unique p.email,s.all_off_trt,s.all_deceased,s.no_enroll
    from participant p, trialcom t, ethics s
    where p.status='A'
    and p.surname=t.surname
    and p.initials=t.initials
    and s.trial_cd = t.tricom
    and s.centre = t.centre
    and p.email is not null
    and (t.centre in (select code from mail_parameters where user_name=user and mail_para='CENTRE')
    or 'XX' in (select code from mail_parameters where user_name=user and mail_para='CENTRE'))
    and (t.tricom in (select code from mail_parameters where user_name=user and mail_para='TRIAL')
    or 'XX' in (select code from mail_parameters where user_name=user and mail_para='TRIAL'))
    and (t.role in (select code from mail_parameters where user_name=user and mail_para='ROLE')
    or 'XX' in (select code from mail_parameters where user_name=user and mail_para='ROLE'))
    and (p.country in (select code from mail_parameters where user_name=user and mail_para='COUNTRY')
    or 'XX' in (select code from mail_parameters where user_name=user and mail_para='COUNTRY'))
    and (t.represent in (select code from mail_parameters where user_name=user and mail_para='REPRESENT')
    or 'XX' in (select code from mail_parameters where user_name=user and mail_para='REPRESENT'));
    This is in a program unit that runs when a button is clicked. At the end of that I need to add on the 3 case statements that help further narrow down the selection of emails to be printed. Then it prints the emails selected from this statement into a file. So it has to be done right in the select statement. The three table variables are the all_off_trt, all_deceased, and no_enroll. The form has 3 checkboxes. One for each, that when checked (giving the variable associated with the checkboxes a value of 'Y') excludes all emails that have a 'Y' in the coresponding table variable.

  • Using case when statement or decode stament in where clause

    hi gems..
    i have a problem in the following query..
    i am trying to use case when statement in the where clause of a select query.
    select cr.customer_name || ' - ' ||cr.customer_number as cust_name,
    cr.salary as salary
    from customer_details cr
    where (case when '>' = '>' then 'cr.salary > 5000'
    when '>' = '<' then 'cr.salary < 5000'
    when '>' = '=' then 'cr.salary = 5000'
    else null
    end);
    the expression in the when clause of the case-when statement will come from UI and depending on the choice i need to make the where clause.
    thats why for running the query, i have put '>' in that place.
    so the original query will look like this(for your reference):
    select cr.customer_name || ' - ' ||cr.customer_number as cust_name,
    cr.salary as salary
    from customer_details cr
    where (case when variable = '>' then 'cr.salary > 5000'
    when variable = '<' then 'cr.salary < 5000'
    when variable = '=' then 'cr.salary = 5000'
    else null
    end);
    so, in actual case,if the user selects '>' then the filter will be "where cr.salary > 5000"
    if the user selects '<' then the filter will be "where cr.salary < 5000"
    if the user selects '=' then the filter will be "where cr.salary = 5000"
    but i am getting the error "ORA 00920:invalid relational operator"
    please help..thanks in advance..

    Hi,
    select cr.customer_name || ' - ' ||cr.customer_number as cust_name,
           cr.salary                                      as salary
    from customer_details cr
    where (    v_variable = 'bigger'
           and cr.salary > 5000
       or (    v_variable = 'less'
          and cr.salary < 5000
       or (    v_variable = 'eq'
            and cr.salary = 5000
           )Edited by: user6806750 on 22.12.2011 14:56
    For some reason I can't write in sql '<', '>', '='

  • UPDATE Statement executing for whole table even when WHERE Clause is presen

    Hi Friends,
    I have a problem in a stored procedure where i have written an update statement with a where clause. At a time only one row should get updated depending upon unique identifier in where clause.
    But whats happening is that Update statement is getting executed for all the rows in the table neglecting the WHERE clause. I am not getting the clue as to why this is happening. Here is the stored Procedure And the update statement is in BOLD :-
    CREATE OR REPLACE PROCEDURE MDMADM.proc_MDM_InsertCntryDetails
    CntryMasterCode IN VARCHAR2,
    CntryName IN VARCHAR2,
    MDMUser IN VARCHAR2,
    Exist IN INTEGER,
    status IN VARCHAR2,
    Inserted_By IN VARCHAR2 DEFAULT NULL,
    Modified_By IN VARCHAR2 DEFAULT NULL,
    Mdm_Code IN NUMBER DEFAULT 0,
    Action IN VARCHAR2 DEFAULT 'add',
    XGenAttNames IN VARCHAR2 DEFAULT NULL,
    XGenAttValues IN VARCHAR2 DEFAULT NULL,
    MirusAttNames IN VARCHAR2 DEFAULT NULL,
    MirusAttValues IN VARCHAR2 DEFAULT NULL,
    GenisysAttNames IN VARCHAR2 DEFAULT NULL,
    GenisysAttValues IN VARCHAR2 DEFAULT NULL,
    XGenModify IN VARCHAR2 DEFAULT NULL,
    MirusModify IN VARCHAR2 DEFAULT NULL,
    GenisysModify IN VARCHAR2 DEFAULT NULL
    IS
    strSQLXGen VARCHAR(1000);
    strSQLMirus VARCHAR(1000);
    strSQLGenisys VARCHAR(1000);
    nMaxMDMCode INTEGER;
    ifExist INTEGER;
    NAME: proc_MDM_InsertCntryDetails
    PURPOSE:
    REVISIONS:
    Ver Date Author Description
    1.0 7/3/2009 1. Created this procedure.
    NOTES:
    Automatically available Auto Replace Keywords:
    Object Name: proc_MDM_InsertCntryDetails
    Sysdate: 7/3/2009
    Date and Time: 7/3/2009, 7:11:20 PM, and 7/3/2009 7:11:20 PM
    Username: (set in TOAD Options, Procedure Editor)
    Table Name: (set in the "New PL/SQL Object" dialog)
    BEGIN
    SELECT COUNT(*) INTO ifExist FROM MDM_COUNTRY_MASTER;
    IF ifExist = 0 THEN
    SELECT 1 INTO nMaxMDMCode FROM DUAL;
    ELSE
    SELECT MAX(MDM_CODE)+1 INTO nMaxMDMCode FROM MDM_COUNTRY_MASTER;
    END IF;
    IF Action='add' THEN
    INSERT INTO MDM_COUNTRY_MASTER(MDM_CODE,MDM_MASTER_CODE,MDM_DESCRIPTION,MDM_USER,MDM_EXIST,MDM_STATUS,MDM_ACTION,DAT_INSERT_DATE,DAT_INSERTED_BY)
         VALUES(nMaxMDMCode,CntryMasterCode,CntryName,MDMUser,Exist,status,Action,SYSDATE,Inserted_By);
    strSQLXGen := 'INSERT INTO MDM_COUNTRY_MAPPING(MDM_CODE,SYSTEM_NAME,SYSTEM_CODE,' || XGenAttNames || ',DAT_INSERTED_BY,DAT_INSERT_DATE) ' ||
    'VALUES(' || nMaxMDMCode || ',' || '''' || 'XGen' || '''' || ',1,' || XGenAttValues || ',' || '''' || Inserted_By || '''' || ',SYSDATE)';
    EXECUTE IMMEDIATE strSQLXGen;
    strSQLMirus := 'INSERT INTO MDM_COUNTRY_MAPPING(MDM_CODE,SYSTEM_NAME,SYSTEM_CODE,' || MirusAttNames || ',DAT_INSERTED_BY,DAT_INSERT_DATE) ' ||
    'VALUES(' || nMaxMDMCode || ',' || '''' || 'Mirus' || '''' || ',2,' || MirusAttValues || ',' || '''' || Inserted_By || '''' || ',SYSDATE)';
    EXECUTE IMMEDIATE strSQLMirus;
    strSQLGenisys := 'INSERT INTO MDM_COUNTRY_MAPPING(MDM_CODE,SYSTEM_NAME,SYSTEM_CODE,' || GenisysAttNames || ',DAT_INSERTED_BY,DAT_INSERT_DATE) ' ||
    'VALUES(' || nMaxMDMCode || ',' || '''' || 'Genisys' || '''' || ',3,' || GenisysAttValues || ',' || '''' || Inserted_By || '''' || ',SYSDATE)';
    EXECUTE IMMEDIATE strSQLGenisys;
    ELSE
    UPDATE MDM_COUNTRY_MASTER
    SET MDM_DESCRIPTION=CntryName,DAT_MODIFIED_BY=Modified_By,DAT_MODIFY_DATE=SYSDATE,
    MDM_USER=MDMUser,MDM_ACTION=Action,MDM_STATUS=status,MDM_EXIST=Exist WHERE MDM_CODE=Mdm_Code;
    SELECT COUNT(*) INTO ifExist FROM MDM_COUNTRY_MAPPING WHERE SYSTEM_CODE=1 AND MDM_CODE=Mdm_Code ;
    IF ifExist = 0 THEN
    strSQLXGen := 'INSERT INTO MDM_COUNTRY_MAPPING(MDM_CODE,SYSTEM_NAME,SYSTEM_CODE,' || XGenAttNames || ',DAT_INSERTED_BY,DAT_INSERT_DATE) ' ||
    'VALUES(' || Mdm_Code || ',' || '''' || 'XGen' || '''' || ',1,' || XGenAttValues || ',' || '''' || Modified_By || '''' || ',SYSDATE)';
    EXECUTE IMMEDIATE strSQLXGen ;
    ELSE
    strSQLXGen := 'UPDATE MDM_COUNTRY_MAPPING SET ' || XGenModify || ',DAT_MODIFY_DATE=SYSDATE,DAT_MODIFIED_BY=' || '''' || Modified_By || '''' || ' WHERE MDM_CODE=' || Mdm_Code || ' and SYSTEM_CODE=1' ;
    EXECUTE IMMEDIATE strSQLXGen ;
    END IF;
    SELECT COUNT(*) INTO ifExist FROM MDM_COUNTRY_MAPPING WHERE SYSTEM_CODE=2 AND MDM_CODE=Mdm_Code ;
    IF ifExist = 0 THEN
    strSQLMirus := 'INSERT INTO MDM_COUNTRY_MAPPING(MDM_CODE,SYSTEM_NAME,SYSTEM_CODE,' || MirusAttNames || ',DAT_INSERTED_BY,DAT_INSERT_DATE) ' ||
    'VALUES(' || Mdm_Code || ',' || '''' || 'Mirus' || '''' || ',2,' || MirusAttValues || ',' || '''' || Modified_By || '''' || ',SYSDATE)';
    EXECUTE IMMEDIATE strSQLMirus ;
    ELSE
    strSQLMirus := 'UPDATE MDM_COUNTRY_MAPPING SET ' || MirusModify || ',DAT_MODIFY_DATE=SYSDATE,DAT_MODIFIED_BY=' || '''' || Modified_By || '''' || ' WHERE MDM_CODE=' || Mdm_Code || ' and SYSTEM_CODE=2' ;
    EXECUTE IMMEDIATE strSQLMirus ;
    END IF;
    SELECT COUNT(*) INTO ifExist FROM MDM_COUNTRY_MAPPING WHERE SYSTEM_CODE=3 AND MDM_CODE=Mdm_Code;
    IF ifExist = 0 THEN
    strSQLGenisys := 'INSERT INTO MDM_COUNTRY_MAPPING(MDM_CODE,SYSTEM_NAME,SYSTEM_CODE,' || GenisysAttNames || ',DAT_INSERTED_BY,DAT_INSERT_DATE) ' ||
    'VALUES(' || Mdm_Code || ',' || '''' || 'Genisys' || '''' || ',3,' || GenisysAttValues || ',' || '''' || Modified_By || '''' || ',SYSDATE)';
    EXECUTE IMMEDIATE strSQLGenisys ;
    ELSE
    strSQLGenisys := 'UPDATE MDM_COUNTRY_MAPPING SET ' || GenisysModify || ',DAT_MODIFY_DATE=SYSDATE,DAT_MODIFIED_BY=' || '''' || Modified_By || '''' || ' WHERE MDM_CODE=' || Mdm_Code || ' and SYSTEM_CODE=3' ;
    EXECUTE IMMEDIATE strSQLGenisys ;
    END IF;
    END IF;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    NULL;
    WHEN OTHERS THEN
    -- Consider logging the error and then re-raise
    RAISE;
    END proc_MDM_InsertCntryDetails;
    Thanks

    It might be helpful to search this forum and google for PL/SQL (variables, stored procs, etc) naming standards. There are quite a few out there and you can choose one that works for you.
    As an example, a lot of standards adopt naming prefixes, ie v_ for VARCHAR variable, n_ for NUMBER variable, pv_ for paramater VARCHAR, etc.

Maybe you are looking for

  • OSB - configuration project deploy error

    Hi! I got an error message when i wanted to deploy a configuration project to OSB: Permission denied Failed to create temporary jar file The OSB works in Linux. I had got problems with permissions of OSB file folder in Linux. I solved these (the orac

  • How to force a re-calculation of a formula (pricing)?

    Hello gurus, I'm facing a big problem regarding the use of custom conditions for SAP pricing. We have created a new pricing condition (ZFR1) and binded it to a custom formula, this condition is a percentual, it updates de field KBETR. Everything work

  • How do I cancel the purchased item that I don't want to purchase?

    I only get free games but when it asks me to purchasing updates I cancel it cause I don't want to get it yet but now that it's showing that I purchased something but I don't have the money and I don't want to get it yet.

  • IP reverse lookup slow

    Hi! I�m trying to create a socket by using the constructor new Socket(host, port) where the host can be a hostname like sun.com or a textual representation of an IP. When creating this socket using a textual representation of an IP and the port the j

  • Sleepy Mac Pro - really sleepy!

    My Mac Pro just goes to sleep constantly works fine for 30min then sleeps every 2 to 5 min. So maybe my Mac Pro is just old and needs to be retired but nobody can find a solution or even a reason why this happens. Energy Saver settings are to 'Never'