Strange Query

Hi all,
I've got a problem with the following query: if I include a filter on a table, the explain plan say me that there's a cartesian. If I avoid the filter, no.
The database version is 10.2.0.4.
In another Environment (same DB, same OS, same etc...) there are no problems!
Here the query and the explain plan:
query without filter:
SELECT DISTINCT
       E.ID_CUSTOMER_UNIFIED
     , E.START_VALIDITY_DATE
     , E.START_ASINC_DATE
     , E.CUSTOMER_STATUS
     , Z.FLAG_PASSIVE_SWITCH
FROM TW_E_SUPPLY_A Z
   , TW_E_SUPPLY_H B
   , TW_E_CUST_UNI_CUST Y
   , TW_T_CUSTOMER_UNIFIED_A E
WHERE Z.ID_SUPPLY = B.ID_SUPPLY
  AND Z.END_VALIDITY_DATE IS NULL
  AND B.END_VALIDITY_DATE IS NULL
  AND B.ID_CUSTOMER = Y.ID_CUSTOMER
  AND Y.END_LINK_DATE IS NULL
  AND Y.ID_CUSTOMER_UNIFIED = E.ID_CUSTOMER_UNIFIED
  AND Y.START_VALIDITY_DATE = E.START_VALIDITY_DATE
--  AND E.CUSTOMER_STATUS = 'NON ATTIVO'
  AND Z.FLAG_PASSIVE_SWITCH = 'Y';explain plan without filter:
| Id  | Operation                  | Name                    | Rows  | Bytes |TempSpc| Cost (%CPU)| Pstart| Pstop |                                                                                                                                                                                         
|   0 | SELECT STATEMENT           |                         |  5152 |   477K|       |  2570   (2)|       |       |                                                                                                                                                                                         
|   1 |  HASH UNIQUE               |                         |  5152 |   477K|  1112K|  2570   (2)|       |       |                                                                                                                                                                                         
|   2 |   HASH JOIN                |                         |  5152 |   477K|       |  2453   (2)|       |       |                                                                                                                                                                                         
|   3 |    HASH JOIN               |                         |  5455 |   351K|       |  1923   (2)|       |       |                                                                                                                                                                                         
|   4 |     HASH JOIN              |                         |  5455 |   175K|       |  1365   (2)|       |       |                                                                                                                                                                                         
|   5 |      PARTITION RANGE SINGLE|                         |  5455 | 70915 |       |   309   (2)|    22 |    22 |                                                                                                                                                                                         
|   6 |       TABLE ACCESS FULL    | TW_E_SUPPLY_A           |  5455 | 70915 |       |   309   (2)|    22 |    22 |                                                                                                                                                                                         
|   7 |      PARTITION RANGE SINGLE|                         |   162K|  3179K|       |  1054   (1)|    22 |    22 |                                                                                                                                                                                         
|   8 |       TABLE ACCESS FULL    | TW_E_SUPPLY_H           |   162K|  3179K|       |  1054   (1)|    22 |    22 |                                                                                                                                                                                         
|   9 |     PARTITION RANGE SINGLE |                         |   327K|    10M|       |   556   (1)|    22 |    22 |                                                                                                                                                                                         
|  10 |      TABLE ACCESS FULL     | TW_E_CUST_UNI_CUST      |   327K|    10M|       |   556   (1)|    22 |    22 |                                                                                                                                                                                         
|  11 |    TABLE ACCESS FULL       | TW_T_CUSTOMER_UNIFIED_A |   311K|  8811K|       |   529   (1)|       |       |                                                                                                                                                                                         
-------------------------------------------------------------------------------------------------------------------                                                                                                                                                                                          query with filter:
SELECT DISTINCT
       E.ID_CUSTOMER_UNIFIED
     , E.START_VALIDITY_DATE
     , E.START_ASINC_DATE
     , E.CUSTOMER_STATUS
     , Z.FLAG_PASSIVE_SWITCH
FROM TW_E_SUPPLY_A Z
   , TW_E_SUPPLY_H B
   , TW_E_CUST_UNI_CUST Y
   , TW_T_CUSTOMER_UNIFIED_A E
