Problem with DECODE block in WHERE clause

Hi,
I'm facing problem with DECODE statement. I just simulated my problem in the simple way as follows. If I execute this following query, I should get "hello", but I'm not getting anything (ZERO rows returned).
SELECT 'hello' FROM DUAL
WHERE 'sample1' in (DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',
2, '''sample4'', ''sample5'', ''sample6'''
I think some problem is there in my WHERE clause.
But When I'm exeucting the following query as a seperate query, then I'm getting the value of DECODE block properly, but didn;t understnad why its not returning the same way when I'm putting the same DECODE statement in WHERE clause.
SELECT DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',
2, '''sample4'', ''sample5'', ''sample6'''
FROM DUAL;
Please help me to get out of this problem. Thank you so much in advance.
Thanks,
Ramji.

The value returned by SELECT DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',2, '''sample4'', ''sample5'', ''sample6''') FROM DUAL;
'sample1', 'sample2', 'sample3' is a single string. Consider it x.
SELECT 'hello' FROM DUAL WHERE 'sample1' in ( DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',2, '''sample4'', ''sample5'', ''sample6'''));
is like SELECT 'hello' FROM DUAL WHERE 'sample1' in ('x');
or
SELECT 'hello' FROM DUAL WHERE 'sample1' in ('''sample1'', ''sample2'', ''sample3''') and not
SELECT 'hello' FROM DUAL WHERE 'sample1' in ('sample1', 'sample2', 'sample3');
For this same reason SELECT 'hello' FROM DUAL WHERE 'sample1' in (select '''sample1'', ''sample2'', ''sample3''' from dual);
also does'nt work.
Please use INSTR to find whether 'sample1' exists in the string 'sample1', 'sample2', 'sample3'.

Similar Messages

  • Problem with date fields in where clause after changing driver

    Hi,
    We have changed the oracle driver we use to version 10
    and now we have some trouble with date-fields.
    When we run this SQL query from our Java program:
    select *
    from LA_TRANS
    where LA_TRANS.FROM_DATE>='20040101' AND LA_TRANS.FROM_DATE<='20041231'
    We get this error code:
    ORA-01861: literal does not match format string
    The query worked fine whit the previous driver.
    Is there some way I can run a SQL query with date fields
    as strings in the where clause?
    Thanks!

    Keeping the argument of standard SQL or not aside, comparing DATE columns to a constant string (which looks like a date in one of the thousands of the formats available, but not in others) is NOT one of the best programming practices and leads to heartburn and runtime errors (as you have seen yourself).
    I would rather compare a DATE to a DATE.
    Also, constants like that would be another issue to fix in your code:
    http://asktom.oracle.com/pls/ask/f?p=4950:8:6899751034602146050::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:528893984337,

  • Performance with dates in the where clause

    Performance with dates in the where clause
    CREATE TABLE TEST_DATA
    FNUMBER NUMBER,
    FSTRING VARCHAR2(4000 BYTE),
    FDATE DATE
    create index t_indx on test_data(fdata);
    query 1: select count(*) from TEST_DATA where trunc(fdate) = trunc(sysdate);
    query 2: select count(*) from TEST_DATA where fdate between trunc(sysdate) and trunc(SYSDATE) + .99999;
    query 3: select count(*) from TEST_DATA where fdate between to_date('21-APR-10', 'dd-MON-yy') and to_date('21-APR-10 23:59:59', 'DD-MON-YY hh24:mi:ss');
    My questions:
    1) Why isn't the index t_indx used in Execution plan 1?
    2) From the execution plan, I see that query 2 & 3 is better than query 1. I do not see any difference between execution plan 2 & 3. Which one is better?
    3) I read somewhere - "Always check the Access Predicates and Filter Predicates of Explain Plan carefully to determine which columns are contributing to a Range Scan and which columns are merely filtering the returned rows. Be sceptical if the same clause is shown in both."
    Is that true for Execution plan 2 & 3?
    3) Could some one explain what the filter & access predicate mean here?
    Thanks in advance.
    Execution Plan 1:
    SQL> select count(*) from TEST_DATA where trunc(fdate) = trunc(sysdate);
    COUNT(*)
    283
    Execution Plan
    Plan hash value: 1486387033
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 9 | 517 (20)| 00:00:07 |
    | 1 | SORT AGGREGATE | | 1 | 9 | | |
    |* 2 | TABLE ACCESS FULL| TEST_DATA | 341 | 3069 | 517 (20)| 00:00:07 |
    Predicate Information (identified by operation id):
    2 - filter(TRUNC(INTERNAL_FUNCTION("FDATE"))=TRUNC(SYSDATE@!))
    Note
    - dynamic sampling used for this statement
    Statistics
    4 recursive calls
    0 db block gets
    1610 consistent gets
    0 physical reads
    0 redo size
    412 bytes sent via SQL*Net to client
    380 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    1 rows processed
    Execution Plan 2:
    SQL> select count(*) from TEST_DATA where fdate between trunc(sysdate) and trunc(SYSDATE) + .99999;
    COUNT(*)
    283
    Execution Plan
    Plan hash value: 1687886199
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 9 | 3 (0)| 00:00:01 |
    | 1 | SORT AGGREGATE | | 1 | 9 | | |
    |* 2 | FILTER | | | | | |
    |* 3 | INDEX RANGE SCAN| T_INDX | 283 | 2547 | 3 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    2 - filter(TRUNC(SYSDATE@!)<=TRUNC(SYSDATE@!)+.9999884259259259259259
    259259259259259259)
    3 - access("FDATE">=TRUNC(SYSDATE@!) AND
    "FDATE"<=TRUNC(SYSDATE@!)+.999988425925925925925925925925925925925
    9)
    Note
    - dynamic sampling used for this statement
    Statistics
    7 recursive calls
    0 db block gets
    76 consistent gets
    0 physical reads
    0 redo size
    412 bytes sent via SQL*Net to client
    380 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    1 rows
    Execution Plan 3:
    SQL> select count(*) from TEST_DATA where fdate between to_date('21-APR-10', 'dd-MON-yy') and to_dat
    e('21-APR-10 23:59:59', 'DD-MON-YY hh24:mi:ss');
    COUNT(*)
    283
    Execution Plan
    Plan hash value: 1687886199
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 9 | 3 (0)| 00:00:01 |
    | 1 | SORT AGGREGATE | | 1 | 9 | | |
    |* 2 | FILTER | | | | | |
    |* 3 | INDEX RANGE SCAN| T_INDX | 283 | 2547 | 3 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    2 - filter(TO_DATE('21-APR-10','dd-MON-yy')<=TO_DATE('21-APR-10
    23:59:59','DD-MON-YY hh24:mi:ss'))
    3 - access("FDATE">=TO_DATE('21-APR-10','dd-MON-yy') AND
    "FDATE"<=TO_DATE('21-APR-10 23:59:59','DD-MON-YY hh24:mi:ss'))
    Note
    - dynamic sampling used for this statement
    Statistics
    7 recursive calls
    0 db block gets
    76 consistent gets
    0 physical reads
    0 redo size
    412 bytes sent via SQL*Net to client
    380 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    1 rows processed

    Hi,
    user10541890 wrote:
    Performance with dates in the where clause
    CREATE TABLE TEST_DATA
    FNUMBER NUMBER,
    FSTRING VARCHAR2(4000 BYTE),
    FDATE DATE
    create index t_indx on test_data(fdata);Did you mean fdat<b>e</b> (ending in e)?
    Be careful; post the code you're actually running.
    query 1: select count(*) from TEST_DATA where trunc(fdate) = trunc(sysdate);
    query 2: select count(*) from TEST_DATA where fdate between trunc(sysdate) and trunc(SYSDATE) + .99999;
    query 3: select count(*) from TEST_DATA where fdate between to_date('21-APR-10', 'dd-MON-yy') and to_date('21-APR-10 23:59:59', 'DD-MON-YY hh24:mi:ss');
    My questions:
    1) Why isn't the index t_indx used in Execution plan 1?To use an index, the indexed column must stand alone as one of the operands. If you had a function-based index on TRUNC (fdate), then it might be used in Query 1, because the left operand of = is TRUNC (fdate).
    2) From the execution plan, I see that query 2 & 3 is better than query 1. I do not see any difference between execution plan 2 & 3. Which one is better?That depends on what you mean by "better".
    If "better" means faster, you've already shown that one is about as good as the other.
    Queries 2 and 3 are doing different things. Assuming the table stays the same, Query 2 may give different results every day, but the results of Query 3 will never change.
    For clarity, I prefer:
    WHERE     fdate >= TRUNC (SYSDATE)
    AND     fdate <  TRUNC (SYSDATE) + 1(or replace SYSDATE with a TO_DATE expression, depending on the requirements).
    3) I read somewhere - "Always check the Access Predicates and Filter Predicates of Explain Plan carefully to determine which columns are contributing to a Range Scan and which columns are merely filtering the returned rows. Be sceptical if the same clause is shown in both."
    Is that true for Execution plan 2 & 3?
    3) Could some one explain what the filter & access predicate mean here?Sorry, I can't.

  • Decode/Case in Where clause

    Hello,
    We are experiencing an issue with a Select statement that uses Decode in the Where clause. Specifically, it seems to be ignoring a nested Decode and just returning the default value. We have another nested decode that works fine, though.
    A member of our team mentioned that he believed there was an issue with using Decode and Case statements inside of a where clause within HTML DB...Is this correct? If it is, is there a workaround? Since the nested Decode works elsewhere in this statement, that doesn't seem right.
    My select statement looks like:
    SELECT
       SUBSTR(OBOB.OBOB_CNAME, 0, 30) d,
       OBOB.OBOB_UID r
    FROM
       ISR_OBOB_OBJECT OBOB,
       ISR_OBAF_OBJECT_AFFILIATION OBAF,
       ISR.ISR_OBSD_SDR OBSD
    WHERE
       OBOB.OBOB_UID = OBSD.OBOB_UID AND
       OBOB.OBOB_UID = OBAF.OBOB_B_UID AND
    /*If Personal radio button is selected, displays all SDRs associated with user.
      If All is selected, displays all SDRs associated with IS group selected from drop down list
          or every SDR.
       OBAF.OBOB_A_UID = DECODE(:P1_DISPLAY_ALL,
                                       'Personal', :F101_APP_USER_UID,
    /*This is the decode statement that it seems to ignore. If ALL is selected, the query should see if a group has
        has been selected from a drop down list that appears when the ALL button is chosen. If a group is selected
        (the item isn't 0), only SDRs for that group should be shown. Otherwise, all SDRs for every group should display.
                                       'ALL', DECODE(:P1_SEARCH_IS_SUPPORT_GROUP, 0, OBAF.OBOB_A_UID, :P1_SEARCH_IS_SUPPORT_GROUP),
                                       OBAF.OBOB_A_UID) AND
    /*If Personal radio button is selected, display SDRs where user is the Primary assignee.
       OBAF.OBAT_UID = DECODE(:P1_DISPLAY_ALL, 'Personal', (select OBAT_UID from ISR_OBAT_OBJ_AFFIL_TYPE WHERE OBAT_APP_REF = 'SDR_PRIMARY'), OBAF.OBAT_UID) AND
    /*If a SDR Status (open, completed, on hold, not started...) is selected, only display the SDRs with that status.
       OBSD.KTTR_STATUS_UID = DECODE(:P1_ISR_STATUS_UID, 0, OBSD.KTTR_STATUS_UID, :P1_ISR_STATUS_UID) AND
    /*If SDR_History textbox is Null, or Open, Not Started, or On Hold SDR status has been selected, then all SDRs with
        a create date between today and 99999 months ago will display. Otherwise, only SDRs with a create date between
        today and however many months are in the textbox will display (i.e. Completed SDRs created in the past 6 months.)
       MONTHS_BETWEEN(sysdate, OBSD.OBSD_CREATE_DATE) <= DECODE(:P1_SDR_HISTORY, NULL, 99999, DECODE(:P1_ISR_STATUS_UID,
                                                              (select KTTR_UID from ISR_KTTR_TRANSLATION where KTTR_APP_REF = 'SD_STAT_OPEN'), 99999,
                                                              (select KTTR_UID from ISR_KTTR_TRANSLATION where KTTR_APP_REF = 'SD_STAT_NOT_STA'), 99999,
                                                              (select KTTR_UID from ISR_KTTR_TRANSLATION where KTTR_APP_REF = 'SD_STAT_HOLD'), 99999,
                                                              :P1_SDR_HISTORY))
    /*Alphabetical order
    Order by
       dWe originally wrote this as a PL/SQL statement that returned a query string since most of the where clause is dependent on items the user may or may not select, but we have moved the query into a multiselect list, which only seems to allow SQL Queries.
    Any help or advice would be appreciated.
    Thanks,
    Scott

    Scott: Did you try running that SQL statement in SQL Workshop in Apex? You can run it as it is, it will popup a window asking you to enter values for the bind variables.
    JAC73: I don't think an IN clause doesn't work that way, you need a actual SQL sub-query, not an expression from a DECODE/CASE statement. Search this site for str2tbl and see Tom's excellent discussion at
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:110612348061

  • Null global variable in block's WHERE clause - no records?

    I'm setting a :GLOBAL.emp_id in certain spots in my form. The EMPLOYEE block's WHERE clause says emp_id = :GLOBAL.emp_id. In the POST-QUERY, it sets that variable back to NULL so the next time they want to run a blind query, it will show all records.
    Well when the :GLOBAL.emp_id is NULL, nothing comes up in a blind query. I even changed the WHERE clause to say emp_id = NVL(:GLOBAL.emp_id,'') but that didn't do anything either.
    How can I get the WHERE clause to (basically) do nothing when that global variable is null? Or should I be messing with DEFAULT_WHERE instead of these global variables
    I'm in 6i

    I'm sorry - I stumbled on something soon after I posted and changed it to:
    emp_id = NVL(:GLOBAL.emp_id,emp_id)
    and it worked - duh

  • Problem with decode!!!

    Hi guys,
    I have a problem with "decode"!
    How can I tell the decode expression
    that if a rowset don't exists --> then doing something.
    I've tried that with "NULL" but that don't works.
    here my code:
    I wanted that if tx.text doesn't exists then
    it returns fs.anlageschwerpunkt_lang, and otherwise
    it returns tx.Text.
    select
    decode(tx.Text,NULL,fs.anlageschwerpunkt_lang,tx.Text) Anlageschwerpunkt_1 from
    POI.Fondsstamm fs,
    Texte tx,
    Texttypstamm txy
    where
    tx.match='amfcomm'
    and tx.match=rtrim(fs.match)
    and tx.TEXTTYPID=txy.TEXTTYPID
    and txy.BEREICHSID=14
    and txy.texttyp='Marketingstrategie'
    I hope somebody of you can help me
    thanxx
    Schoeib

    I read Schoeibs question differently; no ROWS are being returned. In that case you cannot expect DECODE or any other function to do anything. Assuming that rows always exist in fs and txy and are only missing in tx, then you need an outer join. Note that the join of tx.match = rtrim(fs.match) has been altered to avoid outer joining to more than one table. As mentioned before, although the decode is OK, NVL could be used instead.
    select
    decode(tx.Text,NULL,fs.anlageschwerpunkt_lang,tx.Text) Anlageschwerpunkt_1 from
    POI.Fondsstamm fs,
    Texte tx,
    Texttypstamm txy
    where
    tx.match(+)='amfcomm'
    and rtrim(fs.match) = 'amfcomm'
    and tx.TEXTTYPID(+)=txy.TEXTTYPID
    and txy.BEREICHSID=14
    and txy.texttyp='Marketingstrategie'

  • How can we use DECODE function in where clause.

    Hi Guys,
    I have to use DECODE function in where clause.
    like below
    select * from tab1,tab2
    where a.tab1 = b.tab2
    and decode(code, 'a','approved')
    in this manner its not accepting?
    Can any one help me on this or any other aproach?
    Thanks
    -LKR

    >
    I am looking for to decode the actual db value something in different for my report.
    like if A then Accepted
    elseif R then Rejected
    elseif D then Denied
    these conditions I have to check in where clause.
    >
    what are you trying to do?
    may be you are looking for
    select * from tab1,tab2
    where a.tab1 = b.tab2
    and
       (decode(:code, 'A','Accepted') = <table_column>
        or
        decode(:code, 'R','Rejected') = <table_column>
       or
        decode(:code, 'D','Denied') = <table_column>
       )

  • Problems with decoding an latin1-encoded url

    Hi,
    i have a problem with decoding german umlaut-characters from an URL.
    I'm using Tomcat 5.5 on a Linux server and one on a windows machine for development. Both webapps have the same configurations.
    A servlet decodes the URL-String, parses it and stores the parsed data into a mysql-DB.
    For decoding the query-string i'm using org.apache.commons.codec.net.URLCodec.URLCodec.decode .
    Here's the code:
    String unparsedParameters = request.getQueryString();
    URLCodec codec = new URLCodec("ISO-8859-1");
    result = codec.decode(unparsedParameters);Here an example for a query-string: http://servername:8080/servlet/Import?Etwas%20wurde%20am%2025.08.2010%2010%3A16%3A50%20*ge%E4ndert*
    On the windows machine the word "*ge&auml;ndert*" is decoded correctly. But on the linux server i get "*ge?ndert*". It makes no difference if i write the result into the database or just into a logfile.
    Can anyone help?
    Thanks in advance.
    Edited by: sol1640 on Aug 26, 2010 5:59 AM

    Problem resolved.
    Instead of using the decode-method as described in my fist message now i'm doing the folowing:
    fURLDecodigCharset = "ISO8859-1";
    byte[] bytes = originalParam.getBytes(fURLDecodigCharset);
    byte[] decodeUrl = URLCodec.decodeUrl(bytes);
    result = new String (decodeUrl, fURLDecodigCharset);because the method "decode" decodes the string by using the defaultcharset. And that was the problem.
    >
    The default charset is determined during virtual-machine startup and typically depends upon the locale and charset of the underlying operating system.
    >
    Thats why i've got different behaviours on different systems.
    Thanks

  • Using decode to define "where" clause

    Gurus,
    Before, I was unioning several queries to get my desired results. Is there a way to utilize decode to define my "where" conditions?
    Thanks
    msi.global_attribute1               HTS_Number,           
    msi.global_attribute2               ECCN_Number  ,
    msi.market_price                    price,     --- double-check
    decode(msi.serial_number_control_code,5,'Serial','Lot') control_type,
    -- add item_type
    --Item Label Creation        At Receipt or At Sales Order Issue
    (case
    when enabled_flag = 'Y' and end_date_active is null then 'Active'
    when enabled_flag = 'Y' and end_date_active > sysdate then 'Active'
    when enabled_flag = 'Y' and end_date_active < sysdate then 'Inactive'
    when enabled_flag = 'N' then 'Inactive'
    else 'Active'
    end) status,
    from inv.mtl_system_items_b   msi,
         po_hazard_classes    phc,
        po_un_numbers        pun
    where msi.hazard_class_id = phc.hazard_class_id(+)  
    and   msi.un_number_id = pun.un_number_id(+)   
    and   msi.organization_id = 543
    and   msi.creation_date = msi.last_update_date
    --and   'New Items' = nvl(p_item_status,'All Items') --p_item_status
    and   decode('New Items', --p_item_status,
          'New Items', (msi.creation_date = msi.last_update_date),
          'Updated Items', (msi.creation_date <> msi.last_update_date),
          'All Items', (1=1), (1=1))
      and msi.segment2 = '14078'

    Hi,
    sreese wrote:
    Before, I was unioning several queries to get my desired results. Is there a way to utilize decode to define my "where" conditions?Depending on what you mean, yes.
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    Simplify the problem as much as possible. Remove all tables and columns that play no role in this problem.
    Always say which version of Oracle you're using.
    Here's an example of two UNIONed queries:
    SELECT       deptno
    ,       SUM (sal)     AS total_sal
    ,       'MANAGEMENT'     AS grp_name
    FROM       scott.emp
    WHERE       job     IN ('MANAGER', 'PRESIDENT')
    GROUP BY  deptno
         UNION ALL
    SELECT       deptno
    ,       SUM (sal)     AS total_sal
    ,       'OLD-TIMERS'     AS grp_name
    FROM       scott.emp
    WHERE       hiredate     < DATE '1984-01-01'
    GROUP BY  deptno
    ORDER BY  deptno
    ,            grp_name
    ;Output:
    `   DEPTNO  TOTAL_SAL GRP_NAME
            10       7450 MANAGEMENT
            10       8750 OLD-TIMERS
            20       2975 MANAGEMENT
            20       6775 OLD-TIMERS
            30       2850 MANAGEMENT
            30       9400 OLD-TIMERSA more efficient way to get the same information, without a UNION is:
    SELECT       deptno
    ,       SUM (CASE WHEN job IN ('MANAGER', 'PRESIDENT') THEN sal END)     AS management
    ,       SUM (CASE WHEN hiredate < DATE '1984-01-01'      THEN sal END)     AS old_timers
    FROM       scott.emp
    WHERE       job          IN ('MANAGER', 'PRESIDENT')
    OR       hiredate     < DATE '1984-01-01'
    GROUP BY  deptno
    ORDER BY  deptno
    ;Output:
    `   DEPTNO MANAGEMENT OLD_TIMERS
            10       7450       8750
            20       2975       6775
            30       2850       9400As you can see, the results aren't exactly the same. UNION makes it easy to get more rows in the output than there are in the original; CASE (or DECODE,you can use whichever you like) makes it easy to get fewer rows and more columns. If you reallt want one kind of output or the other, it can be done with a little more work using either UNION or CASE.
    When using CASE, the WHERE clause is typically more inclusive than any of the WHERE caluses in the UNION. Some of the conditions (in this example, all of the conditions) that were in the separate WHERE clauses of the UNION get changed to be conditions in separate CASE expressions.

  • Function-based index with OR in the wher-clause

    We have some problems with functin-based indexes and
    the or-condition in a where-clause.
    --We use Oracle 8i (8.1.7)
    create table TPERSON(ID number(10),NAME varchar2(20),...);
    create index I_NORMAL_TPERSON_NAME on TPERSON(NAME);
    create index I_FUNCTION_TPERSON_NAME on TPERSON(UPPER(NAME));
    The following two statements run very fast on a large table
    and the execution-plan asure the usage of the indexes
    (-while the session is appropriate configured and the table is analyzed):
    1)     select count(ID) FROM TPERSON where upper(NAME) like 'MIL%';
    2)     select count(ID) from TPERSON where NAME like 'Mil%' or (3=5);
    In particular we see that a normal index is used while the where-clause contains
    an OR-CONDITION.
    But if we try the similarly select-statement
    3)     select count(ID) FROM TPERSON where upper(NAME) like 'MIL%' or (3=5);
    the CBO will not use the function-index I_FUNCTION_TPERSON_NAME and we have a full table scan in the execution-plan.
    (This behavior we only expect with views but not with indexes.)
    We ask for an advice like a hint, which enable the CBO-usage
    of function-based indexes in connection with OR.
    This problem seems to be artificial because it contains this dummy logic:
         or (3=5).
    This steams from an prepared statement, where this kind of boolean
    flag reduce the amount of different select-statements needed for
    covering the hole business-logic, while using bind-variables for the
    concrete query-parameters.
    A more realistic (still boild down) version of our select-statement is:
    select * FROM TPERSON
    where (upper(NAME) like 'MIL%' or (NAME is null))
    and (upper(FIRSTNAME) like 'MICH% or (FIRSTNAME is null))
    and ...;
    thank you for time..
    email: [email protected]

    In the realistic statement you write :
    select * FROM TPERSON
    where (upper(NAME) like 'MIL%' or (NAME is null))
    and (upper(FIRSTNAME) like 'MICH% or (FIRSTNAME is null))
    and ...;
    as far as i know, NULL values are not indexed, "or (NAME is NULL)" have to generate a full table scan.
    HTH
    We have some problems with functin-based indexes and
    the or-condition in a where-clause.
    --We use Oracle 8i (8.1.7)
    create table TPERSON(ID number(10),NAME varchar2(20),...);
    create index I_NORMAL_TPERSON_NAME on TPERSON(NAME);
    create index I_FUNCTION_TPERSON_NAME on TPERSON(UPPER(NAME));
    The following two statements run very fast on a large table
    and the execution-plan asure the usage of the indexes
    (-while the session is appropriate configured and the table is analyzed):
    1)     select count(ID) FROM TPERSON where upper(NAME) like 'MIL%';
    2)     select count(ID) from TPERSON where NAME like 'Mil%' or (3=5);
    In particular we see that a normal index is used while the where-clause contains
    an OR-CONDITION.
    But if we try the similarly select-statement
    3)     select count(ID) FROM TPERSON where upper(NAME) like 'MIL%' or (3=5);
    the CBO will not use the function-index I_FUNCTION_TPERSON_NAME and we have a full table scan in the execution-plan.
    (This behavior we only expect with views but not with indexes.)
    We ask for an advice like a hint, which enable the CBO-usage
    of function-based indexes in connection with OR.
    This problem seems to be artificial because it contains this dummy logic:
         or (3=5).
    This steams from an prepared statement, where this kind of boolean
    flag reduce the amount of different select-statements needed for
    covering the hole business-logic, while using bind-variables for the
    concrete query-parameters.
    A more realistic (still boild down) version of our select-statement is:
    select * FROM TPERSON
    where (upper(NAME) like 'MIL%' or (NAME is null))
    and (upper(FIRSTNAME) like 'MICH% or (FIRSTNAME is null))
    and ...;
    thank you for time..
    email: [email protected]

  • Problems with file block settings

    We manage file block settings via group policy.  I have run into problems with the file block settings not working as advertised.
    I've run into a couple of issues:
    First, in Excel 2010 I would like to open Web Page and XML files in protected view rather than blocking entirely.  Our "Set Default File Block Behavior" in the GPO is set to "Blocked Files are not opened."  According to the
    documentation, the settings for individual file types should be able to override this behavior but this is not the case in my testing.  If I set "Web pages and Excel 2003 XML spreadsheets" to "Allow editing and Open in Protected View"
    the files are still blocked and the Trust Center list the file as Do not open, not the GPO setting of open in protected view.  I have verified via GPresults that the GPO applied successfully, rebooted the PC, etc.  The "Set Default File Block
    Behavior" is NOT overridden by individual file type settings.
    According to the "plan file block settings" technet article:
    The “Set default file block behavior” setting specifies how blocked files open (for example: does not open, opens in protected view, or opens in protected view but can be edited). If you enable this setting, the default file block behavior you specify applies
    to any file format that users block in the Trust Center UI. It also applies to a specific file format only if you both enable its file format setting (for more information about individual file format settings, see the tables in this article) and select the
    Open/Save blocked, use open policy option. Otherwise, if you configure an individual file format setting, it overrides the
    Set default file block behavior setting configuration for that file type.
    Second, even if I do change the set default file block behavior to open in protected view, I still cannot open XML spreadsheets.  The trust center says that the file format is set to open in protected view but when I attempt to open a file it behaves
    as if the setting was still set to block entirely.
    The only thing that works is setting it to "do not block" which is not where I'd like to go - I would for security reasons like these types of files to open in protected view but there doesn't seem to be any way to do this contrary to the Technet
    documentation.

    Hi,
    I had opened a case at Microsoft in 2012 about the «Open/Save Block, use open policy» parameter about HTM/HMTL files... Here is the answer I got from the support.
    Hope it will help
    Thank you for contacting Microsoft regarding your recent Office 2010 Hotfix request (SR 112022071246968) in reference to File Block settings on web pages. We have conducted a thorough investigation into this matter
    and while we recognize the impact the issue is having on your business, we cannot accept this Hotfix request because it is acting as designed.<u5:p></u5:p>
    Office will block any files that are explicitly set in the File Block UI by an Administrator when there is no built in validator.  The Office File Validation scans and validates certain kinds of files and will
    only display those applicable files in Protected View.  We could provide a safe experience in Protected View for HTM, but it wouldn't be a useful experience. Linked content of the web page is not available (images, stylesheets, javascript, etc), so the
    user would effectively see plain text. This is not the experience we want in Protected View, and it would encourage users to leave Protected View, putting their machine at risk. So HTM/HTML files are blocked.<u5:p></u5:p>
    <u5:p></u5:p>

  • Problem with table(cast..)) clause - timeout

    Hello,
    I've in shared memory one query in multiple copies - one differences between copies is in arguments count given with in clause. For example, in shared memory i have:
    select name from a where id in (?);
    select name from a where id in (?,?);
    select name from a where id in (?,?,?);
    I try to minimize size of shared memory by change this query as in example:
    select name from a where id in (select * from table(cast(? as seqintegertable)))
    In this case my shared memory is ok, but I have problem with timeout exception:
    - time of executing query without cast is about 250 ms
    - with cast: about 10560 ms and sometimes I get ORA-01652
    Why this time is so long? Can I reduce it? Maybe I should change something other?

    user13241971 wrote:
    Why this time is so long? Can I reduce it? Maybe I should change something other?To know why your query takes so long: {thread:id=501834}
    Likely it's because of wrong cardinalities, to which this excellent article gives possible solutions: http://www.oracle-developer.net/display.php?id=427
    Regards,
    Rob.

  • Problem with ParForEach Block

    Hi, Gurus.
    i have a strange problem with blocks (parallel processing).
    My Wf contain of:
    1. Dialog step, where user choose actors.
    2. parallel block for actors, the first step in the block - no-dialog step for getting instance of actor object.
    When I test this WF, and choose more than 5 actors, the parallel processing not working,
    all non-dialog task for each actor are in READY state, and not processing.
    But when I delete  dialog step and set actors manually, its working fine, and when I chosee less than 5 actors, it's working.
    I check mapping, everything ok. Thank you for advise.
    Regards,
    Oleg.

    Thank you for your reply.
    I have no rule in this Workflow, the processor of first dialog step is wf_initiator.
    This step base on standard method - WF_TASK.DISPATCH.
    Initiator chooses actor's (in my case it's org. units) and the table seem's like:
    O 01000000
    O 02000000
    O 03000000
    Then, I try to make paralllel steps for each line of this table. In WF Log, I see that parallel blocks is created,
    but the first step in this blocks (it's no-dialog step to generate instance of orgunit object), is in ready state (the line (object key) is transfer to this step, and the instance is not generated). As I said, when I delete the step with agent chose, and fill this table manually, its working fine...

  • DECODE inside the WHERE clause

    Hello All:
    I can't get the DECODE statement to work inside my WHERE clause. I have read the information on
    tahiti.oracle.com
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/functions049.htm#i1017437
    But still can't get it working. Originally I had it working as dynamic SQL and then execute that string, but I am not allowed to use dynamic SQL and need to use "Real" PL/SQL.
    I have the following WHERE clause (more info after the WHERE clause)
    WHERE
         a.ebiz_asn_no(+) = te.ebiz_cntrl_no
         AND w.ebiz_work_no(+) = te.ebiz_cntrl_no
         AND o.ebiz_ord_no(+) = ebiz_cntrl_no
         AND t.ebiz_trailer_no(+) = te.ebiz_trailer_no
         AND ms.ebiz_sku_no(+) = te.ebiz_sku_no
         AND NVL(ms.ebiz_sku_no, -1) = NVL(p_SKU, nvl(ms.ebiz_sku_no, -1))
         AND tl.ebiz_lp_no(+) = te.ebiz_lp_no
         AND NVL(te.ebiz_lp_no, -1) = NVL(p_LP, nvl(te.ebiz_lp_no, -1))
         AND eu.ebiz_user_no(+) = te.act_ebiz_user_no
         AND NVL(te.act_ebiz_user_no, -1) = NVL(p_UserID, NVL(te.act_ebiz_user_no, -1))
         AND NVL(te.begin_location, '~') = NVL(p_BeginLocation, NVL(te.begin_location, '~'))
         AND NVL(te.end_location, '~') = NVL(p_EndLocation, NVL(te.end_location, '~'))
         AND te.comp_id = p_CompID
         AND te.site_id = p_SiteID
         AND INSTR('' || p_TaskType || '', te.task_type) > 0
         AND NVL(task_priority, -1) = NVL(p_Priority, NVL(task_priority, -1))
         AND NVL(te.ebiz_cntrl_no, -1) = DECODE(te.task_type, 'IULD', DECODE(p_Order, null, te.ebiz_cntrl_no, ebiz_po2asn.get_ebiz_po_no(p_Order)), NVL(p_Order, NVL
                           (te.ebiz_cntrl_no,-1)))
         AND NVL(te.batch_no,'~') = NVL(p_Batch, NVL(te.batch_no, '~'))
         AND NVL(te.ebiz_wave_no, -1) = NVL(p_Wave, NVL(te.ebiz_wave_no, -1))
         || whereClauseStatus
         || whereClauseFromDate
         || whereClauseToDate;As you can see, originally I was appending values of "whereClauseStatus, whereClauseFromDate, whereClauseToDate" and this was set with the following PL/SQL code:
         IF(p_TaskStatus = 'C') THEN
              --     Set From Date Clause
              IF(p_FromShipDate IS NOT NULL) THEN
                   whereClauseFromDate := ' AND TRUNC(te.act_end_date) >= TO_DATE(''' || p_FromShipDate || ''',''MM/dd/yyyy'') ';
              END IF;
              --     Set To Date Clause
              IF (p_ToShipDate IS NOT NULL) THEN
                   whereClauseToDate := ' AND TRUNC(te.act_end_date) <= TO_DATE(''' || p_ToShipDate || ''',''MM/dd/yyyy'') ';
              END IF;
         ELSE
              --     Incomplete and All statuses are filtered on the currdate
              --     Set From Date Clause
              IF(p_FromShipDate IS NOT NULL) THEN
                   whereClauseFromDate := ' AND TRUNC(te.currdate) >= TO_DATE(''' || p_FromShipDate || ''',''MM/dd/yyyy'') ';
              END IF;
              --     Set To Date Clause
              IF (p_ToShipDate IS NOT NULL) THEN
                   whereClauseToDate := ' AND TRUNC(te.currdate) <= TO_DATE(''' || p_ToShipDate || ''',''MM/dd/yyyy'') ';
              END IF;
         END IF;
         IF (p_TaskStatus = 'I') THEN
              whereClauseStatus := ' AND act_end_date IS NULL ';
         ELSIF (p_TaskStatus = 'C') THEN
              whereClauseStatus := ' AND act_end_date IS NOT NULL ';
         ELSE
              whereClauseStatus := '';
         END IF;I am having serious issues getting the DECODE statement to replace the three appended variables.
    Any help would be greatly appreciated.
    Thanks
    Andy
    Edited by: BluShadow on 02-Aug-2011 15:11
    added {noformat}{noformat} tags for clarity. Please read {message:id=9360002} and learn to do this yourself.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    I'm going to take a wild stab in the dark and suggest that this may be what you are looking for...
    WHERE
         a.ebiz_asn_no(+) = te.ebiz_cntrl_no
         AND w.ebiz_work_no(+) = te.ebiz_cntrl_no
         AND o.ebiz_ord_no(+) = ebiz_cntrl_no
         AND t.ebiz_trailer_no(+) = te.ebiz_trailer_no
         AND ms.ebiz_sku_no(+) = te.ebiz_sku_no
         AND NVL(ms.ebiz_sku_no, -1) = NVL(p_SKU, nvl(ms.ebiz_sku_no, -1))
         AND tl.ebiz_lp_no(+) = te.ebiz_lp_no
         AND NVL(te.ebiz_lp_no, -1) = NVL(p_LP, nvl(te.ebiz_lp_no, -1))
         AND eu.ebiz_user_no(+) = te.act_ebiz_user_no
         AND NVL(te.act_ebiz_user_no, -1) = NVL(p_UserID, NVL(te.act_ebiz_user_no, -1))
         AND NVL(te.begin_location, '~') = NVL(p_BeginLocation, NVL(te.begin_location, '~'))
         AND NVL(te.end_location, '~') = NVL(p_EndLocation, NVL(te.end_location, '~'))
         AND te.comp_id = p_CompID
         AND te.site_id = p_SiteID
         AND INSTR('' || p_TaskType || '', te.task_type) > 0
         AND NVL(task_priority, -1) = NVL(p_Priority, NVL(task_priority, -1))
         AND NVL(te.ebiz_cntrl_no, -1) = DECODE(te.task_type, 'IULD', DECODE(p_Order, null, te.ebiz_cntrl_no, ebiz_po2asn.get_ebiz_po_no(p_Order)), NVL(p_Order, NVL
                           (te.ebiz_cntrl_no,-1)))
         AND NVL(te.batch_no,'~') = NVL(p_Batch, NVL(te.batch_no, '~'))
         AND NVL(te.ebiz_wave_no, -1) = NVL(p_Wave, NVL(te.ebiz_wave_no, -1))
         AND TRUNC(te.act_end_date) >= NVL(TO_DATE(p_FromShipDate,'MM/dd/yyyy'),TRUNC(te.act_end_date))
            AND TRUNC(te.act_end_date) <= NVL(TO_DATE(p_ToShipDate,'MM/dd/yyyy'),TRUNC(tw.act_end_date))
            AND TRUNC(te.currdate) >= NVL(TO_DATE(p_FromShipDate,'MM/dd/yyyy'),TRUNC(te.currdate))
         AND TRUNC(te.currdate) <= NVL(TO_DATE(p_ToShipDate,'MM/dd/yyyy'),TRUNC(te.currdate))
            AND (  (act_end_date IS NULL AND p_TaskStatus = 'I')
                OR (act_end_date IS NOT NULL AND p_TaskStatus = 'C')
                OR p_TaskStatus NOT IN ('I','C')
                )Edited by: BluShadow on 02-Aug-2011 16:27
    missed the last clause. oops.

  • 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 '<', '>', '='

Maybe you are looking for

  • Custom login page with Policy Agent 2.2 & Access Manager

    Hi, I’m trying to set up policy agent 2.2 and Access Manager to use the login page of the application I’m trying to secure. I’m not sure if this is the correct forum or not so feel free to move this if need be. I’ve been using this link: http://docs.

  • Color and contrast different from Premiere Pro 2 DVD creation

    I found after creating DVD's via Premiere Pro 2 are more saturated and more neutral in color vs encoding through Encore. I made a si8de by side test, converted them back to AVI and grabbed the same still of each. The Encore still was lower in contras

  • How to import a schema??

    Hi All, How to import schema from another project when the present schema is already containing a node and its elements. And the imported schema has to be the next node in the schema.  Also kindly clarify the differences between import, include and r

  • Compatibility: OS X 10.4.6 and FCP 3

    I use FCP 3 on a Powerbook G4. My primary external video device is a Sony DV CAM DSR-20. Until recently, I was running OS X 10.3 and the setup was bulletproof. Days ago, I installed OS X 10.4.6 and immediately thereafter FCP would not recognize the D

  • Why doesn't the 7.2.2 update work for the Quad PPC?

    since we've discussed being upset about this, I thought I would pose this rather simple 'technical' question. also, is it possible to adapt the universal binary to PPC (using X-code or something)? any programmer people that can answer this? just for