Understand the dynamic conditions in which the clause

Hi all
I have a requirement where I need to dynamically register the conditions in which the clause based on the variable binding.

My condition is like that.

SELECT f.scheduled_date, a.bld_id, a.room_id, a.cage_id, f.test_num
OF feeding_test_results f.
v_onl_gf_anmls one
WHERE f.sak_feeding_test_res > 5000000
AND f.anml_id (+) = a.anml_id
AND f.bld_id = 'A5 '.
AND f.room_id > 0
AND f.cage_id > '0'
-case when: check_value = 1 Then
"AND scheduled_date < = 16 April 2009"
' AND scheduled_date > = 6 April 2009.
On the other
AND scheduled_date = April 16, 2009"
End
AND f.feeding_status <>'X') f



Kindly somebody help me how to do this.


Thank you and best regards,
P. Gesret Devi

michaels2 wrote:

and scheduled_date <= case when :check_value = 1 then date '2009-04-16' end
and scheduled_date >= case when :check_value = 1 then date '2009-04-06' end
and scheduled_date = case when not :check_value = 1 then date '2009-04-16' end

Hmmm, maybe you want some NVL around these statements of cases such as...

       and scheduled_date <= NVL(case when :check_value = 1 then date '2009-04-16' end,scheduled_date)
       and scheduled_date >= NVL(case when :check_value = 1 then date '2009-04-06' end,scheduled_date)
       and scheduled_date = NVL(case when not :check_value = 1 then date '2009-04-16' end,,scheduled_date)

or something like this. Otherwise the comparisons with null will just because all this to fail.

Tags: Database