WHERE Z.ID_SUPPLY = B.ID_SUPPLY
  AND Z.END_VALIDITY_DATE IS NULL
  AND B.END_VALIDITY_DATE IS NULL
  AND B.ID_CUSTOMER = Y.ID_CUSTOMER
  AND Y.END_LINK_DATE IS NULL
  AND Y.ID_CUSTOMER_UNIFIED = E.ID_CUSTOMER_UNIFIED
  AND Y.START_VALIDITY_DATE = E.START_VALIDITY_DATE
  AND E.CUSTOMER_STATUS = 'NON ATTIVO'
  AND Z.FLAG_PASSIVE_SWITCH = 'Y';explain plan with filter:
| Id  | Operation                           | Name                    | Rows  | Bytes | Cost (%CPU)| Pstart| Pstop |                                                                                                                                                                                        
|   0 | SELECT STATEMENT                    |                         |     1 |    95 |  1401   (2)|       |       |                                                                                                                                                                                        
|   1 |  HASH UNIQUE                        |                         |     1 |    95 |  1401   (2)|       |       |                                                                                                                                                                                        
|   2 |   TABLE ACCESS BY GLOBAL INDEX ROWID| TW_E_SUPPLY_H           |     1 |    20 |     3   (0)|    22 |    22 |                                                                                                                                                                                        
|   3 |    NESTED LOOPS                     |                         |     1 |    95 |  1400   (2)|       |       |                                                                                                                                                                                        
|   4 |     HASH JOIN                       |                         |     1 |    75 |  1397   (2)|       |       |                                                                                                                                                                                        
|   5 |      MERGE JOIN CARTESIAN           |                         |     1 |    42 |   838   (2)|       |       |                                                                                                                                                                                        
|   6 |       TABLE ACCESS FULL             | TW_T_CUSTOMER_UNIFIED_A |     1 |    29 |   529   (1)|       |       |                                                                                                                                                                                        
|   7 |       BUFFER SORT                   |                         |  5455 | 70915 |   309   (2)|       |       |                                                                                                                                                                                        
|   8 |        PARTITION RANGE SINGLE       |                         |  5455 | 70915 |   309   (2)|    22 |    22 |                                                                                                                                                                                        
|   9 |         TABLE ACCESS FULL           | TW_E_SUPPLY_A           |  5455 | 70915 |   309   (2)|    22 |    22 |                                                                                                                                                                                        
|  10 |      PARTITION RANGE SINGLE         |                         |   327K|    10M|   556   (1)|    22 |    22 |                                                                                                                                                                                        
|  11 |       TABLE ACCESS FULL             | TW_E_CUST_UNI_CUST      |   327K|    10M|   556   (1)|    22 |    22 |                                                                                                                                                                                        
|  12 |     INDEX RANGE SCAN                | TW_E_SUPPLY_H_CUST_IDX  |     2 |       |     2   (0)|       |       |                                                                                                                                                                                        
--------------------------------------------------------------------------------------------------------------------                                                                                                                                                                                         Someone know what can cause this?
Thanks in advance
Steve

In general, this is not necessarily something to be worried about.
In general, if that estimate of one row from TW_T_CUSTOMER_UNIFIED_A is inaccurate, then you've most likely got a statistics issue.
However, is that one row estimate accurate?
If not, firstly can you post the predicates sections of this plan?
Then can you also run the query (run it not explain it) with the /*+ gather_plan_statistics */ hint and immediately afterwardsoutput from
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(null,null,'ALLSTATS LAST');

