A clumsy behavior of the place where the clause on joins

I have a problem to join tables querying. If i:

(1) join two tables
(2) then filter a few lines with 'where '.
(3) then filter the result with another 'where '.

It seems oracle swaps two filtering. It seems wrong for two 'where' clauses cannot be expected.

How to reproduce:
create table table_a(
  n_a Number);
  
create table table_b(
  n_b Number);
  
insert into table_a (n_a) values(1);
insert into table_a (n_a) values(2);
insert into table_b (n_b) values(1);
commit;

create or replace function func(p_n in Number)
  return Number
as begin
  if p_n = 1 then
    raise_application_error(-20100, 'Redwood City, we have a problem');
  end if;
  
  return p_n;
end;
/
The fact that the following query works:
select *
  from table_a
  left join table_b
    on table_a.n_a = table_b.n_b
 where n_b is null;
and it didn't 'has value 1 ='. But
with t as (
  select *
    from table_a
    left join table_b
      on table_a.n_a = table_b.n_b
   where n_b is null)
select * from t
 where func(n_a) = 2
fails, although "func" throws the exception only on the value "1", which I assume to be absent in 't', I have filtered it earlier. The question is exposed both in oracle 10 and 11.

Is this a bug or expected behaviour? In any case, how could avoid dealing with 'where' oracle as commutative?

UPD
Even easier way to reproduce without a user-defined function:
with t as (
  select *
    from table_a
    left join table_b
      on table_a.n_a = table_b.n_b
   where n_b is null)
select * from t
 where 1/(n_a-1) = 2
It will trigger the divide by zero exception.

Published by: 922141 on 24.09.2012 06:17

Published by: 922141 on 24.09.2012 06:25

Hello

The optimizer may choose to evaluate the conditions in an order; He can choose to evaluate the conditions of the main query WHERE clause before it evaluates the conditions in the WHERE clause of the query-sub.
You can force it to evaluate the subquery all first by adding ROWNUM to its result set:

with t as (
  select table_a.*, table_b.*, ROWNUM AS r_num     -- *****  CHANGED  *****
    from table_a
    left join table_b
      on table_a.n_a = table_b.n_b
   where n_b is null)
select * from t
 where func(n_a) = 2
;

Tags: Database