Similar Questions

  • on the Clause type

    Hi all
    I read some documents oracle and and some examples
    I understand that this model is used to create the table multidimensional and for the prediction of the future.

    but I am not able to write the query using the type clause.
    Please someone help me to understand the clause type base.
    I want everything clause type to start from scratch.

    Please guide me.

    Links: http://rwijk.blogspot.in/2007/10/sql-model-clause-tutorial-part-one.html.
    http://rwijk.blogspot.in/2007/10/SQL-model-clause-tutorial-part-two.html

    There is a post over here in the OTN forum. Please do a search.

    Concerning
    Biju

    Edited by: biju2012 1 Sep 2012 16:02
    (The link for part 2 is provided)

    Published by: biju2012 on Sep 2, 2012 02:45

  • How to use the clause type conditionally create new lines

    This question is just for learning - no object other than to start real world to create versions of some queries known to learn how to measure the performance of the MODEL clause clause of the MODEL versions.

    The question is: How can you write a STANDARD clause that pivots (updates) ONLY the lines that actually need to rotate and do NOT change the lines that have no value and cannot be rotated.

    I found a good site that has about two dozen example articles on different pieces. This first link is the beginning of the series.

    SQL features tutorials - Clause TYPE

    http://www.sqlsnippets.com/en/topic-11663.html

    This link is to a clause of FAQ of BluShadow MODEL version "how to convert rows to columns."

    Line - MODEL method string

    http://www.sqlsnippets.com/en/topic-11987.html

    The solution to this link uses this line of source:

    POSITION KEY VAL

    --- ---------- ----------

    R08 0 v1, v2, v3,.

    and this result set:

    POSITION KEY VAL

    --- ---------- ----------

    R08 1 v1

    R08 2 v2

    R08 3 v3

    The reason why it produces that result set is this clause of the statement of MODEL

    RETURN THE UPDATED LINES

    If you comment on this article, you will see that the original lines are all in position 0. This means that the solution reproduced EACH SOURCE LINE even if there is only one item in the list of values.

    Thus, even a line source with a single value (for example, the r01 'a') will be updated and updated this line is returned.

    For a large number of data sources with only a few lines that actually need to rotate it would be a great performance of infringement.

    This is the sample data source

    with t as (button 1, 'a' value 'abc' col2, col3 'def' of the double
    Select Union all 2, 'b', 'ghi', 'jkl' from dual
    Union all select 3, 'c, d, e, 'mno', 'pqr' from dual.
    Union all select 4, 'f', 'stu', 'vwx' from dual
    )
    Select the key, value, col2, col3
    t

    KEY, VALUE, COL2, COL3
    1, a, abc, def
    2, b, GHI, jkl
    3, "c, d, e, mno, pqr.
    4, f, stu, vwx

    Lines 1, 2 and 4 only have a value of (a, b, c respectively.

    Only line 3 must rotate. It contains "c, d, e" and which must become 3 lines in the result set

    Value of the key, col2 col3
    1 an abc def
    2B ghi jkl
    3 c mno, pqr
    3 d mno, pqr
    3 e mno, pqr
    4 f stu vwx

    The nut of the problem is that if the clause 'RETURN UPDATED ROWS' is used, then the lines 1, 2 and 4 must be updated in order to be returned in the result set. And if this clause is NOT used, then line 3 must be updated by 'c', d, e 'c' and two new product lines: one line for a ' and one for 'e '.

    How can you do this with the TYPE clause without the help of the clause "Return LINES UPDATE"? I don't have a solution to sample showing what I tried because I can't understand what it takes to even try.

    I have a solution that uses "RETURN UPDATED ROWS" but I want to compare this performance to the exercise, when this clause is NOT used.

    We ask BluShadow to add the solution of MODEL clause to this FAQ with other similar solutions.

    Like this?

    SQL > with t as
    () 2
    3 select the 1 key, 'a' val, 'abc' col2, col3 'def' of the double


    Select 4 Union all 2, 'b', 'ghi', 'jkl' from dual
    5 union all select 3, 'c, d, e, 'mno', 'pqr' from dual.
    Select 6 Union all the 4 'f', 'stu', 'vwx' from dual
    7)
    8. Select the key
    9, key_1
    10, val
    11, regexp_substr (val, ' [^,] +', 1, key_1) val_new
    12, col2
    13, col3
    14 t
    model 15
    16 partition by (key)
    dimension (1 key_1) 17
    18 measures (val, col2, col3, (length (val) - length (replace (val, ",")) + 1) as len)
    19 rules
    (20)
    21 val [for 1 to increment of len key_1 [1] 1] = val [1]
    22, col2 [for 1 to increment of len key_1 [1] 1] = col2 [1]
    23, col3 [for 1 to increment of len key_1 [1] 1] = col3 [1]
    24)
    25 order
    26 by key
    27, key_1;

    KEY KEY_1 VAL VAL_N NECK NECK
    ---------- ---------- ----- ----- --- ---
    1 1 has an abc def
    2 b 1 b ghi jkl
    3 1 c, d, e c mno pqr
    3 2 c, d, e d mno pqr
    3 3 c, d, e e mno pqr
    4 1 f f stu vwx

    6 selected lines.

  • Problem with dynamic setting where the clause OFA

    Hi all

    I have a view object with the following query:

    SELECT rownum LINENUM,

    B.line_id LINE_ID,

    B.INVENTORY_ITEM_ID INVITMID,

    B.QUANTITY_DELIVERED PICKQTY

    MTL_TXN_REQUEST_HEADERS a,.

    MTL_TXN_REQUEST_LINES B

    WHERE A.HEADER_ID = B.HEADER_ID

    AND A.MOVE_ORDER_TYPE = 2

    AND "on" =: 1

    AND B.TO_SUBINVENTORY_CODE = NVL(:4,B.TO_SUBINVENTORY_CODE)

    AND A.request_number = NVL(:5,A.REQUEST_NUMBER)

    UNION ALL

    SELECT rownum LINENUM,

    a.wip_entity_id LINE_ID,

    a.INVENTORY_ITEM_ID INVITMID,

    a.QUANTITY_ISSUED PICKQTY

    WIP_REQUIREMENT_OPERATIONS has

    eam_work_orders_v b

    WHERE a.wip_entity_id = b.wip_entity_id

    AND "on" =: 2

    AND a.ATTRIBUTE2 = NVL(:4,a.ATTRIBUTE2)

    and b.wip_entity_name = NVL(:6,b.wip_entity_name)

    I need to dynamically pass a condition to my where clause that I can manage it by setting two binding settings in the query of vo and can pass it on but the problem is the connection variable contains a string like 1311,13112,14445 that I need to spend for a domain like B.line_id in the first query and b.wip_entity_id in the second query , so when I'm passing the string as a value it works fine, but it gives for value separetd by comma prob.

    so I tried passing dynamic where clause, but there is every time that the execution of the first clause only how can I dynamically pass both queries.

    vo.setWhereClause ("LINE_ID in" + wherclause);

    Please help me

    Thnaks

    Deb

    Hello

    Actually I'm passing the parameter to the basic page popup, so in page popup page and the base, I was using the VO even to run then, probably due to that he was running again for all data, so for the basic page I created a new VO and tried to pass the parameter like when clause for questioning now it runs very well Thank you for all your help

  • Query on calculated field where deletes conditions of the clause

    Hi gurus,

    Under a new requirement, we have created a new field calculated in Contact before JC, which removes the condition from which to extract the clause and made full table.

    Requirement:

    We have a field in the user interface, that has data like "J1234" or "K44335". Customer won't see the first character of the alphabet of these data.

    Solution, we have developed:

    (1) create a new calculated field 'ABC person UId Calc' as follows.

    Name: ABC person UId Calc
    Calculated: true
    Computed value: right ([nobody UId], Len([Person UId]) - 1).

    (2) exposed this field in the user interface.

    Question:

    When the user queries in the applet for this field, the generated SQL code has no condition in a Where Clause to the query on PERSON_UID.

    SQL has earlier been something like...

    (T25. EMP_FLG = 'N') AND (T25. PERSON_UID LIKE: 3)

    But after you make this change, the current SQL is trimmed of the just

    (T25. EMP_FLG = 'N')

    This means that this isn't question with PERSON_UID, resulting in an impact huge performance.

    If someone could suggest on this issue, to the difficulty.

    Concerning

    Oh sorry, I guess I missed something.

    I guess the simplest solution is to store the values of redundantly (A, B the value of the value and the value of A + B) and stop using a calculated field.

    You could script something in the PreQuery event, but I think it's an ugly hack.

  • Unable to understand the original clause


    Hi gurus

    I tried to understand what follows where the clause, but still facing problem to understand that and I really appreciate if someone explain it to me step by step and in detail. Thanks in advance:

    Where Clause

    NOT the CASE (min_age = min_min_age

    OR (min_age - 1, rule_id, status_code)

    IN (SELECT max_age, rule_id, status_code

    OF got_analytics

    )

    )

    Concerning

    Shu

    not ( -- simple
      min_age = min_min_age  -- simple
      or -- simple
      (min_age-1, rule_id, status_cod) in (select max_age,rule_id,status_cod from analytics) -- complex
    )
    

    Description for COMPLEX line

    The triplicate (min_age-1, rule_id, status_code)

    must match one of the Geometry produced by:

      (select
          max_age,rule_id,status_code -- your triplicate
        from analytics)
    

    You'll have to check that my logic, but I think that the 'complex' line can be re-written as a clause EXISTS

    EXISTS ( select null
             from analytics A
             where A.max_age = X.min_age - 1
               and A.rule_id = X.rule_id
               and A.status_code = X.status_code )
    

    MK

  • Aggregated value of the column in which referencing Clause

    Hello-

    I am trying to determine how I can accomplish the following the most simple and effective way.

    Among other things, I select the next value in my table:
    max(received_date) as last_received_date
    I also need to assess the value of 'last_received_date' as a condition in my where clause. However, I can't refer to my value in the column alias 'last_received_date', and when trying to evaluate max (received_date) in where clause, I get the error 'group feature is not permitted here.

    Does anyone know of a good workaround?

    Thank you
    Christine

    Hello

    Maybe you can use the HAVING clause:

    Example:

    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as hr
    
    SQL>
    SQL> WITH DATA as (
      2  select to_date('10/02/2009', 'dd/mm/yyyy') as received_date from dual union all
      3  select to_date('10/01/2009', 'dd/mm/yyyy') as received_date from dual union all
      4  select to_date('14/02/2009', 'dd/mm/yyyy') as received_date from dual union all
      5  select to_date('11/01/2009', 'dd/mm/yyyy') as received_date from dual union all
      6  select to_date('15/02/2009', 'dd/mm/yyyy') as received_date from dual union all
      7  select to_date('13/02/2009', 'dd/mm/yyyy') as received_date from dual
      8  )
      9  select max(received_date) from data having max(received_date) > to_date('14/02/2009', 'dd/mm/yyyy');
    
    MAX(RECEIVED_DATE)
    ------------------
    15/02/2009
    
    SQL>
    

    Kind regards

  • Need help to understand the collection

    Hi all

    I'm trying to understand the concept of collection, but when I look in the documentation that exists in google.ca, then, it seems very confusing. If someone suggest me or send me some simple examples and good collection and I really appreciate it. Thanks in advance.

    Concerning

    Line

    Thanks for the explanation, could you please explain what does really to take care of the index as a whole and clause varchar2 and if yes then what condition we use varchar2 index and in which condition we use index as a whole, be we just use index by integer in our daily practice. Really appreciate your response. Thank you

    Generally if you use collections, especially PL/SQL-only collections, your architecture is probably wrong. Collections are rarely necessary, but are often USED in the mistaken belief that they will help performance.

    The use of the collections usually DEGRADES performance, sometimes severely, and they are often used in a way that is not scalable. You should avoid using collections if possible.

    So don't use the collections AT ALL in your 'common practice '.

    For the rare cases where there is to use an array associative index type to use depends on the data type of the element that you will use for the index. If you plan to use a string, then you use INDEX OF VARCHAR2. If you plan to use an integer, then you use INDEX BY PLS_INTEGER.

    What type of index to use has NOTHING to do with performance.

    One of the WORST mistakes developers make is to use an associative array as target of a BULK COLLECT INTO instead of using a TABLE IMBRIQUEE. Collection in bulk is more often used in a FORALL statement so that the elements are accessible only in the order. Useds "indexed" access with associative arrays isn't even necessary or used.

  • Help! I don't understand the mechanics of the plot.

    Hi, I tried to understand the functioning of images in Flash.  I am new to ActionScript, so I don't know the inner workings of the language.  I tried to check the API but no Frame class is listed.  The closest thing is FrameLabel, and which was not useful.  I need to know a few things:

    (1) how do I know what I am?  If there is a class method, for this, what is the exact name?

    (2) how a framework?  I have a code with no timer, only listeners/event handlers, and I have an animation pirated without playing the clips on the line of working time.  The displayed pictures change every time I press an arrow key to move the character.  This isn't really what I want to do however, because I'm the visibility of the many different symbols of switching and update their position according to the original symbol of the player.  Very inefficient.  And does this mean that the frame ahead only when you press a button? Am I moving forward even the frame at all?  I don't know any method of advance structure.

    (3) how to work the frames on the time line?  I have all my symbols on a single image.  I did wrong in my constructor visibility because I don't want something to show when I first load the .swf file.  When I created a second image, everything went crazy and things began to appear.  This suggests that the visibility = false has been done only in the first picture?  What caused the framework change?  I really don't understand.

    Ideally, I would like to make an editable animation dynamically, because game actions will not be linear.  The player character will respond to the controls (which will change the animation) and it will meet the player (which will also change the animation).  I don't think I can do this without understanding management, so please help me.  I am very confused!  It would be cool for pointing me in the right direction as to where I can read about the details of the image.  I tried Adobe Tutorials, documentation, and support but it was not enough.  Is there a place where there is a very in depth explanation on the frames, or someone would be so kind as to taught me to their subject?

    Thanks in advance.

    Hello.

    Without layers. Inside the symbol Bob calle, go to frame 1 another symbol called state1 or how you want to name for the first condition. On frame 2 another symbol with its second State and so on. After that, you can call these States: bob.gotoAndStop (1), bob.gotoAndStop (2), etc.

  • Help to understand the basics of the integration of Javascript/QML

    Hey all!

    I am just development of BB for the first time, so please bear with me. I'm not sure that understand the interaction between JS and QML. I understand that you can write JS in QML, particularly in managers of signals, and I used chunks of it with success. Also, I show/read by the "Javascript in QML" and JS linked in the pages of Qt, which helped a bit.

    However, I am having a few problems incorporating it into my code.  Could you take a look at this and point me in the right direction? (I'm also new to JS itself, so maybe that my mistakes are with this instead?)

    onTriggered: {}

    When an item is selected, we push the recipe Page in the attribute of file chosenItem.

    var chosenItem = dataModel.data (row);

     

    Create the content page and place on top of drill down for it.

    contentPage var = pillDetailPageDefinition.createObject ();

     

    Set the properties of content to reflect the selected image.

    contentpage.contentImageURL = chosenItem.thumbnail

    contentpage.contentName = chosenItem.name + ', ' + chosenItem.mass

     

    * Errors begin to surface in this block *.

    contentpage.contentConsumption = {}

    Guide bar = "With"

    Mistakes of the top line: 'missing}, unknown symbol "guideline", missing colon "guideline", etc.

     

    Boolean multiInstruction = false;

    Top line errors: inconsistent input boolean expected RBRACE

                            

    If {(chosenItem.withFood)

    guideline += "food";

    multiInstruction = true;

    }

    If {(chosenItem.withWater)

    If (multiInstruction) guideline += 'and ';

    guideline += 'water '.

    }

    Return to the guideline;

    }

     


    Thanks in advance! I feel I'm missing something incredibly small/basic

    try calling it without braces.

    You can also create a function directly in QML, no need to export to a js file unless you want to use other components (that are not subcomponents) as well.

    to learn more about the construction of Qt/QML parent, I suggest to read this doc API:
    http://Qt-project.org/doc/Qt-4.8/objecttrees.html

    createObject (this) would create a new component with the parent defined on the object class, and if this is destroyed a new is also destroyed. This is useful when you create components dynamically as you don't have to delete them manually later.

  • Unable to understand the result of the loop


    Hi all

    I got the tracking code:

    Code

    Set serveroutput ON

    DECLARE
    TYPE IS VARRAY months_array (12) STRING (3 CHAR);
    MONTHS months_array: = months_array ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
    BEGIN
    < < list_month > >
    FOR month number IN REVERSE 6.12
    LOOP
    dbms_output.put_line (' number month = ' | number month |) "Items =' | MONTH (MONTHNO));
    CONTINUE list_month
    WHEN number month < 9;
    END LOOP;
    END;

    Code output

    number months = 12 = Dec

    number month = 11 = Nov

    number months = 10 items = Oct

    number month = 9 elements = Sep

    number month = 8 = August

    number month = 7 cells = Jul

    number months = 6 items = Jun

    My question is if you notice the code condition which is CONTINUE list_month number months WHEN < 9 means loop must be output if number month < 9 and according to code loop starting with number months = 12 so system should display the 1st line of output that is number months = 12 elements = Dec , then exit because the loop exit condition is true that is list_month MORE WHEN number month < 9. Please, help me to understand the output.

    Hi Muzz,

    try something like this

    BEGIN
      FOR monthno IN REVERSE 6..12
      LOOP
        exit when monthno < 9;
        dbms_output.put_line('monthno= '||monthno||' Elements='||MONTH(monthno));
      END LOOP;
    END;
    

    concerning

    Kay

  • WITH THE CLAUSE

    Hi all

    I'm using oracle 11.2.0.4

    I m using this for the purpose of learning

    Below is my table and insert statement

    CREATE TABLE COMPANY (NUMBER EMPLOYEE_ID, EMPLOYEE_NAME VARCHAR2 (30), NUMBER OF MANAGER_ID)

    INSERT INTO THE COMPANY'S VALUES (1, 'FRED', ");

    SOCIETY VALUES (2, 'BARNEY', '1');

    SOCIETY VALUES (3, 'WILMA', '1');

    SOCIETY VALUES (4, 'BETTY', '3');

    INSERT IN THE VALUES(5,'PEBBLES','3') SOCIETY;

    INSERT IN THE VALUES(6,'BAM-BAM','4') SOCIETY;

    INSERT IN THE VALUES(7,'DINO','4') SOCIETY;

    INSERT IN THE VALUES(8,'HOPPY','4') SOCIETY;

    WITH RSFC(CK,PK,LVL,HIER) AS

    (SELECT EMPLOYE_ID, MANAGER_ID, 0 AS LVL, EMPLOYEE_NAME LIKE YESTERDAY)

    SOCIETY

    WHERE MANAGER_ID IS NULL

    UNION ALL

    SELECT EMPLOYE_ID, MANAGER_ID, LVL + 1, YESTERDAY. '/' || EMPLOYEE_NAME

    OF THE RSFC R INNER JOIN COMPANY F

    ON R.CK = F.MANAGER_ID

    )

    WIDTH OF SEARCH FIRST BY CK ORDR SET

    SELECT A.LVL, A.CK, A.PK, A.HIER, ORDR

    THE RSFC HAS

    ORDER BY ORDR

    01FRED1
    121FRED/BARNEY2
    131FRED/WILMA3
    243FRED/WILMA/BETTY4
    253FRED/WILMA/PEBBLES5
    364FRED/WILMA/BETTY/BAM-BAM6
    374FRED, WILMA, BETTY, DINO7
    384FRED, WILMA, BETTY, HOPPY8

    First part, I believe, as well, explains Frank

    hierarchical queries

    next part in bold, I need to understand

    Thanks and respect.

    Guylaine

    Hi, lyly,

    You said that you did not understand the part highlighted in your query.  It looks like the 2 lines are highlighted:

    WIDTH OF SEARCH FIRST BY CK ORDR SET

    SELECT A.LVL, A.CK, A.PK, A.HIER, ORDR

    I guess that it's a typo.  The 2nd day of these lines is just the main SELECT clause; This is the 1st line, the clause of the SEARCH, who really needs an explanation.

    As far as I know, the SEARCH clause is only for the sorting of the results.  In other words, the a WITH recursive clause results will be the same, no matter what you put in the SEARCH clause, or if you omit the clause of RESEARCH.  The only purpose of the clause of RESEARCH is to generate the column command (ORDR in your example), which reflects where each row fits in the graph defined by your recursive query.  (Maybe, if you use non-deterministic user-defined functions, it can be a difference in the results.  Chances are, you never have to worry about this).

    If you do not use a clause in RESEARCH at all, it seems like by default

    WIDTH OF SEARCH FIRST BY NULL...

    In other words, the lines appear in order by level and in no particular order after that.  In your case, that would mean 'FRED' would come first, then "BARNEY" and "WILMA" (not necessarily in that order), followed by all the children of 'BARNEY' or 'WILMA' and so on.  No column order would be generated, so you could not guarantee order in the ORDER BY clause.

    I'm not sure that there is nothing you can do with a clause of RESEARCH that you can not do without a.  In other words, the SEARCH clause automatically generates a command column.  I believe you can still create an equivalent ordering column in the recursive query itself.  In your example, you could say

    ORDER BY lvl, ck

    to get the results sorted the same way.  Sometimes, using a SEARCH clause is much more convenient, and I bet that sometimes it is therefore more effective, too.

    2937991 wrote:

    Hi all

    I'm using oracle 11.2.0.4

    I m using this for the purpose of learning

    Below is my table and insert statement

    CREATE TABLE COMPANY (NUMBER EMPLOYEE_ID, EMPLOYEE_NAME VARCHAR2 (30), NUMBER OF MANAGER_ID)

    INSERT INTO THE COMPANY'S VALUES (1, 'FRED', ");

    SOCIETY VALUES (2, 'BARNEY', '1');

    ...

    As always, thank you for posting this information: it really helps!

    Manager_id is a NUMBER, it would be better if you don't quote it.  In other words, it would be more clear, more effective and less prone to say:

    INSERT INTO COMPANY (EMPLOYE_ID, EMPLOYEE_NAME, MANAGER_ID) VALUES (1, 'FRED', NULL);

    INSERT INTO COMPANY (EMPLOYE_ID, EMPLOYEE_NAME, MANAGER_ID) VALUES (2, 'BARNEY', 1);

    ...

    In this example, the unnecessary quotation marks do not hurt a lot, but they do not help all.

  • Question of the Clause

    Hello
    I have a query like the following.
    ------------------------------------------------
    with base as
    (
    Select date, cust_id, amount
    several tables
    Union of all the
    Select date, cust_id, amount
    several tables
    )

    Select * Basic
    where snapshot_date = July 31, 2014"
    -------------------------------------------------
    This query is too long. If I throw ' where snapshot_date = July 31, 2014 ' ' for both selects in the "-with clause", it's really fast. This is because all the tables in the db have indices on the field of snapshot_date.
    It seems that the with clause creates a view with all stereotypes, rather than just July 31, 2014. Y at - there a way to force the "-with clause" to retrieve data for only snapshot_date = July 31, 2014 ' as specified in the main query above without using where clause within the "with clause"?

    Thanks a lot to all the...

    As Gaff has suggested, I begin to believe that the WITH Clause is actually a temporary display based only on what is covered by the clause.

    Maybe it did and maybe it isn't. There is NO value to speculate unless you use this speculation to actually test your assumptions.

    In my case, there are 30 years of history.

    So why do you need to do a UNION ALL operation to get the results? Why can't simply run both queries separately?

    The optimizer does not resemble what data are used.

    More speculation on your part. I can create a simple example of the SCOTT schema on 11.2.0.1.0 vanilla that uses the index.

    create the table emp_copy1 in select * from emp;

    create the table emp_copy2 in select * from emp;

    create index emp_copy1_ndx on emp_copy1 (deptno);

    create index emp_copy2_ndx on emp_copy2 (deptno);

    explain plan for
    with base as
    (
    Select ename, empno and deptno from emp_copy1
    Union of all the
    Select ename, empno and deptno from emp_copy2
    )
    Select * base where deptno = 20;

    Select * from table (dbms_xplan.display_cursor ())

    PLAN_TABLE_OUTPUT

    SQL_ID, 77q19ypwbjkvq, number of children 0

    -------------------------------------

    with base (select empno, ename, deptno emp_copy1 Union all the)

    Select empno, ename, deptno emp_copy2) select * base where

    DEPTNO = 20

    Hash value of plan: 2111487496

    -----------------------------------------------------------------------------------------------

    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |

    -----------------------------------------------------------------------------------------------

    |   0 | SELECT STATEMENT |               |       |       |     4 (100) |          |

    |   1.  VIEW                         |               |    10.   330.     4 (0) | 00:00:01 |

    |   2.   UNION-ALL |               |       |       |            |          |

    |   3.    TABLE ACCESS BY INDEX ROWID | EMP_COPY1 |     5.   165.     2 (0) | 00:00:01 |

    |*  4 |     INDEX RANGE SCAN | EMP_COPY1_NDX |     5.       |     1 (0) | 00:00:01 |

    |   5.    TABLE ACCESS BY INDEX ROWID | EMP_COPY2 |     5.   165.     2 (0) | 00:00:01 |

    |*  6 |     INDEX RANGE SCAN | EMP_COPY2_NDX |     5.       |     1 (0) | 00:00:01 |

    -----------------------------------------------------------------------------------------------

    Information of predicates (identified by the operation identity card):

    ---------------------------------------------------

    4 - access ("DEPTNO" = 20)

    6 - access ("DEPTNO" = 20)

    Note

    -----

    -dynamic sample used for this survey (level = 2)

    Which show the index range scan is done for both tables. These statistics are current since Oracle collected his stats when the indexes have been built

    I think that there is no solution to this problem

    . No, unless indicate you at least a way for us to reproduce the problem.

  • Need to understand the features of LEVEL when printing from 1 to 100

    Can someone please explain to me how the following query?

    SELECT LEVEL just_a_column

    OF the double

    CONNECT BY LEVEL < = 365

    I tried to understand Oracle generator line Techniques - Oracle FAQ , but I did not understand much.

    Hello

    ORA - aff wrote:

    Thanks Frank. I appreciate your response.

    Can you please explain more about how "CONNECT LEVEL <=> works in this query?"

    I understand when it is "CONNECT BY PRIOR emp_id = mgr_id" - for a current line it's going to go and find a row in the table employees whose Manager id is equal to the employee id for the previous line.

    Good!  You already understand the most difficult part.

    In this case, CONNECT BY condition is

    Emp_id PRIOR = mgr_id

    This condition uses emp_id PREREQUISITE, which means that, when deciding if a line will join the game at the level of results = n, he's looking to see what the emp_ids are on LEVEL =(n-1).

    A line will join the LEVEL = 2 if its mgr_id is identical to a level 1 = emp_id.

    A line will join the LEVEL = 3 if its mgr_id is identical to a level 2 = emp_id

    A line will join the LEVEL = 4 if its mgr_id is identical to a level 3 = emp_id.

    ...

    and so on, until you reach a LEVEL where no line do not join.

    But I don't understand "CONNECT LEVEL <=> ?"

    In this case, CONNECT BY condition is just

    LEVEL<=>

    PRIOR is not used in this condition, which means that, when deciding if a line will join the game at the level of results = n, it is not all knowledge on what is on LEVEL =(n-1).

    A line will join the LEVEL = 2 if 2<=>

    A line will join the LEVEL = 3 if 3<=>

    A line will join the LEVEL = 4 If 4<=>

    ...

    and so on, until you reach a LEVEL where no line do not join (which will be LEVEL = 366).

  • Problem with the case where the clause

    Hello

    I want to use cases in which clause. I wrote a very simple query to test how it works. However, I always got an error message. Here's what I did.

    Select eid, firstname, lastname from employee where eid = 1 works fine

    Select eid, name, name of the employee

    where

    cases where 1 = 1 then eid = 1

    When 1! = 1 then eid = 2

    end

    I ORA-00905: lack of keyword.

    Did I miss something?

    Thank you

    Jennifer

    Hi, Jennifer.

    Why do you want to use BOX in a WHERE clause?  The wonderful thing about the CASE is that it allows you to do IF-THEN-ELSE logic.  In a SELECT clause, or an ORDER BY clause, this is really useful, but the WHERE clause already allows you to use the IF-THEN-ELSE logic.

    However, if you use the BOX in a WHERE clause, it is as it does nowhere else.  Always BARGAIN instead of a single expression in a SQL data types.  All the clauses THEN (and ELSE, if there is one) must return a single expression, such as the NUMBER.  (There is no BOOLEAN data type in SQL).  So, you can use a CASE statement like this:

    ...

    CASES WHERE

    WHEN 1 = 1 THEN 1

    WHEN 1! = 1 THEN 2

    END = eid

    Here, the CASE expression takes the place of a NUMBER.

    However, if I was not sure if 1 = 1 or not, I would write the condition in this way, without a CASE expression:

    WHERE (1 = 1 AND eid = 1)

    OR (1! = 1 AND eid = 2).

Maybe you are looking for