Similar Messages

  • A strange query of queries bug in CF11?

    Hi,
    I have this strange query of queries result that could be a bug in CF11.  The result is fine in CF10.
    Basically, I have 2 queries, qrA and qrB.  I do a join of the two in joinQr, after which I do a query of qrA.  Since I didn't alter qrA in any way, I would expect newQrA to give me the same result as qrA.  However it only gives me one row ("D").  Now, here's the strange thing:  If I start off qrA with the letters in ascending order ["A", "B", "C", "D"], then newQrA gives me the right result.
    <cfset qrA = queryNew("")>
    <cfset queryAddColumn( qrA, "size", "varchar", [ "D", "A", "B", "C" ] )>
    <cfset qrB = queryNew("")>
    <cfset queryAddColumn( qrB, "size", "varchar", [ "A" ] )>
    <cfset queryAddColumn( qrB, "quantity", "integer", [ 0 ] )>
    <cfquery name="joinQr" dbtype="query">
        select qrA.*, qrB.quantity
        from qrA, qrB
        where qrA.size = qrB.size
    </cfquery>
    <cfquery name="newQrA" dbtype="query">
        select *
        from qrA
    </cfquery>
    <cfdump var="#qrA#">
    <cfdump var="#qrB#">
    <cfdump var="#joinQr#">
    <cfdump var="#newQrA#">

    For your interest, by coincidence, my first test was with
    <cfset queryAddColumn( qrA, "size", "varchar", [ "A","B","C","D" ] )> 
    It turns out that the order "A","B","C","D" works, whereas "D","A","B","C" fails. Quite funny, really.

  • Strange query / explain plan

    (I posted this in the Oracle Text forum, but I think it's as appropriate here.)
    Consider the following queries:
    :the_filter := 'FILE';
    (1)
    SELECT COUNT(*)
    FROM FOO
    WHERE CONTAINS(search_col,:the_filter) > 0;
    (2)
    SELECT COUNT(*)
    FROM FOO
    WHERE 'FILE' IS NULL OR CONTAINS(search_col,:the_filter) > 0;
    (3)
    SELECT COUNT(*)
    FROM FOO
    WHERE :the_filter IS NULL OR CONTAINS(search_col,:the_filter) > 0;
    (1) and (2) use the text index and run normally, but (3) does a full table scan, but I don't understand why.
    The reason behind my using a query of the form (3) is to say 'keep the record if the filter is null or the record contains the filter'. I'm using the filter as a switch, and (3) is actually a simplified form of a complex query with several tables and filters. How can I do this without the query using a full table scan?
    Below is the script and a record of the full session:
    SET ECHO ON;
    SET TIMING ON;
    DROP TABLE FOO;
    CREATE TABLE FOO (search_col VARCHAR2(100));
    -- Loads of dummy data
    INSERT INTO FOO (search_col) SELECT OBJECT_NAME || ' ' || OBJECT_TYPE
    FROM ALL_OBJECTS WHERE ROWNUM <= 20000;
    COMMIT;
    CREATE INDEX I1 ON FOO(search_col) INDEXTYPE IS CTXSYS.CONTEXT
    PARAMETERS(' section group ctxsys.html_section_group');
    variable the_filter varchar2(100);
    begin
    :the_filter := 'FILE';
    end;
    SET AUTOTRACE ON EXPLAIN;
    SELECT COUNT(*)
    FROM FOO
    WHERE CONTAINS(search_col,:the_filter) > 0;
    SELECT COUNT(*)
    FROM FOO
    WHERE 'FILE' IS NULL OR CONTAINS(search_col,:the_filter) > 0;
    SELECT COUNT(*)
    FROM FOO
    WHERE :the_filter IS NULL OR CONTAINS(search_col,:the_filter) > 0;
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production
    With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.6.0 - Production
    SQL*Plus: Release 10.2.0.1.0 - Production on Tue Nov 21 11:21:22 2006
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production
    With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.6.0 - Production
    SQL> SET TIMING ON;
    SQL> DROP TABLE FOO;
    Table dropped.
    Elapsed: 00:00:00.73
    SQL> CREATE TABLE FOO (search_col VARCHAR2(100));
    Table created.
    Elapsed: 00:00:00.03
    SQL> -- Loads of dummy data
    SQL> INSERT INTO FOO (search_col) SELECT OBJECT_NAME || ' ' || OBJECT_TYPE
    2 FROM ALL_OBJECTS WHERE ROWNUM <= 20000;
    20000 rows created.
    Elapsed: 00:00:01.92
    SQL> COMMIT;
    Commit complete.
    Elapsed: 00:00:00.01
    SQL> CREATE INDEX I1 ON FOO(search_col) INDEXTYPE IS CTXSYS.CONTEXT
    2 PARAMETERS(' section group ctxsys.html_section_group');
    Index created.
    Elapsed: 00:00:10.76
    SQL> variable the_filter varchar2(100);
    SQL> begin
    2 :the_filter := 'FILE';
    3 end;
    4 /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.00
    SQL> SET AUTOTRACE ON EXPLAIN;
    SQL> SELECT COUNT(*)
    2 FROM FOO
    3 WHERE CONTAINS(search_col,:the_filter) > 0;
    COUNT(*)
    29
    Elapsed: 00:00:00.07
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1 Bytes=59)
    1 0 SORT (AGGREGATE)
    2 1 DOMAIN INDEX OF 'I1' (Cost=0 Card=1 Bytes=59)
    SQL> SELECT COUNT(*)
    2 FROM FOO
    3 WHERE 'FILE' IS NULL OR CONTAINS(search_col,:the_filter) > 0;
    COUNT(*)
    29
    Elapsed: 00:00:00.08
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1 Bytes=59)
    1 0 SORT (AGGREGATE)
    2 1 DOMAIN INDEX OF 'I1' (Cost=0 Card=1 Bytes=59)
    SQL> SELECT COUNT(*)
    2 FROM FOO
    3 WHERE :the_filter IS NULL OR CONTAINS(search_col,:the_filter) > 0;
    COUNT(*)
    29
    Elapsed: 00:00:04.06
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=34482 Card=1 Bytes=5
    9)
    1 0 SORT (AGGREGATE)
    2 1 TABLE ACCESS (FULL) OF 'FOO' (Cost=34482 Card=453 Bytes=
    26727)

    Nothing is really strange when you are attempting to integrate with legacy systems! =)
    If no numerical processing is done why should numerical values be stored as numbers?

  • Oracle taking a strange query execution path

    I have a query which is admittedly a bit unconventional but Oracle is really doing something strange with it...
    SELECT   GROUP_CODE, STATUS, COL3, COL4, ETC...
    FROM MAIN_TABLE A
    WHERE A.STATUS = 'COMPLETE' -- ONLY GET COMPLETE RECORDS...
        -- AND ONLY FOR THOSE WHERE THERE ARE NO INCOMPLETE RECORDS IN THE SAME GROUP
        AND (SELECT COUNT(*) FROM MAIN_TABLE B WHERE B.GROUP_CODE = A.GROUP_CODE AND B.STATUS != 'COMPLETE') = 0
    ORDER BY GROUP_CODE  
    [\CODE]
    This query is done on a table of ~100k records, and the result should only return about 100 or so records.
    The only index in the table is on GROUP_CODE, and statistics are up-to-date.
    The strange part is that the query takes over an hour to complete, UNLESS I take out the ORDER BY, then it takes only a few seconds!!!  The difference is that with the ORDER BY, it is using the GROUP_CODE index (even with a */*+ NO_INDEX(MAIN_TABLE) */* hint in the query).
    How can I either reorganize this query or prevent Oracle from taking the "incorrect" path?
    Edited by: xaeryan on May 20, 2011 3:01 PM
    Edited by: xaeryan on May 20, 2011 3:02 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    try something as below..
    select *
    from
         select GROUP_CODE, STATUS, COL3, COL4, ETC...,
         max(case when STATUS != 'COMPLETE' then 1 ELSE 0 END) over( partition by  GROUP_CODE) as mx
         from
         MAIN_TABLE
    )X
    where mx= 0 HTH...

  • APEX Views - Strange query results

    One of my customers is running 3.1.2 version of APEX on a 10g database. I had two problems with it today:
    1. I implemented IBM Webseal SSO there and suddenly none of the authorisation schemes were running. Why, I don't know. I had to delete and recreate them.
    2. To be sure I replaced all the old authorization schemes I had to query the apex views. Searching on the non public pages with authorization I noticed some strange results. I run this query
    SELECT page_id
      FROM apex_application_pages
    WHERE page_requires_authentication = 'No' AND application_id = 200and in the result set I received a lot of pages where "Page requires Authentication" was set. I checked and indeed the results were wrong. After that I picked one of the pages from the result set and I set it to "Page is public". After running the same query the page id was not in the result set anymore.
    Has anyone seen this before?
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

    missing records after query when using a radiogroup are normally caused by an unappropiate setting of the property "Mapping of other values" at the record group. Check your setting for that value.

  • Query Profile Option - Strange Query Result

    Hello,
    I'm having a strange situation working with the profile option.
    I have the responsibility MY_RESP associated to the profile option "MY_PROFILE" that is set to the value "Company Business Group Europe".
    Now If I check using the OA which is profile option value associated to the profile option MY_PROFILE I get the right value "Company Business Group Europe".
    If I run a query to check the same thing insted to get the value "Company Business Group Europe" I get a strange number.
    Now I'm having this problem with several profile option values and that's not good 'cause I absolutly need to copy some hundreds of responsibilties with profile options, from an environment to another one and if I cannot get this values using the query it seems enough crazy to get them one by one using the application.
    Do you have an idea about how to resolve this problem?
    The query I was running to see the profile option values set for each profile option of each responsibilty was the following:
    SELECT distinct
    d.responsibility_name user_or_responsibility_name,
    g.user_profile_option_name,
    b.profile_option_value,
    a.start_date_active,
    a.end_date_active,
    a.profile_option_name
    FROM
    applsys.fnd_profile_option_values b,
    applsys.fnd_profile_options a,
    applsys.fnd_responsibility_tl d,
    FND_PROFILE_OPTIONS_VL g
    WHERE
    b.profile_option_id = a.profile_option_id
    and g.profile_option_id = a.profile_option_id
    and b.level_id = 10003
    and b.level_value = d.responsibility_id
    and d.responsibility_name like '%_ES'
    ORDER BY
    d.responsibility_name;
    morover if I run the query
    select PROFILE_OPTION_VALUE
    from fnd_profile_option_values
    where PROFILE_OPTION_VALUE = 'Company Business Group Europe'
    the result is empty...
    Thank you for the tips.
    BR
    DV

    can any one please help me that i have a requirement based on the profile option name get all the available values which are present for each level i tried the so many queries but for each profile option name it getting the id not the value please provide me a query for this issueThere are many docs available, and if you search the forum you could simply find it -- profile option pointing to old sid
    Thanks,
    Hussein

  • Strange query behavior when displayed in browser.

    Hi gurus,
    when I open a query in browser on one of the computers, I get no detailed cells, just the overall result.
    No matter, if I open the query in Portal, or in BEx Web Analyzer.
    When I use BEx Analyzer, everything seems to be fine.
    When I open the same query, on the same user, but on another computer, queries are displayed properly.
    Do you know what might cause the problem? Maybe some browser settings?
    Regards,
    Dorota

    Thanks, we recently installed a new GUI version on this computer, so probably you're right

  • Strange query from JDBC Thin Client on all_arguments

    Hi,
    in my statspack report I can see that query
    SELECT   package_name AS procedure_cat, owner AS procedure_schem,
             object_name AS procedure_name, argument_name AS column_name,
             DECODE (POSITION,
                     0, 5,
                     DECODE (in_out, 'IN', 1, 'OUT', 4, 'IN/OUT', 2, 0)
                    ) AS column_type,
             DECODE (data_type,
                     'CHAR', 1,
                     'VARCHAR2', 12,
                     'NUMBER', 3,
                     'LONG', -1,
                     'DATE', 93,
                     'RAW', -3,
                     'LONG RAW', -4,
                     'TIMESTAMP', 93,
                     'TIMESTAMP WITH TIME ZONE', -101,
                     'TIMESTAMP WITH LOCAL TIME ZONE', -102,
                     'INTERVAL YEAR TO MONTH', -103,
                     'INTERVAL DAY TO SECOND', -104,
                     'BINARY_FLOAT', 100,
                     'BINARY_DOUBLE', 101,
                     1111
                    ) AS data_type,
             DECODE (data_type,
                     'OBJECT', type_owner || '.' || type_name,
                     data_type
                    ) AS type_name,
             DECODE (data_precision,
                     NULL, data_length,
                     data_precision
                    ) AS PRECISION,
             data_length AS LENGTH, data_scale AS scale, 10 AS radix,
             1 AS nullable, NULL AS remarks, SEQUENCE, overload, DEFAULT_VALUE
        FROM all_arguments
       WHERE owner LIKE :1 ESCAPE '/'
         AND object_name LIKE :2 ESCAPE '/'
         AND data_level = 0
         AND package_name LIKE :3 ESCAPE '/'
         AND (   argument_name LIKE :5 ESCAPE '/'
              OR (argument_name IS NULL AND data_type IS NOT NULL)
    ORDER BY procedure_schem, procedure_name, overload, SEQUENCE
    /its executed 7000 per day and its top logical i/o consuming .
    Whats the functionality behind that ?
    How can I speak with developers to get rid of that :) ?
    DB is 9.2.0.8
    Regards
    GregG

    Whats the functionality behind that ? A quick search over the Internet shows that it seems related to this Java class :
    oracle.jdbc.OracleDatabaseMetaData.getProcedureColumns

  • Another strange query

    hi,
    the call:
    patient = (PPatient)pm.getObjectById(patientId, true);
    yields to the following sql statement:
    SELECT COUNT(*) FROM PPATIENT, PPATIENT t0 WHERE t0.OID = ?
    this is a dramatically performance problem for us.
    the patientId is an id returned by
    pm.getObjectId(patient);
    then
    commit;
    and then getObjectById
    the above call behaves the same with or with or without an active
    transaction!
    thanks in advance
    matthias.stephan

    Matthias & Tibor-
    Good catch. You are right: the SQL we are issuing is sub-optimal. I've
    made a bug report for this at:
    http://bugzilla.solarmetric.com/show_bug.cgi?id=613
    You can expect it to be fixed in the near future.
    In article <[email protected]>, Tibor Varga wrote:
    Hi,
    This is something I was also pondering about. Can you explain why the
    query performed by Kodo is faster than this one:
    SELECT COUNT(*) FROM PPATIENT t0 WHERE t0.OID = ?
    This one does not count the number of rows in the given table, it either
    gives you 1 or 0, depending on the existence of the sought record.
    I feel I'm missing something tricky here. Thank you,
    Tibor
    Marc Prud'hommeaux wrote:
    Matthias,
    Passing the "true" argument to PersistenceManager.getObjectById
    indicates that the JDO system must verify that the object exists in the
    datastore. Thus, Kodo is performing the validation in as fast a way as
    it can.
    If you do not want datastore-side validation, and instead just want to
    grab the object from the cache, then pass "false" as the second
    argument.
    See also:
    http://www.solarmetric.com/javadoc/jdo/javax/jdo/PersistenceManager.html#getObjectById(java.lang.Object,%20boolean)
    In article <b59hmm$dai$[email protected]>, Matthias Stephan wrote:
    hi,
    the call:
    patient = (PPatient)pm.getObjectById(patientId, true);
    yields to the following sql statement:
    SELECT COUNT(*) FROM PPATIENT, PPATIENT t0 WHERE t0.OID = ?
    this is a dramatically performance problem for us.
    the patientId is an id returned by
    pm.getObjectId(patient);
    then
    commit;
    and then getObjectById
    the above call behaves the same with or with or without an active
    transaction!
    thanks in advance
    matthias.stephan
    Marc Prud'hommeaux [email protected]
    SolarMetric Inc. http://www.solarmetric.com

  • Strange query behaviour

    I have a simple select query having a like statement as
    select * from table where name like %sami%
    This query behaves differently when run in the MS Access DB and when run from the Java code.
    when i remove the LIKE stmt then its behabiour is normal but when i use LIKE (sometimes with % and sometimes with *) the query does not return anything from the Java code.
    it works fine within Access DB
    whats the problem?
    Thanks

    try this
    '_sami_'
    or
    without ' '
    sami
    i don't know exactly....
    just try it out

  • Strange query plans, and so different results from a view.

    In my database (11g), I have a currency exchange rate table, which contains all currencies and their exchange rate to USD. I need to have a number of different exchange rates - To GBP, EUR, etc...
    To accomplish this I have created a view, which has one union statement of all the USD exchange rates, with the same data joined back on itself to give the exchange rates based on their exchange rate to USD - ie: SELECT b1.Date, b1.Currency AS FromCurrency, b2.Currency as ToCurrency, b1.Rate/b2.Rate as Exchange Rate FROM Rates b1, Rates b2 on b1.Date = b2.Date
    This view works fine when I query it, and returns the data as I expect.
    I have a second view that is joined to this view to give a return of the amount in each currency for reporting. This view seems to work correctly when I narrow down the search requirements and have a small set of data.
    The issue I am having is when I query the second view and get it to return all the data. Instead of receiving 4 rows per transaction (I am only interested in 4 exchange rates for display) I typically receive up to 2 rows. The first record is for the conversion to USD, the second record is for the conversion to the supplied currency. The issue is that this exchange rate actually includes the aggregate for all 3 other requested currencies (not the USD).
    So instead of getting something like:
    Amt RC BC (Amt = Amount, RC = Reporting Currency. BC = Base Currency)
    60 GBP GBP
    80 EUR GBP
    100 USD GBP
    1000 ZAR GBP
    60 GBP USD
    80 EUR USD
    100 USD USD
    1000 ZAR USD
    I get the following set of results:
    1140 GBP GBP
    100 USD GBP
    100 USD USD
    Has anyone come accross something similar or have any ideas on how I can resolve this?
    Thanks
    PS: I can get both sets of results from the same view depending on the filter criteria. Also if I convert the exchange rates into a table, it then returns the correct results as expected.

    943081 wrote:
    The idea is to seek help in solving the problem. I was hoping that perhaps someone had experienced the same thing - different results for "effectively" the same query:Well, that's the issue... without additional info, it's not clear what issue you were seeing.
    SELECT * FROM view WHERE Date = '01 January, 2012'
    verse
    SELECT * FROM view WHERE Date > '31 December, 2011' ORDER BY DateNow it's a bit clearer. That second query is not "effectively" the same as the first query. If the date column is in DATE format, then you ought to have a to_date() around the date string to explicitly convert it into a date so you can do date-to-date comparisons correctly. Also, DATE datatype stores times as well as dates, so asking for data matching midnight of a specific date is different than asking for data greater than midnight of the previous day.
    If the date string is a string, then ... well, the string "31 December 2011" is greater than the string "31 August 2013", despite it being an earlier date. This is why making sure you're using the right datatype for the job is important - a date is different to a string that just happens to contain a date.
    DateID
    I have no objection to using a Date but always struggle to understand what someone means when they tell me "06/07/2012" - granted if the day is above 12 or the same day and month I don't have a problem - but it still leaves 121 days a year that are confusing. sure, but just because you find outputting the display (or rather, someone else's output) confusing doesn't mean you still shouldn't use the correct datatype. Store things as a date, and you can then output it in whatever format you like. Try doing that with a string or a number.
    Don't say it doesn't happen as I got a birthday card from a company in May this year when I have specifically entered my date of birth as being the 5 of a month (name drop down box on their website)!Just because someone else doesn't understand how to work with dates correctly doesn't mean you can't! It's not exactly rocket science, after all!*{;-)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Grouping Inner Query based on a column.Please help

    I have a strange query.
    I am using Subquery to display the count of rows from the inner query
    depending upon the value of 'Y' or 'N'
    Trade
    id_entity       id_inst_code_type   id_inst_code   dt_trade
    AGL            SE                  5660249        10-Feb-06
    AGL            SE                  5660249        13-Feb-06
    AGL            SE                  5660249        13-Feb'06
    Instrument_xref
    ID_inst      id_inst_xref_type     id_inst_xref  flg_active
    0029010             SE          5660249          Y
    0070789          SE          5660249          Y
    0071190          SE          5660249          Y
    0072385          SE          5660249          Y
    0073215          SE          5660249          Y
    0084797          SE          5660249          Y
    0091375          SE          5660249          Y
    0094690          SE          5660249          Y
    0104438          SE          5660249          Y
    My output:
    id_inst_code_type          id_inst_code   Earliest    Latest       Total    Active
    SE                         5660249       10 Feb 06   13 Feb 06    3        9
    2) If all the 'flg_active' column in Table Instrument_xref is set to 'N'
       the Active should be 0.
    3) Assume that the flg_active could be 3 Y's and 6 N's then what?
    id_inst_code_type          id_inst_code   Earliest    Latest       Total    Active
    SE                         5660249       10 Feb 06   13 Feb 06    3        0
    How do I check for the 'Y' or 'N' value in my code below ?
    Help appreciated as the the functionality changes by the hour...
    select    tie.id_entity             'Entity',
              tie.id_inst_code          'Inst Code',
              min(tie.dt_trade)         'Earliest',
              max(tie.dt_trade)         'Latest',
              count(*)                  'Total',
              dt.InnerTotal             'Active'   
    from     trade_input_event tie,
    (Select  insx.id_inst_xref_type,
                   insx.id_inst_xref,
                   insx.flg_active,
                   count(*) InnerTotal
      from instrument_xref insx
      where insx.id_inst_xref = '5660249'
      ---** Do I need to Check the flg_active here..
      ---** Do I need to use the Having clause here? ie having count(insx.id_inst_xref) = 'N'
       group by insx.id_inst_xref_type,insx.id_inst_xref,insx.flg_active) dt
      where tie.id_inst_code = dt.id_inst_xref
      and tie.id_entity = 'AGL'
      group by tie.id_entity, tie.id_inst_code_type,tie.id_inst_code

    As the flg_active is set to 'Y', I am trying to set it to 'N' in the query
    so that count of 0 is returned, but this displays nothing.
    Please help as to how to display a count(*) of 0 when the flg_active is 'N'??
    Select  insx.id_inst_xref_type,
                   insx.id_inst_xref,
                   insx.flg_active,
                   count(*) InnerTotal
      from instrument_xref insx
      where insx.id_inst_xref = '5660249'
      and insx.flg_active = 'N'
      group by insx.id_inst_xref_type,insx.id_inst_xref,insx.flg_active) dt

  • Query to retrieve rows from database

    hi ,
    I have a strange query " My oracle database contains around 4000 records. As it is not advisable to retrieve all the rows at the time. Is it possible for me to retrieve the rows 100 in a page and then the next hundred and then the next....... Not sure whether we can write a PL/SQL command for this or we need to tweak the database to show such options. Can anyone suggest on this please ????

    Hi,
    That's called a Pagination Query , and here's one way to do it:
    WITH     got_r_num     AS
         SELECT     x.*     -- or whatever columns you need
         ,     ROW_NUMBER () OVER (ORDER BY u_key)     AS r_num
         FROM     table_x
    --     WHERE     ...     -- If you need any filtering, put it here
    SELECT       *     -- or list all columns except r_num
    FROM       got_r_num
    WHERE       TRUNC (r_num / 100)     = :page_number
    ORDER BY  r_num
    ;U_key is whatever unique key determines the order. It can be a single column, or a comma-delimited list of expressions, as in any ORDER BY clause. fOR EXAMPLE:
    ...     ,     ROW_NUMBER () OVER ( ORDER BY       UPPER (last_name)
                             ,          UPPER (first_name)
                             ,          created_date     DESC
                           )     AS r_num

  • Query Requirment

    Hi
    I had a strange Query Requirement....and wondering is there any way to achieve this with out using Cell editor
    In columns i had Previous,Current and Next Year in months (3*12=36) (Restrictions on Current Cal year Variable and Month)
    In Rows Formula...but the formula should be Populated with KF X for all the months Less than current month and Populated by Y for all months Greater than Current Month
    Any options

    So you want if curent is Feb:
           lastJan   curJan nextJan lastFeb curFeb.....
    F:    X            X          Y         X           Y
    define formula variable FV1 replaced by key 0calyear and FV2 replaced by key 0calmonth
    F= (FV1<curent year)X+(FV1=curent year)(FV2>=Curent month)Y+(FV1=curent year)(FV2<Curent month)X+(FV1>current year)Y
    see note 1385580 about formula var

  • How to count number of sales orders generated in a month in SAP SD

    Hi SD Gurus,
    I have a very strange query from client. I have to count the number of sales order created in a month for a z report. For example 30 in Jan, 25 in Feb etc. Could anyone suggest me How to count number of sales orders generated in a month in SAP SD.
    Regards
    Vinod Kumar

    Hi,
    Goto the T.Code "SE16" or "SE16n" or "SE11".
    Enter the table name as VBAK
    Enter the created on date as the starting date of the period and to date as the end date.
    Enter.
    Click on "Number of Entries".It will tell you the number of entries created in a particular period.
    If you want a report,goto the T.Code "VA05n".
    Regards,
    Krishna.

Maybe you are looking for

  • PDF converter and combine PDF pages are blank?

    I signed in to Adobe and tried to use the PDF converter, but the page is blank.  The combine PDF page is blank also.  What happened?  I can see the other tabs, but these two are blank.  Need to know what is going on. Thanks.

  • Exporting events in iphoto

    Hi - I am running the 2011 version of Iphoto (version 9.2.3) off Snow Leopard and have had iphoto crash twice in the last year.  The last time, I had to bring my data in to get recovered.  Now, I'm trying to get save all my photo by event folders ont

  • Handshake error

    When perfoming handshake I am getting the following error. Not sure where the error is and what is causing the error Please help Thanks, ============================================= Failed When Handshake : java.lang.IllegalArgumentException javax.ne

  • (Junk-)Mail and setting up a new computer

    Hi all, Naturally, I do not very often replace my computer, but every time I need to set up a new computer I run into this issue with Mail.app which annoys me. I am a relatively heavy mail user (I have about 24.000 messages in my inbox on a gmail-acc

  • Port Translation (Non to Standard Ports)

    Hi Guys I would like some advise/ideas on the best solution for the below. I have a application server which uses non standard HTTP/HTTPS ports. What I want is a solution to translate these ports to standard ports. Client 1 accesses the site on port