Similar Questions

  • "Invalid column" on the place where several clauses with subqueries and cfqueryparam

    I see a behavior in the cfquery coldfusion I would like to find an exmplanation for.  I have a query that performs a subquery in the select part and if I have several where lines, I get a message 'invalid column name' to find out where my second article, but only when I'm with cfqueryparam

    For example, on what follows, I get "invalid column name «position_id»»

    SELECT department_staff_tbl.*,
    (SELECT max (bookmark_id)
    OF bookmarked_items_tbl
    WHERE item_id = department_staff_tbl.staff_id

    ) AS bookmark_id
    OF department_staff_tbl
    WHERE department_id = < cfqueryparam value = "" #arguments.deptid # "cfsqltype ="cf_sql_integer">"
    AND position_id = < cfqueryparam value = "" #arguments.posid # "cfsqltype ="cf_sql_integer">"
    AND staff_id = < cfqueryparam value = "" #arguments.staffid # "cfsqltype ="cf_sql_integer">"

    If I change the order of my where clause staff_id is first, and then he said "department_id" is an invalid column.

    If I don't have a where clause, it works.  (i.e. WHERE position_id = < cfqueryparam value = "" #arguments.posid # "cfsqltype =" cf_sql_integer">).

    If I remove the where clause of my subquery (WHERE item_id = department_staff_tbl.staff_id) it works.

    This also works if I remove the cfqueryparam where my article so that my query looks like this:

    SELECT department_staff_tbl.*,
    (SELECT max (bookmark_id)
    OF bookmarked_items_tbl
    WHERE item_id = department_staff_tbl.staff_id

    ) AS bookmark_id
    OF department_staff_tbl
    WHERE department_id = #arguments.deptid #.
    AND position_id = #arguments.posid #.
    AND staff_id = #arguments.staffid #.

    Any thoughts?

    A more conventional way to enter your data is without the subquery.  Something like that

    Select fields, the bookmarkid max (bookmark_id)

    from bookmarked_items__tbl join department_staff_tbl on staff_id = bookmark_id

    When etc.

    Some field group

  • Using bind variable to allow the user the place where complete clause.

    Hello

    I have a question like that I am able to run in SQL_Developer:
    SELECT INITCAP(c.name) AS "Species Name"
         , AVG(b.height) AS "Avg Height (m)"
      FROM smt_plot_index a
         , smt_photo_plot_data b
         , smt_species_names c
     WHERE a.plot_id = b.plot_id
       AND b.species_name_id = c.species_name_id
       AND a.plot_id IN (2473201,2473202)
     GROUP BY c.name
    But I'd like to do the following in an apex application:
    SELECT INITCAP(c.name) AS "Species Name"
         , AVG(b.height) AS "Avg Height (m)"
      FROM smt_plot_index a
         , smt_photo_plot_data b
         , smt_species_names c
     WHERE a.plot_id = b.plot_id
       AND b.species_name_id = c.species_name_id
       AND a.plot_id IN ( :P11_ENTER_PLOT_NUMBERS )
     GROUP BY c.name
    But this returns an error:

    error report:
    ORA-01722: invalid number

    I know that if I included only one number for example 2473201 in the element: P11_ENTER_PLOT_NUMBERS it market, but if I try and enter the following text in the element 2473201,2473202 it does not work. The screen session state, said that the value of the item is correct depending on how I entered it.

    Anyone have any solutions for this?
    Thank you
    Ben

    Published by: Benton on May 6, 2010 13:54

    Very strange... read the whole message again, there is already something, you should change: INSTR (': ' |: P11_ENTER_PLOT_NUMBERS |': ',' :'|| a.plot_id |': ') > 0 use INSTR ("," |: P11_ENTER_PLOT_NUMBERS |) ',', ',' || a.plot_id | ', ') > 0

    When you use one as a separator instead of:

    You can try to run in the SQL Developer and see how it works?
    If it works, then you would look in session state to see what values are actually used.

    I tried with BLAKE as a value in P1_TEST and that seems to work:
    Select *.
    WCP
    where INSTR (': ' |: P1_TEST |': ',' :'||) Ename |': ') > 0

    Hope that helps,
    Dimitri

  • As for the Clause on Oracle 10 g db

    Hi experts,

    I had little doubt about my simple request

    When I go through the black book of Oracle for db10g article on the clause
    They stated something like this
    SELECT * FROM EMPLOYEES (EMPLOYEE_ID = '1981');
    on the clause simliar to the place where clause.

    SELECT * FROM EMPLOYEES WHERE EMPLOYEE_ID = '1981'.

    When I run this statement .it fine.

    ' using ' ON clause ' instead of ' where clause.

    He didn't accept the clause on, run the command not properly ended sql.

    where I'm not kidding...?


    Thank you & & looks
    ADF7.

    Version
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

    Oracle provides the clause TO specify join conditions in the SELECT statements involving multiple tables. It is independent of data types and column names. As the USING clause, the clause and NATURAL JOIN are mutually exclusive.

    In cases where the tables participating are more two CLAUSES, Oracle uses the first specification of the clause to join the two tables. He uses the second ON the specification of the clause to combine the next table with the result of the join of the first.
    The key word THERE is also used in other contexts, such as in GRANT and INDEX statements.

    Notes:

    After the keyword ON the join condition is written, in general, it can contain predicates connected with Boolean AND, OR, and NOT
    The order of the tables is not relevant
    The use of parentheses are optional in syntax, but the readability of the increases

    Syntax example:

    SELECT

    FROM TABLE_1

    JOIN TABLE_2

    ON (join condition)

    Usage example:

    The SQL query below shows the employee's name and the name of Department of their work:

    SQL > SELECT E.ENAME, D.DNAME

    EMPLOYEE E JOIN DEPT D

    WE (E.DEPTNO = D.DEPTNO)

  • I liquidated my bar. As the search bar when you type in the web address, and now I can get it back. I handed to the clicked place where I did to trun off (unchecked it), and I don't see anything again?

    I liquidated my bar. As the search bar when you type in the web address, and now I can get it back. I handed to the clicked place where I did to trun off (unchecked it), and I don't see anything again?

    Hold down the key (key in OSX) and press the following letters in this exact order: V T M
    The bar of menus must now appear permanently, unless you turn it off again (view > toolbars). Turn on/off the menu bar is a new feature in version 3.6.

    See the other bars under view > toolbars. By clicking on one of them will place a check mark (display) or remove the check mark (not shown).

    Then, in the Menu bar, go to view-> toolbars-> customize, then press the Restore Default Set .

  • Example: Pavilion 550qe: have just got a QED Pavilion and can not find the place where the monitor.

    Have just got a 550qe of Pavilion and can not find the place where the monitor.   The image on the book they sent shows the exact card, I need but can't find anywhere on the back of the PC.    There are a few plates little who have the drivers there, but do not want to start removing the panels unless this is where some of the connections are hidden.

    Hello

    Can't find the official specs of HP. But since the following specifications

    |-Intel-Core-i7-|-Windows-10-|-Silver.product.100241370.html http://www.Costco.com/HP-Pavilion-550qe-desktop-

    There

    Ports:

    • 2 x USB 3.0
    • 2 x USB 2.0
    • 1 x HDMI
    • 1 x VGA
    • 1 x jack Headphone-out/microphone-in the drop-down list
    • Multi format card reader

    Depending on your monitor, you can use HDMI or VGA to connect. What is your monitor (make and model)?

    Kind regards.

  • im not able to log out of facebook, there is no error, the place where you disconnect everything isn't here

    im not able to log out of facebook, there is no error, the place where you disconnect everything isn't here

    Contact Facebook support.

  • My entry point jumps away from the place where I post (and double-click) my cursor

    I had a lot of trouble with the slider staying in the place where I have the position of the entry point.  I will place the cursor at the end of a sentence - or even in the middle of a sentence for an insert.  Then, when I start typing, the new text will eventually be listed somewhere else in the document.  This occurs in Microsoft Word (2007) and a single Note (2007).  The entry point for the text does not stay when I click the cursor for some reason any.  Does anyone else have this problem?  I work in Vista Home Premium on a Dell Studio 1500 series.  I use a Kensington Expert Mouse to operate the cursor.

    Antaresting,

    Its probably your touchpad. Turn off your touchpad while you write. Sometimes I accidentally type my touchpad with my Palm when I type. Thank you, Jeremy M - Support Engineer

  • I am trying to download Photoshop CS 5 installation stops because I was invited to turn the Notifications of Safari and SafariCloudHisto.  I don't know what they are and the places where to disable them.  Help, please.  I use a macbook pro.

    I am trying to download Photoshop CS 5 installation stops because I was invited to turn the Notifications of Safari and SafariCloudHisto.  I don't know what they are and the places where to disable them.  Help, please.  I use a macbook pro.  How can I find the Notifications of Safari and SafariCloudHisto?

    Guest of installation of close SafariNotificati

    https://helpx.Adobe.com/Acrobat/KB/install-prompt-close-safarinotificati.html

  • I have a Windows Server 2008 R2 system. I use Adobe Acrobat Pro XI. I'm looking for the place where I can change the default font of Calibri Minion Pro? Tools, content editing, formatting

    I have a Windows Server 2008 R2 system. I use Adobe Acrobat Pro XI. I'm looking for the place where I can change the default Miinion Pro to Calibri font?

    Tools, content editing, formatting

    You can't change it.

    Tuesday, January 13, 2015 11:22, tonywaidmann [email protected]>

  • Unexpected behavior with the Option "record in the result.

    Hello

    I have unexpected behavior with the Option "record in the result.

    I have a few steps in the subsequence 'X', this subsequence passes a Boolean parameter. According to the value of the parameter I change the "Recorgind results" Option to report it or not. The thing is that if 'result Recorgind' set at race time I modofy by changing the value of Step.ResultRecordingOption to "Enable" and "Disable", the step is not reported until the same sous-suite 'X' is called for the second time (without changing the parameter passed).

    For example: (Preconditon: result Recorgind Option of all value sous-suite x are defined as Disable)

    1 CallSubsequenceX(Parameter: Enable)

    2 CallSubsequenceX(Parameter: Enable)

    3 CallSubsequenceX(Parameter: Disable)

    4 CallSubsequenceX(Parameter: Disable)

    Expected result:

    1. measures have been reported.

    2. measures have been reported.

    3. measures have not been reported.

    4. measures have not been reported.

    Result:

    1. measures would not same value Step.ResultRecordingOption has been changed to 'enable '. (Not Ok)

    2. measures have been reported. (Ok)

    3. measures reported same value Step.ResultRecordingOption has been changed to 'disable '. (Not Ok)

    4. measures have not been reported. (Ok)

    I use TestStand 2013 (5.1.0.226)

    Thanks in advance.

    -Josymar.

    Hi josymar_guzman,

    I just review the sequence and indeed we´re experience unexpected behavior with the Step.ResultRecordingOption callback. By a reason when you run the callback in the expression before each step section, the statement runs only until the next sequence is called, which is not what we want.

    To avoid this, you can place a statement before each step of the sequence, so you can change the State of the Option "record result" for the sequence running (and it is only the following). You can try something like this

    where the expression of the statement will be the recall "RunState.NextStep.ResultRecordingOption is YourCondition". With this, we guarantee that the results of the next step will be saved or not. I also remove the expression in the expression prior to each step section, because the condition is now on the statement before each step.

    I tried and it works fine. I´ll set the sequence that you share with me, with the changes. I hope this will help you and solve your problem.

  • Different behavior on the eyes; layer names are correct?

    Different behavior on the eyes; scales up and down, left right behaves as expected. All layer names are correct in artificial intelligence. Where to find a solution?Ai_layers_different_eye_behaviors.JPG

    Hmm, the sent JPG seems to be broken.

    But here's a place to look: in the Panel of the puppet, with no layers selected, you should see the behavior of face in the properties panel. Twirl in the group "Handles" to see what parts of the face it found. It shows the layers that you expect to find? (ToolTips will tell you what he's looking for.) Twirl down replacements also to see the layers of flashing. Note that if it does not find a layer of Blink for a certain look, it dimensionnera the eye that you close the eye rather than go to the work of replacement blink.

  • Behavior of the node #visible

    I'm not sure that the behavior of the Node #visible (). According to the API doc's 'Accurate' If this node and subnodes must be made within the framework of the graphic scene.

    The result I get, at least when it is applied to a button and TextField inside a bar of tools, is it is when they are not visible, it is the empty space where they should have been.

    The behavior I want, is that they should not take place at all. Is there a way to do this without removing them from the graphic scene?

    Hello. Mix setVisible and setManaged

            button.setVisible(false);
            button.setManaged(false);
      
    
  • strange behavior on the procedure

    Hello

    Today, in my class I came across a very mysterious behavior of Oracle DB without logical explanation. If anyone knows what this could mean that it would be useful.


    Some cases of training:

    SELECT name
    Employees
    WHERE id_employee IN (SELECT id_employee
    Of employees_seminars
    natural join seminars
    WHERE seminar_name = 'PHP');

    -> This works, lists employees who participated in PHP seminar

    same case with NOT IN:

    SELECT name
    Employees
    WHERE id_employee NOT IN (SELECT id_employee
    Of employees_seminars
    natural join seminars
    WHERE seminar_name = 'PHP');

    -> This works, employees of lists who NOT attended the PHP seminar

    And now comes the interesting - even put in the procedure with cursor + loop + fetch dbms_output (not paste complete SQL here, but would be also possible if necessary) and execution of the procedure, only the variant with NOT IN worked, the other (with only IN) shows nothing!

    Any ideas what could be wrong with that?

    I don't need to work, I was wondering as even the professor asked himself with me, so I decided try to check if this is a bug or what is magic.

    Thanks a lot if anyone would be interested in solving this mystery :-)

    (we use version 10.2.0.1.0 XE)

    Filip

    Hello

    905502 wrote:
    And now comes the interesting - even put in the procedure with cursor + loop + fetch dbms_output (not paste complete SQL here, but would be also possible if necessary) and execution of the procedure, only the variant with NOT IN worked, the other (with only IN) shows nothing!

    In your last post, you posted a procedure of NOT IN. Why, after the procedure which worked and not one that you don't understand?

    Any ideas what could be wrong with that?

    Yes:

    CREATE TABLE "STUDENT2"."SKOLENI"
    ( "ID_SKOLENI" NUMBER(*,0),
    "NAZEV" CHAR(25 BYTE), ...
    

    I suspect that the problem is the CHAR data type.
    Here's everything you need to know about the datayype TANK: do not use it. Use rather VARCHAR2.

    There are rules on how tanks are compared to the VARCHAR2s, and there is probably a subtle difference between what you do one place (where you get them expected results) and somewhere else (where you have not), such as the use of a literal in one place and a variable in another. Such a difference would not matter with a VARCHAR2, but it might with a TANK.
    You can search comparison rules in the manual of the SQL language if you really want to, but it is simpler, just to avoid the completely CHAR data type.

  • Behavior of the filter action "stop filter execution.

    What is the intended behavior of the filter action "stop filter execution"? I can't find any recent documentation on this issue. When part of the filters manually execution, "Stop filter execution" is intended to stop all other filters for all messages if the filter that contains both matches? This seems to be the behavior for me. When included in the first several filters filter, only the first filter matches and the log only shows instances of correspondence of the first filter, although several other subsequent filters must correspond to several messages that don't match not the first filter.

    I appreciate the functionality of Thunderbird filters, but I try to find a solution to implement more complex logical Boolean to move messages from my Inbox with the help of manually run filters. I have several filters put in place to classify the messages, but I want to implement filters such that they are not applied to tracked messages. Currently I have the logic in most filters do not match a favorite message using the option 'Match all the following', however this prevents the use of the logic of the GOLD in the filter and led to an increase in the number of filters. I want to set up the filters as a first filter messages from games played and prevents other filters running only for messages that match the filter first.

    Maybe the behavior I see is a bug specific to my system, but I would like to get a confirmation on the expected behavior and see if others have encountered this problem. I work under the assumption that the behavior of "Stop filter execution" must stop subsequent treatment only for messages on which a filter containing is as indicated in the old post to https://groups.google.com/forum/#! topic/mozilla.feedback.thunderbird.prerelease/rUXaQ0NdZvM, but this assumption may be wrong.

    Any help or suggestions are appreciated.

    OK, it seems that this is a bug documented, for example to https://bugzilla.mozilla.org/show_bug.cgi?id=552936. I should have searched for bug reports before posting here. I follow things with bug reports. Thank you.

Maybe you are looking for

  • the airport does not connect to windows 10.

    Dear community, Eversince I've upgraded to a new deskptop (imac sold and exchanged it for an alienware area51 r2) and since I installed windows 10 on my apple airport computer has stopped working... I have tryd many airport uttilitys programs for win

  • Impossible to use WLAN on my Satellite 5105-s501

    Hello I just bought this computer. I don't know if the 5105 s501 is the L series - I can't find any information anywhere, maybe someone could push me in the right direction. I can't get the wireless to work. I can connect to the internet via a cable,

  • Why my games rolled up to the taskbar at random intervals?

    So my problem is this: I'm playing a game, and with no sign windows puts up the taskbar in random intervals. (It's really annoying). The operating system does not drop an error or warning. I used Windows 7 RC 64-bit since almost 3-4 months and so far

  • How to wake up the monitor

    After not using the PC for a bit, while the monitor going to sleep and the only way to wake up, is to shut down the computer.  We tried to turn the monitor off when we use it, and it'll still sleep.

  • Dell Powerconnect 3548P - a reference not rattling, or allowing access to the web console

    Hello I wonder why we are able to access our PoE switch through the web console http, I can connect via the serial port and the Dell Setup Wizard, we have all the information and our ip address for that switch to 10.0.3.192 255.255.255.0 with a defau