a slightly different similar query where clause

Hi all, I am facing a problem with my request.
I have a query that looks like this

with names like
(select name, lastname, id
FROM table1
where id = 1
and type = "enu".
and asset = 'other '.
and cashid = 2
and $vdate = system_date
)
Select * from names
(< joins with other tables)

the thing is that enu value is past as parameter of the procedure. This is only of value if away from the front end.
further, I have to spend 2 different values now ("cae", "peq")
However, for these two values, of what I need not use the active column in where clause and the cashid will have to be change to cashid in (3.4)

I was thinking a dynamic query construction and function of the value pass, I'll build the query. I am looking for another way to implement these changes with minimal impact on the code. Anyone know how to go around this case?

with these two new values for the query are very similar with the exception of the active column that is more use and cashid will include an IN clause. only a value will be in the procedure, either enu, cae, peq. for enu, the query must be as above, but for the other two active column values are not in the query and cashid must be cashid in (3.4). How to take care of these scenarios
with names as
(select name, lastname, id
   from table1
  where id = 1
    and (
    (type = 'enu' and asset = 'others' and cashid =2)
    or
    (type in ('cae','peq') and cashid in (3,4))
    )
    and vdate = system_date
)
select * from names

Max

Tags: Database

Similar Questions

  • Best place to initialize the View object query where clause or params

    Where is the best place to initialize the View object 'where' clause before the page is initially rendered? Or how should it be done?
    Specifically, I can't set these values in the entity or view objects because I need information from the user or information Session
    the user has entered before you navigate to the page. I want to prepare the View object so that the results of the query appears something reasonable
    the first time before using chooses search.

    Note: The view object must exist and I need to access managed beans to define the query.

    Is there an event hook (java code) that can be called before the page is rendered?
    Also, there are hooks that can be called when the user navigates to another tab or page?

    Published by: Greateful Sep 6, 2012 19:48

    Hello

    Check out this blog: https://blogs.oracle.com/aramamoo/entry/an_epic_question_how_to

    Arun-

  • Query where clause of different table without data

    Hello

    Oracle 11g.

    I have a 'Points' table that stores information point.
    In carts, users can record information on these points.
    Then, the user can some carts he wants to apply to display data in a report.

    Here is a minimal example (I hope I didn't too many mistakes):
    create table points (
         pt_id integer,
         pt_type varchar2(1),
         pt_accl varchar2(15),
         pt_class varchar2(10),
         pt_status varchar2(1),
         constraint pk_pt_id primary key(pt_id),
         constraint ck_pt_type check(pt_type in ('B','P', 'S', 'T')),
         constraint ck_pt_status check(pt_status in ('A','E'))
    );
    
    create table carts(
         cart_id integer,
         cart_name varchar2(30),
         cart_current varchar2(1),
         constraint pk_cart_id primary key(cart_id),
         constraint ck_cart_current check(cart_current in ('Y','N')) 
    );
    
    create table user_selected_types(
         ust_id integer,
         ust_cart_id integer,
         ust_type varchar2(1),
         constraint pk_ust_id primary key(ust_id),
         constraint fk_ust_cart_id foreign key(ust_cart_id) references carts(cart_id)
    );
    
    create table user_selected_accls(
         usa_id integer,
         usa_cart_id integer,
         usa_accl varchar2(15),
         constraint pk_usa_id primary key(usa_id),
         constraint fk_usa_cart_id foreign key(usa_cart_id) references carts(cart_id)
    );
    
    create table user_selected_classes(
         usc_id integer,
         usc_cart_id integer,
         usc_class varchar2(10),
         constraint pk_usc_id primary key(usc_id),
         constraint fk_usc_cart_id foreign key(usc_cart_id) references carts(cart_id)
    );
    
    create table user_selected_status(
         uss_id integer,
         uss_cart_id integer,
         uss_status varchar2(1),
         constraint pk_uss_id primary key(uss_id),
         constraint fk_uss_cart_id foreign key(uss_cart_id) references carts(cart_id)
    );
    
    insert into carts values (1, 'cart_1', 'N');
    insert into carts values (2, 'cart_2', 'Y');
    insert into carts values (3, 'cart_3', 'Y');
    
    insert into points values (1, 'B', 'AAA', 'AAKCM', 'A');
    insert into points values (2, 'B', 'BIONH1', 'AAKCM', 'A');
    insert into points values (3, 'B', 'BIONH1', 'AAKCM', 'E');
    insert into points values (4, 'B', 'CTF1', 'RF45Q33', 'E');
    insert into points values (5, 'T', 'L4C', 'H4V1', 'A');
    insert into points values (6, 'T', 'L4C', 'H4V1', 'E');
    insert into points values (7, 'S', 'BIONH1', 'RX4', 'A');
    insert into points values (8, 'S', 'L4D', 'L2585', 'A');
    insert into points values (9, 'S', 'L4D', 'L2585', 'E');
    insert into points values (10, 'S', 'CTF1', 'CCMBQX', 'A');
    insert into points values (11, 'S', 'CTF1', 'CCMBQX', 'E');
    insert into points values (12, 'S', 'CTF2', 'CCMBQX', 'A');
    insert into points values (13, 'S', 'CTF2', 'CCMBQX', 'E');
    insert into points values (14, 'P', 'H4', 'L44W', 'A');
    insert into points values (15, 'P', 'H4', 'L44W', 'E');
    insert into points values (16, 'P', null, 'RK', 'E');
    
    insert into user_selected_types values (1, 1, 'B');
    insert into user_selected_types values (2, 1, 'S');
    insert into user_selected_types values (3, 3, 'T'); 
    
    insert into user_selected_accls values (1, 1, 'BIONH1');
    insert into user_selected_accls values (2, 2, 'CTF1');
    insert into user_selected_accls values (3, 2, 'CTF2');
    insert into user_selected_accls values (4, 3, 'L4C');
    
    insert into user_selected_classes values (1, 1, 'AAKCM');
    
    insert into user_selected_status values (1, 3, 'A');
    If a user may for example have the following carts (according to the example above):
    cart_1
    Types : 'B', 'S'
    Accls : 'BIONH1'
    Classes : 'AAKCM'
    Status : [All]
    
    cart_2
    Types : [All]
    Accls : 'CTF1', 'CTF2'
    Classes : [All]
    Status : [All]
    
    cart_3
    Types : 'T'
    Accls : 'L4C'
    Classes : [All]
    Status : 'A'
    When no value is selected for an item, it must return all values.

    For now, I have the following query:
    with t as (select cart_id d from carts where cart_current = 'Y')
    select
         *
    from
         points
    where
         ...
         and (
              pt_type in (select ust_type from user_selected_types where ust_cart_id in (select d from T))
              or not exists (select 1 from user_selected_types where ust_cart_id in (select d from T)))
         and (
              nvl(pt_accl, '' - (null)'') in (select nvl(usa_accl, '' - (null)'') from user_selected_accls where usa_cart_id in (select d from T))
              or not exists (select 1 from user_selected_accls where usa_cart_id in (select d from T)))
         and (
              pt_class in (select usc_class from user_selected_classes where usc_cart_id in (select d from t))
              or not exists (select 1 from user_selected_classes where usc_cart_id in (select d from T)))
         and (
              pt_status in (select uss_status from user_selected_status where uss_cart_id in (select d from T))
              or not exists (select 1 from user_selected_status where uss_cart_id in (select d from T)))
    It works, but the data or mixed...
    If the user apply cart_2 and cart_3, I don't want to for example points to accl "L4C" with status "E", forthcoming.
    I just want to return the union all selected each carts.

    Of course I can loop over Cart ID, PL_SQL, and build the query dynamically, as:
    for cur_c in (select cart_id d from carts where cart_current = 'Y') loop
         l_query := l_query || 'select ... from ... where ...' || ' union all ';
    end loop;
    l_query := substr(l_query,1,length(l_query)-11);
    But imagine the user ask 500 wagons..., I've reached the limit of varchar2.
    I can't use a CLOB that I use Oracle APEX to view the report, and he expects the query a varchar2.

    I don't want to use a temporary table, as it is too slow for the application (I've tested).

    You have a solution?

    Thank you.

    Yann.

    Thanks for create/insert statements - makes it much easier to help :D

    Here's one way:

    SQL> select
      2  c.cart_id,
      3  p.pt_id,
      4  p.pt_type,
      5  p.pt_accl,
      6  p.pt_class,
      7  p.pt_status
      8  from carts c
      9  cross join points p
     10  where c.cart_current = 'Y'
     11  and ( not exists(select null from user_selected_types ust where ust.ust_cart_id = c.cart_id)
     12     or p.pt_type in (select ust.ust_type from user_selected_types ust where ust.ust_cart_id = c.cart_id)
     13      )
     14  and ( not exists(select null from user_selected_accls usa where usa.usa_cart_id = c.cart_id)
     15     or p.pt_accl in (select usa.usa_accl from user_selected_accls usa where usa.usa_cart_id = c.cart_id)
     16      )
     17  and ( not exists(select null from user_selected_classes usc where usc.usc_cart_id = c.cart_id)
     18     or p.pt_class in (select usc.usc_class from user_selected_classes usc where usc.usc_cart_id = c.cart_id)
     19      )
     20  and ( not exists(select null from user_selected_status uss where uss.uss_cart_id = c.cart_id)
     21     or p.pt_status in (select uss.uss_status from user_selected_status uss where uss.uss_cart_id = c.cart_id)
     22      )
     23  order by
     24  c.cart_id,
     25  p.pt_id
     26  ;
    
       CART_ID      PT_ID P PT_ACCL         PT_CLASS   P
    ---------- ---------- - --------------- ---------- -
             2          4 B CTF1            RF45Q33    E
             2         10 S CTF1            CCMBQX     A
             2         11 S CTF1            CCMBQX     E
             2         12 S CTF2            CCMBQX     A
             2         13 S CTF2            CCMBQX     E
             3          5 T L4C             H4V1       A
    
    6 rows selected.
    

    The cross join creates all the possible combinations of carriage/point. Then they are checked for 4 columns according to your rules. I think that the result is correct, if I read your question right?

    If it's the most effective depends a lot on your actual data. Are the usual cases each cart sets a very small subset of points, or each cart will usually define a substantial part of the points. Carts of how are your tables? How many tables of user_selected_? How is the distribution? How many points? Indexes are available?

    If the data are such that it can "pay" to build all of the possible production and "weed" down, then the foregoing can be very effective. If the data is such that the result is usually very small subset then the effectiveness may depend on the index are available.

    Test and see if it works for you ;-)
    If it takes hours, so if please give some information on the quantity and distribution of the data and the expected quantity and size carts etc. Then we could think in a different way...

  • selection of values to query where clause

    Hi guys, it of maybe a silly question but do not know if I approach the solution in the correct engineering.

    At the top of my form, I framed that the user fills out the different values. These values are then used to refine the query results in the block below. I know that I can go in the datablock being interrogated and set the where the clause equal to the value of the text boxes above, but I don't feel it is the right place to do it.

    If I do like this when the above text box is empty, it returns no results when infact I want to ask all if the values are left white. So should I put it in motion pre? If so how should we do?

    Any help would be greatly appreciated.

    Thank you.

    In the trigger of the QUERY before block you, just put the value in the corresponding element

      :block.name := :ctrl.selection ;
    

    François

  • Complex Inner Join and outer subquery where clause to join internal?

    The DDL for this post was too big and I had to put on my site:
    http://www.harbortownsolutions.com/DDLForDORTable.txt

    My goal is to create a report of sales data for 116 stores containing daily sales and count of comments in recent years. My challenge is that I am pulling data from the same table, but with different dates to get data from last year and the week in data from date of last year.


    The dates used for reports are:

    SalesDate = 06/04/2009
    SalesDateForLastYear = 2008-06-05
    SalesDateBeginningOfWeek = 01/06/2009
    SalesDateBginningOFWeekLastYear = 2008-06-02

    PSEUDOQUERYS:
    ---======= DOLLAR VARIANCE = You Said you have $100 worth of meat(inventory) but you only have $50 worth of meat
    SELECT 
        BUSI_DATE as BusinessDate, 
        ORACLE_KEY as StoreID,
        FIELD1  as Sales,
        FIELD2  as GuestCount,
        FIELD3  as DollarVariance,
        FIELD4  as Cars
    FROM MYDAILYTOTALS
    WHERE Busi_date = SalesDate
       AND ORACLE_KEY IN (SELECT StoreID From MyStores); 
    -======= ONLY Guest count and Sales are needed in comparisons against last year    
    ---======    Last YEar dates = corresponding dates for this year ie Tuesday of this 
    week matched to Tuesday of last year (except for leap year)
    SELECT 
        ORACLE_KEY as StoreID
        FIELD1  as SalesLastYear
        FIELD2  as GuestCountLastYear   
    FROM MYDAILYTOTALS
    WHERE Busi_date = SalesDateForLastYear 
       AND ORACLE_KEY IN (SELECT StoreID From MyStores);
           
    
    SELECT 
        ORACLE_KEY as StoreID
        SUM(FIELD1)  as WeekToDateSales
        SUM(FIELD2)  as WeekToDateGuestCount  
    FROM MYDAILYTOTALS
    WHERE Busi_date BETWEEN SalesDateBeginningOfWeek and SalesDate
       AND ORACLE_KEY IN (SELECT StoreID From MyStores) 
    GROUP BY ORACLE_KEY 
       --=======  
    SELECT 
        ORACLE_KEY as StoreID
        SUM(FIELD1)  as WeekToDateSalesLastYear
        SUM(FIELD2)  as WeekToDateGuestCountLastYear  
    FROM MYDAILYTOTALS
    WHERE Busi_date BETWEEN SalesDateBeginningOfWeekLastYear and SalesDateLastYear
       AND ORACLE_KEY IN (SELECT StoreID From MyStores) 
    GROUP BY ORACLE_KEY   
    Question: Since they all use the same store of nbrs, I specify on each request? Can't I just specify only once on outer query Where clause?

    Also, how would fit the following of HOEK script:
    See how I put 1 field based on another field value

    He reads a record for each store of 116 stores in the database. There are 2 situations that have been addressed by Hoeks code:
    For each of the 116 stores in the store table, there must be 1 and only
    registration of 1 stock to match the record of MyStoreTotals. However, sometimes there is no record of inventory.
    and sometimes there will be 2 (in a case where a manager of database updates)
    After daily treatment) files. If so, the record with Is_posted = 1
    is the one that should be included in the query. The following text accomplishes this:
    -chr (39) is the single quote
     Select StoreId, 
             DollarVariance 
      from   (select store.storeid, 
                       case
                              when inv.storeid is null then 'None'
                              when inv.is_posted = 0 then 'NP'
                              else chr(39)||inv.total_dol_var||chr(39)
                        end as DollarVariance, 
                        row_number() over (partition by store.storeid order by inv.is_posted desc) rn  
                   from  myInven inv 
                   right outer join mystores  store
                                  on store.storeid = inv.fk_str_main_id
                                  and inv.busi_date = to_date(SalesDate, 'dd-mon-yyyy'))
          where rn = 1;      
    Can I put this request on the place where clause of the outer to query I put on a JOIN clause?

    So I guess that's why you used the MAX.

    That is right.
    I used CASES to identify and complete the necessary columns since the first set of results (WITH).
    So then I more or less "swivels somehow" lines of this result set to the columns, each store will appear once the most.

  • Passing the value of the where clause with the page

    Dear friends,

    I have a requirement like when I select a selection list value I should pass this value to sql query where clause without submitting the page

    ex I have a select like: P1_Dept guess I selects the value 10 in this

    then I have a query select * from emp where deptno =: P1_Dept.

    DB. ORACLE 11G

    APEX 4.1.1.00.23

    is this possible? can someone help me please in this topic

    Thanks and greetings

    Vballeda

    Suppose we have the selection list with the name P1_DEPT and query for report

    select * from emp where deptno = :P1_DEPT
    

    We create dynamic Action on the evolution of the P1_DEPT point. We will need two real actions:

    1-> set value action

    Set the Type - > body of the PL/SQL function

    The function of body - > return 1;

    Page item to submit-> P1_DEPT

    Change to delete-> Yes event

    Selecttion Type-> trigger element

    2. action-> Refresh

    Selecttion Type-> region

    Region-> your region of report

  • How to change where clause in VO interview at the bean

    Hi experts

    I need to change vo object query where clause execution... is - it possible?

    If so please suggest me.

    as mentioned by Timo, it is quite possible

    See this link-

    Change in the WHERE clause or query on VO when running in Oracle ADF | Techartifact

    Dynamically change the query in the view object in Oracle ADF | Techartifact

  • NVL selection list does not not on the place where clause in query

    Ok. APEX 4.2...

    Im having problems with my selection lists and NULL values... I see that it has come time and time again...

    I have a tabular presentation, with a query based on a selection list.  The selection list has the ability to '- Show All -'... The value of the selection list is a number, and the display is words...  (for reference the LOV query is: select status, batch from pmt_stat_lookup by 1)

    Initially I had problems with null and invalid numbers like ' display Null = 'Yes' and the problem of null % ', so have used the code in this blog to remove the NULL values... Display Null = & amp; #34; Yes & amp; #34; and the problem of null % | Inside Oracle APEX by Patrick Wolf

    Then in the application of my report, I have a where clause clause that checks the value of the selection list... WHERE batch = nvl(:P11_STATUS_SELECT,STATUS_ID)

    everything works almost fine, and I can choose a status, or I choose - see the All-, but the query will not include the lines where the State is null.

    (I also see that maybe I should be, use the case statement instead of the NVL on where clause, but not sure of the syntax. In addition, NVL was used somewhat in the different reports in the application...)

    For reference, the code of the old blog that I as a process page is:

    BEGIN

    FOR rItem IN

    (SELECT NOM_ELEMENT

    OF APEX_APPLICATION_PAGE_ITEMS

    WHERE APPLICATION_ID = TO_NUMBER(:APP_ID)

    AND PAGE_ID IN (TO_NUMBER(:APP_PAGE_ID), 0)

    AND LOV_DISPLAY_NULL = 'Yes'

    AND LOV_DEFINITION IS NOT NULL

    -change here

    AND LOV_NULL_VALUE = '% null | '%'

    )

    LOOP

    IF V (rItem.ITEM_NAME) = "% null | '%'

    THEN

    Apex_Util.set_session_state (rItem.ITEM_NAME, NULL);

    END IF;

    END LOOP;

    END;

    Thank you very much

    Richard

    Richard,

    Perhaps this example can help you solve your problem.

    https://Apex.Oracle.com/pls/Apex/f?p=63838:2

    Jeff

  • Creation of a where clause clause in the LOV query box

    Hi guys is any able to help me with this one

    I have a page in my application where there down LOV down now values this menu drop-down comes from a table that looks like this

    users_for _form_TBL

    E_MAIL Name of the vendor
    [email protected]Oracle
    [email protected]SAP
    [email protected]IBM
    [email protected]Oracle
    [email protected]Intergraph

    So my syntax for the LOV I mentioned looks like this

    Select PROVIDER as display_value, SELLER as return_value

    of form_user_tab where email =: APP_USER

    order by 1;


    so if [email protected] connects to the application and to make a selection on the LOV it would only show suppliers compared to his E_MAIL like oracle, sap, IBM , and then he clicks the submit button on the page then the seller that he chose is inserted into another table. What I did on the table of insertion has been to create a trigger that after inserting a seller the trigger inserts a 1 in a column called assessed.

    What I did after that is add a select statement in the where clause of the LOV so that she would check in the table insert if this seller had been chosen before and not show them again to be selected my syntax, the second time around in the SQL query box has been

    Select PROVIDER as display_value, SELLER as return_value

    to users_for _form_TBL where email =: APP_USER

    and (select "seller", "ASSESSD' of _tbl inserted is null);

    order by 1;

    But im getting an error of ideas guys. Thank you

    rhisingh wrote:

    hay man thanks for your response really using the syntax is

    Select PROVIDER as display_value, SELLER as return_value

    to users_for _form_TBL where email =: APP_USER

    and (select provider, ESTIMATED from _tbl of nserted where there is no "seller", "RATED")

    order by 1;

    im still get and error is the where the clause allowed in the second select statement

    He still has basic syntax errors. You posted 4 different "table names" whose only in the first query is valid so far. That can not see your database, I don't know what really is the name of these tables, and to what extent these is wrong helps your problem.

    I can tell that you are looking for:

    select
        u.vendor display_value
      , u.vendor return_value
    from
        users_for_form_tbl u
    where
        u.e_mail = :app_user
    and not exists (select null from inserted_tbl_imp i where u.vendor = i.vendor)
    order by
        u.vendor
    

    but the table names could be something else...

  • Optimize query with function in where clause

    Hello

    I have a query like this:

    SELECT * FROM table_1 t
    WHERE
    (
    -- Clause A (very long clause that filters a lot of rows)
    )
    AND f(t.field) = 'Y' -- This function is heavy but it should filter few rows
    

    This query, it is very slow because I think he's trying to evaluate f() for all rows in table_1.

    Howerver, if I have database query:

    SELECT f(t.field) FROM table_1 t
    WHERE
    (
    -- very long clause that filters a lot of rows
    )
    

    It's very fast.

    How can I reference the query to filter the lines of division A, then by function?

    Thanks in advance!

    If you wrap the function in a select clause then the optimizer can use a scalar subquery caching:

    SELECT * FROM table_1 t 

    WHERE  (  -- Clause A (very long clause that filters a lot of rows)  ) 

    AND (Select f(t.field) From Dual) = 'Y' -- This function is heavy but it should filter few rows

  • Order columns (which make up the primary key constraint) matter in where clause of DML query for use of indexing mechanism to operate.

    Version of DB: database Oracle 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production


    I have a table my_table as below:
    create table my_table
    (
    my_code varchar2 (6).
    my_id varchar2 (24).
    forced pk_1 primary key (my_code, my_id)
    );


    Primary_key here's a composite key that contains columns 1 (my_code) and 2 (my_id).
    Is there that a difference in the way below queries is executed in terms of performance (use of indexing in the extraction).

    (a) select * from my_table where my_code = '123' and my_id = "456";
    (b) select * from my_table where my_id = '456' and my_code = '123';


    The understanding I have the order of the column in the where clause should be identical to the sequence in
    What primary key draws for indexing to be used by oracle in oracle other DML queries ignores indexing
    However when I used explain plain both show the same query cost with single scan with index rowid.
    so I don't know if I'm wrong in the concept that I have. Kindly help.

    Thanks in advance,
    Gerard

    Your question is answered in the Performance Tuning Guide

    Using indexes and clusters

    14.1.4 choosing composite indexes

    A composite index contains several key columns. Composite indexes can provide additional benefits compared to the index to single column:

    • Improved selectivity

      Sometimes the two or more columns or expressions, each with a low selectivity can be combined to form a composite with a high selectivity.

    • Reduced IO

      If all columns selected by a query are a composite index, then Oracle may return these values in the index without access to the table.

    A SQL statement can use a path on a composite index if the statement contains constructions that use a main part of the index.

    Note:

    This is no longer the case with the skip index scans. See "Index Skip Scans".

    A main part of an index is a set of one or more columns that have been specified first and consecutively in the list of columns in the CREATE INDEX statement that created the index.

  • Where clause causing a query slow down in a slider

    I have a table "the_table" with about 10,000 rows and four columns (id, description, inventory and category).

    This query returns all of the rows immediately:

    ----

    Select id

    description

    inventory

    from the_table

    where category = nvl (null, category);

    ----

    However, when it is placed in a slider, like this:

    (p_user_category is a variable that is defined by the user, which may be zero if the user wants that all lines)

    ----

    c_results sys_refcursor;

    --

    Open the c_results for

    Select id

    description

    inventory

    from the_table

    where category = nvl (, p_user_category);

    extract the c_results in v_id, v_description, v_inventory;

    close c_results;

    ----

    Then, it takes five minutes to return even just a line when the p_user_category is null.

    However, if I change the where clause:

    ----

    where (p_user_category is null or category = p_user_category)

    ----

    then it returns all the rows immediately.

    He began to be a problem right at the time of the most recent update - I'm under 11.2.0.2.0 (production of 64 - bit).

    The optimizer is smart enough to recognize that null is null, then "nvl (null, category)' collapses 'category' and your 'category = nvl (null, category)' predicate is transformed into 'category is not null' (if it is allowed to be null) or simply - disappears for the test SQL is not the same as the executed PL/SQL.

    In PL/SQL rewrite your manual is not the same logicall than the original at least that you have said category to be non-null because your first testament leaking is to allow the rows with a null category to declare, while the original request would lose their.

    See the implementation plans for the SQL and PL/SQL versions.

    Concerning

    Jonathan Lewis

    http://jonathanlewis.WordPress.com

    Now on Twitter: @jloracle

  • Tuning - using the CASE statement in the WHERE clause of the query

    Hi all

    My request has been changed to use a CASE statement in the WHERE clause to examine the data to some columns based on a parameter value. This modified request is made a full table and constantly running scan. Please suggest what can be done to improve its performance:

    Query:
    SELECT LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))) AS summary_date,
    os.acctnum,
    os.avieworigin_refid,
    COUNT(1) cnt_articleview,
    SUM(NVL(autocompletedterm,0)) cnt_autocompletedterm
    FROM TABLE1 os
    WHERE os.acctnum IS NOT NULL
    AND os.avieworigin_refid IS NOT NULL
    AND os.requestdatetime IS NOT NULL
    AND UPPER(os.success_ind) = 'S'
    
    AND CASE WHEN
    Param_ValueToCheck  = 'FULL' AND get_date_timestamp(os.requestdatetime)  BETWEEN 
    TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
    TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    THEN 1
    WHEN
    Param_ValueToCheck  = 'INCR' AND os.entry_createddate  BETWEEN 
    TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
    TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    THEN 1
    END = 1
    AND CASE WHEN
    Param_ValueToCheck  = 'FULL' AND os.entry_CreatedDate BETWEEN 
    TO_DATE('01-APR-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
    TO_DATE('07-JUN-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    THEN 1
    WHEN
    Param_ValueToCheck  = 'INCR' THEN 1
    END = 1
    GROUP BY LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))), os.acctnum,os.avieworigin_refid;
    Description of the table:
    (Number of lines: approx. > amount 600 000 000)
    Name                           Null     Type       
    ------------------------------ -------- ------------
    ARTICLEID                      NOT NULL NUMBER(20) 
    USERKEY                                 NUMBER(10) 
    AVIEWORIGIN_REFID                       VARCHAR2(10)
    SUCCESS_IND                             VARCHAR2(2)
    ENTRY_CREATEDDATE                       DATE       
    CREATED_BY                              VARCHAR2(10)
    FILENUMBER                              NUMBER(10) 
    LINENUMBER                              NUMBER(10) 
    ACCTNUM                                 VARCHAR2(10)
    AUTOCOMPLETEDTERM                       NUMBER(2)  
    REQUESTDATETIME                         VARCHAR2(19)
    Explain Plan
    SQL> select * from table(dbms_xplan.display);
    
    PLAN_TABLE_OUTPUT
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Plan hash value: 2224314832
    
    ----------------------------------------------------------------------------------------------------------
    | Id  | Operation            | Name              | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    ----------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT     |                   |   590 | 33040 |  2501K  (1)| 08:20:15 |       |       |
    |   1 |  HASH GROUP BY       |                   |   590 | 33040 |  2501K  (1)| 08:20:15 |       |       |
    |   2 |   PARTITION RANGE ALL|                   |   590 | 33040 |  2501K  (1)| 08:20:15 |     1 |1048575|
    |*  3 |    TABLE ACCESS FULL | TABLE1 |   590 | 33040 |  2501K  (1)| 08:20:15 |     1 |1048575|
    ----------------------------------------------------------------------------------------------------------
    
    
    PLAN_TABLE_OUTPUT
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       3 - filter(UPPER("OS"."SUCCESS_IND")='S' AND CASE  WHEN ('FULL'='FULL' AND
                  "OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-04-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
                  "OS"."ENTRY_CREATEDDATE"<=TO_DATE(' 2011-06-07 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN
                  'FULL'='INCR' THEN 1 END =1 AND "OS"."REQUESTDATETIME" IS NOT NULL AND CASE  WHEN ('FULL'='FULL'
                  AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")>=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd
                  hh24:mi:ss') AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")<=TO_DATE(' 2011-05-31 00:00:00',
                  'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN ('FULL'='INCR' AND "OS"."ENTRY_CREATEDDATE">=TO_DATE('
                  2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE('
    
    PLAN_TABLE_OUTPUT
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                  2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 END =1 AND "OS"."ACCTNUM" IS NOT NULL AND
                  "OS"."AVIEWORIGIN_REFID" IS NOT NULL)
    Published by: Chaitanya on June 9, 2011 02:44

    Published by: Chaitanya on June 9, 2011 02:47

    When it is executed individually, MERGE LOGIC 1 and LOGIC of MERGE 2 take about ten for a daterange of 30 days data.

    BUT FULL is to get the scores of APR - JUN, INCR becomes partitions for MAY so not both 30 days.
    Are compare us like with like?

  • Setting in the WHERE clause of the query

    Hi all

    I have 2 tables.

    TABLE_A contains 10 million documents.
    TABLE_B contains 100 records.

    I associate myself with these 2 tables

    Here's a.ID left
    SELECT A.*, B.*
    FROM TABLE_A a, TABLE_B b
    WHERE a.ID = b.ID;
    Here's b.ID left
    SELECT A.*, B.*
    FROM TABLE_A a, TABLE_B b
    WHERE b.ID = a.ID;
    My question is what query will give better performance? I thought that, if we put the column in the table with a lower number of lines on the left, then it will be faster than the other.

    In current versions of Oracle, it does not matter in what order you sum-up your predicates in the WHERE clause of a query: they will be optimized/executed in a way even.

  • where clause to query the hierarchy in the tree Apex area does not

    Hi all

    I am building a tree Menu in Apex 5.0.3 (Oracle 11 g XE), when using when the clause, it does show all the data, but without him, showing all the data.

    I'm trying to populate Tree Menu with data specific to a user successfully logged on.

    (A) table created as HR2. TREE_MENU

    menu_name varchar2 (50).

    number of menu_parent

    number of menu_child

    menu_id varchar2 (12),

    menu_path varchar2 (100),

    number of user_no

    (B) SQL statement for the tree in the Apex region

    Select case when connect_by_isleaf = 1 then 0

    When level = 1 then 1

    else                           -1

    end the status,

    level,

    'Menu_name' as the title,

    NULL as an icon,

    "MENU_CHILD" as a value.

    NULL as ToolTip,

    NULL as link

    to HR2. "" TREE_MENU ".

    -WHERE USER_NO =: P_USERNO

    Start with 'MENU_CHILD' is null

    connect prior "MENU_PARENT" = "MENU_CHILD."

    brothers and sisters of order by 'MENU_ID '.

    Note: also used static value where clause but is not workd.

    that the mistake of me or something else? When using the wizard, she asks (possibly) where clause, this means that when the clause can be used in the SQL statement.

    Help, please.

    Kind regards.

    If you want to prune your tree to show only the elements of the No. 7 usermenu, copy the following code helps you

    select case when connect_by_isleaf = 1 then 0
                when level = 1             then 1
                else                           -1
           end as status,
           level,
           "MENU_NAME" as title,
           null as icon,
           "MENU_CHILD" as value,
           null as tooltip,
           null as link
    from HR2."TREE_MENU"
    start with "MENU_CHILD" is null
    connect by
        prior "MENU_PARENT" = "MENU_CHILD"
        and "USER_NO" = 7
    order siblings by "MENU_ID"
    

    Concerning

    Mahmoud

Maybe you are looking for

  • Can libretto W100 - I use the page GPU Intel driver?

    Firefox application driver Intel HD Graphics at least 8.15.10.2202 activate direct2d, webgl and speed up windows. The current version of toshiba's 8.15.10.2189. Intel offers new versions. Can I download them and install them or I do wrong to my w100?

  • New political opening/closing tab

    I noticed that the tabs, the opening by a link (opens in a new tab), appear next to the tab with a site of origin of this link. So far I like it, but I can imagine a situation where it might be boring. Another thing is closing of tabs. usually when c

  • X 200 horrible experience

    I just wanted to share my story being horrible Lenovo tech support: There was a progressive degradation of the LCD... of hundreds of blackheads started appearing on the screen. Laptop sent to the "DEPOSIT" for repair and he returned with a different

  • My USB ports do not recognize my external devices

    Hello My USB ports are a complete mess. My external drive and my USB is not recognized in one of the ports, my mouse is recognized only in 2 of them, my cam and my mobile are recognized throughout. The external drive, USB key, and mouse already worke

  • my screen is somehow on the side and I can't understand to turn around

    I don't know what I did, but the image on my monitor is vertical not horizontal.  I tried eveery drop down, etc. what IK can find but noithing tells me what to do.