bad result of 10g using sys_connect_by_path, COUNT (*) OVER (PARTITION OF...)

Hello

I get incorrect results when I run my SQL on Oracle 10.2.0.4 prod database.
When I run the same SQL on Oracle 11.2.0.1 prod database, I get the results I expect.

See the PATH_TO_EMP_ROOT column in 10g (all are null, why?)

Here's the SQLs and respective results on Oracle 10.2.0.4 prod database:
create table TEST_WITH_EMP_TABLE
(
  EMP_ID NUMBER(5) NOT NULL,
  EMP_NAME VARCHAR2(100) NOT NULL,
  MGR_EMP_ID NUMBER(5),
  CONSTRAINT TEST_WITH_EMP_TABLE_PK
      PRIMARY KEY (EMP_ID) USING INDEX,
   CONSTRAINT TEST_WITH_EMP_TABLE_FK1
      FOREIGN KEY (MGR_EMP_ID)
      REFERENCES TEST_WITH_EMP_TABLE(EMP_ID) ON DELETE CASCADE
);

INSERT INTO TEST_WITH_EMP_TABLE  VALUES (10, 'Emp1', null);
INSERT INTO TEST_WITH_EMP_TABLE  VALUES (20, 'Emp2', 10);
INSERT INTO TEST_WITH_EMP_TABLE  VALUES (30, 'Emp3', 20);
INSERT INTO TEST_WITH_EMP_TABLE  VALUES (40, 'Emp4', 30);
INSERT INTO TEST_WITH_EMP_TABLE  VALUES (50, 'Emp5', 10);
INSERT INTO TEST_WITH_EMP_TABLE  VALUES (60, 'Emp6', 50);
INSERT INTO TEST_WITH_EMP_TABLE  VALUES (70, 'Emp7', 10);
INSERT INTO TEST_WITH_EMP_TABLE  VALUES (80, 'Emp8', null);
commit;

select level as EMP_LEVEL, 
       sys_connect_by_path(EMP_ID, '/') as PATH_TO_EMP_ROOT, 
       COUNT(*) OVER (PARTITION BY level, MGR_EMP_ID) as EMPS_COUNT,
       EMP_ID, EMP_NAME, MGR_EMP_ID
from TEST_WITH_EMP_TABLE
START WITH MGR_EMP_ID IS NULL
CONNECT BY NOCYCLE PRIOR  EMP_ID = MGR_EMP_ID
ORDER BY EMP_LEVEL, MGR_EMP_ID;

EMP_LEVEL   PATH_TO_EMP_ROOT    EMPS_COUNT  EMP_ID  EMP_NAME    MGR_EMP_ID
---------   ----------------    ----------  ------  --------    -----------
1           (null)              2           10      Emp1        (null)
1           (null)              2           80      Emp8        (null)
2           (null)              3           20      Emp2        10
2           (null)              3           50      Emp5        10
2           (null)              3           70      Emp7        10
3           (null)              1           30      Emp3        20
3           (null)              1           60      Emp6        50
4           (null)              1           40      Emp4        30
Exact same SQL running on * 11.2.0.1 Oracle database * as a result of results (than I expected on 10.2 as well):
EMP_LEVEL   PATH_TO_EMP_ROOT    EMPS_COUNT  EMP_ID  EMP_NAME    MGR_EMP_ID
---------   ----------------    ----------  ------  --------    -----------
1           /10                 2           10      Emp1        (null)
1           /80                 2           80      Emp8        (null)
2           /10/20              3           20      Emp2        10
2           /10/50              3           50      Emp5        10
2           /10/70              3           70      Emp7        10
3           /10/20/30           1           30      Emp3        20
3           /10/50/60           1           60      Emp6        50
4           /10/20/30/40        1           40      Emp4        30
Y at - it a bug known RDBMS? Any change that I can do to get this working on 10.2, SQL database as well?

The other strange thing is that if I remove the
COUNT(*) OVER (PARTITION BY level, MGR_EMP_ID) as EMPS_COUNT
the select part of SQL on 10.2.0.4 DB column, the
 PATH_TO_EMP_ROOT 
I get now is correct even on the 10.2 database.

Kind regards
Vivek.
select level as EMP_LEVEL,
       sys_connect_by_path(emp_id, '/') as path_to_emp_root,
       --COUNT(*) OVER (PARTITION BY MGR_EMP_ID) as EMPS_COUNT,
       EMPS_COUNT,
       emp_id, emp_name, mgr_emp_id
from (select emp_id, emp_name, mgr_emp_id,
      count(*) over (partition by mgr_emp_id) as emps_count
      from TEST_WITH_EMP_TABLE)
start with mgr_emp_id is null
connect by nocycle prior   emp_id=mgr_emp_id
ORDER BY EMP_LEVEL, MGR_EMP_ID;

Tags: Database

Similar Questions

  • Count on column month function gives bad result

    Hello

    I'm on OBIEE 11.1.1.7.150120.

    I used the count on the column for the month function and instead of getting 12 as the answer I get 365. (I used a filter on the column year to restrict to one year)

    How could it happen?

    Any help would be appreciated.

    A count on your back 1661600 fact table is not strange because it is normal to have a ton of lines (zero, one or more for each value of your dimensions).

    If you look at the physical SQL what is it? 365 days is because of 1 line of time Sun has multiple matches on your fact table or is dim because your time is at the level of the day (again 365 is really a strange number: exactly the number of days in the year...).

    But the distinct count is your solution, because as soon as your will a request using your time and dimension of any other table with County you will count the number of lines and not the number of months.

  • bad results for the search for context on the empty element tags

    I use Oracle DBMS 11.1 and 11.2 and created an index on an XML column context (article group: PATH_SECTION_GROUP).
    When you enter a query like

    SELECT count (*) FROM my_table t WHERE contains (t.co_xml,'hasPath(/tag1/tag2)') > 0

    I get bad results if tag2 is an empty element tag (< tag2 / >) that appears somewhere in the
    XML instance, but is NOT directly under tag1.

    For example, the following XML instance is (but shouldn't!):

    < a >
    blah blah < tag3 > < tag1 > < / tag3 > < / tag1 >
    blah < tag4 > < tag2 / > < / tag4 >
    < /a >

    This seems to happen only for the empty element tags. Is this a known bug and does anyone know of a workaround?

    Thank you in advance for your help!
    Roman

    Like you, I've been looking in the wrong places, bug of thought, rather than documented behavior. Finally, I came across the following excerpt from the next section of the documentation on haspath in Oracle text reference.

    http://download.Oracle.com/docs/CD/B28359_01/text.111/b28304/cqoper.htm#i997393

    Limits

    Because of the way in which XML data section are saved, false match may appear with XML sections that are completely empty as follows:

    
    

    A query of HASPATH(A/B/E) or HASPATH(A/D/C) falsely corresponds to this document. This type of fake correspondent can be avoided by inserting some text between the empty tags.

  • Problem using RANK() over (partition of)

    Hello

    I have a select statement that selects a single record among the many recordings sorted by date!

    SELECT the isin code, id, mkt, CTL, TM

    Of

    (SELECT isin, id, mkt, CTL, TM,

    Rank() OVER (partition by isin arrested by ASC TM) RNK

    CORD)

    where "CPOS" = id

    and "SSEFN" = mkt

    AND rnk = 1

    By this statement, I will get a single record (rnk = 1 so it select the first record)

    But the problem is that whenever there is only one record (qualifying) it does not appear in the result set.

    And I also need this record! My goal is always a single record , no matter how they are!

    I joined record a sample and also the script table here!

    SE0001ACPCNESSSSS2013-04-16 06:55:37
    SE0005ACPCNESSSSS2013-11-04 06:57:16

    CREATE TABLE cord

    (

    ISIN VARCHAR2 (13 BYTE) NOT NULL,

    ID VARCHAR2 (33 BYTE),

    VARCHAR2 (20 BYTE) TM,

    TMMILL NUMBER (13).

    TMMILLREC NUMBER (13).

    VARCHAR2 (49 BYTE) NM,

    MKT VARCHAR2 (11 BYTE) NOT NULL,

    CTL VARCHAR2 (4 BYTE)

    )

    ;

    Hello

    Louis wrote:

    Hello

    I have a select statement that selects a single record among the many recordings sorted by the timestamp!

    Whenever you have a problem, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
    Explain, using specific examples, how you get these results from these data.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

    Remember, RANK may return the same value for multiple lines in the same partition.

    If you have exactly 1 for each value in each partition, use ROW_NUMBER instead of RANK.

  • BAD RESULTS WITH OUTER JOINS AND TABLES WITH A CHECK CONSTRAINT

    HII All,
    Could any such a me when we encounter this bug? Please help me with a simple example so that I can search for them in my PB.


    Bug:-8447623

    Bug / / Desc: BAD RESULTS WITH OUTER JOINS AND TABLES WITH a CHECK CONSTRAINT


    I ran the outer joins with check queries constraint 11G 11.1.0.7.0 and 10 g 2, but the result is the same. Need to know the scenario where I will face this bug of your experts and people who have already experienced this bug.


    Version: -.
    SQL> select * from v$version;
    
    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE    11.1.0.7.0      Production
    TNS for Solaris: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - Production

    Why do you not use the description of the bug test case in Metalink (we obviously can't post it here because it would violate the copyright of Metalink)? Your test case is not a candidate for the elimination of the join, so he did not have the bug.

    Have you really read the description of the bug in Metalink rather than just looking at the title of the bug? The bug itself is quite clear that a query plan that involves the elimination of the join is a necessary condition. The title of bug nothing will never tell the whole story.

    If you try to work through a few tens of thousands of bugs in 11.1.0.7, of which many are not published, trying to determine whether your application would be affected by the bug? Wouldn't be order of magnitude easier to upgrade the application to 11.1.0.7 in a test environment and test the application to see what, if anything, breaks? Understand that the vast majority of the problems that people experience during an upgrade are not the result of bugs - they are the result of changes in behaviour documented as changes in query plans. And among those who encounter bugs, a relatively large fraction of the new variety. Even if you have completed the Herculean task of verifying each bug on your code base, which would not significantly easier upgrade. In addition, at the time wherever you actually performed this analysis, Oracle reportedly released 3 or 4 new versions.

    And at this stage would be unwise to consider an upgrade to 11.2?

    Justin

  • My m4v videos to view a preview, but now it is a generic white band 'film' with a blue dot. I used to fly over the icon and preview would play. Previews were an easy way of the video ID. How can I restore previews?

    My m4v videos to view a preview, but now it is a generic white band 'film' with a blue dot. I used to fly over the icon and preview would play. Previews were an easy way of the video ID. How can I restore previews? OS X El Capitan 10.11.4

    I'm ' dropped in ' the answer! By changing the name of the ".m4v" to ".mov" file preview is now fixed! Billy just got lucky...

  • Bad results value amplitude and phase

    I try to add two Phasers of tension and to get incorrect when simulated results on Multisim using the frequency unique AC analysis. I changed the amplitudes of analysis AC from both sources to their respective values of 20 and 15 volts. The result of the addition should be size = 25 volts peak and phase = 66.87 degrees, which does not match results of Multisim. What I am doing wrong?

    Thank you in advance.

    You must click twice on the fickle source V1 and V2 and the "AC size' and the 'magnitude of AC Phase', change the settings.

    Also, depending on your preference, select Options of Simulation global preference, time = 0 if you want the right to shift to change phase or left, you can configure it here.  This setting affects your calculation of phase.

  • How to tell if someone uses my count at home when I'm not home?

    Original title: who was on my computer.

    Probably a stupid question, but I've never had to ask before.  How to tell if someone uses my count at home when I'm not home?

    You can examine (eventwvr.exe) Event Viewer system log. He recorded each logon.

  • Acrobat DC more bad results of the marking of Word 2010

    Does using Acrobat DC and Word 2010 usually produced marking poor results? Everything gets the tag, but 95% of the labels are incorrect and role mapping is in every sense (title 1 title [final paragraph, text body mapped to title 2, etc.). Fortunately, lists and tables come out well. The results were not significantly different between a Word well formatted, built from a solid model structure or file Word a bit chaotic, riddled with direct formatting.

    I am relatively new to mark the PDF files for accessibility, and I wonder if I would get better results by using Word 2010 with Acrobat X or XI or Word 2013 2016 with Acrobat DC. My goal is to have structured accessible PDF files without the need of treatment of syndrome of carpal for my hands.

    Yikes! Certainly worth a try a newer version of Word to see if you get the best results, although I use Word 2010 and 2015 and have not noticed a huge difference. A rate of 20% on average, cleaning is a reasonable expectation, IMHO.

  • I can't open the InDesign program, which I have been using now for over 18 months...  He starts to open then crashes, I uninstalled/re-installed the program and always without success.

    I can't open the InDesign program, which I have been using now for over 18 months...  He starts to open then crashes, I uninstalled/re-installed the program and always without success.

    Hi all

    A hotfix is now available for licensing.

    Please click on the link below and follow the steps.

    Easy steps to follow and should help you to solve the problem.

    https://helpx.Adobe.com/InDesign/KB/crash_on_launch.html

    Thanks and greetings

    Kaushik Afonso

  • Why my desktop fonts not appear as an option to use in Muse over?

    Why are my Office fonts is not appear as an option to use in Muse over? I know that my office fonts aren't secure web and export as image... But I would still like to have them as an option. Why this departure with the latest version? I can't find anything in the preferences or menus to make them appear as an option. I am running OSX 10.9.4 and Muse 2014.0.1.30 CL785017. Help, please!

    Hello

    Desktop fonts (System) are still supported. We have not removed this possibility in 2014.0. Looks like you have encounter a bug.

    Have you recently installed a new font? Try to uninstall and try again.

    Another thing to try is to close the Muse, rename the file fonts.db (see below) to something else and restart Muse. To locate the fonts.db:

    In Finder, click go > go to folder (CMD + SHIFT + G), type ~/Library/Preferences/com.adobe.AdobeMuseCC.2014.0/Local store

    Abhishek

  • I can do this (use a counter 'i' the instance name)

    Hello

    I have 5 dynamic text object in my scene and I need to make a treatment for them (compare each one to the other)

    my text instance names are:

    0, to1, 2, to3, to4

    and their names of variables are:

    T0, t1, t2, t3, t4

    what I have to do is:

    If (t0>t1) then 0 moves to the place of to1 and to1 will move instead of 0

    up to now, I have no problem to compare 2 elements and change their place, but what happens if I have a large number or an unknown number of items, I know that I can (must) a loop but the problem is that I can't do this

    For examle, let's say I have 10 items:

    for (i = 0; i < 10; i ++) {}

    {If (t [i] > {t [i + 1])}

    Exchange (to [i], to [i + 1]);

    }

    }

    This code perfectly work when I work with a table

    I hope that you understand my problem, I don't need someone to tell me how to apply sorting in a table all the I want, it's the ability to use a counter on a MovieClip instance variable name, DynamicText, etc...

    Thank you

    If you follow what I offered in your other post, it would be something like...

    for (i = 0; i<>

    {if(t[i]>t[i+1])}

    Exchange (this ["on" + i], this ["to" +(i+1));

    }

    }

  • count the number of lines without using the count function

    Hello
    How count the number of lines without using the count function?

    Thank you

    Assuming that your statistics table are updated:

    select num_rows
    from   all_tables
    where  table_name = 'YOUR_TABLE_NAME_IN_UPPERCASE';  
    

    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14237/statviews_2105.htm#REFRN20286

  • Interview with case/when &amp; sum() over (partition) producing unexpected lines

    Since some time ago, I asked a question in this forum on an unusual problem of join and subtract ( subtract the total periods of highest level duration ). I had what seemed like a work request. So far, I could not really use it. Now that I'm looking closer results, I think that there is something wrong with it, but I can't understand why it's happening.

    Using the definition of the table of the original question, the following simple query shows a special extract of the data I'm looking at.

    Select duration, event_type, start_time, code_range, request_id from MYTABLE where REQUEST_ID = 'abc '.

    This translates into the following lines (separate columns by ' / '):

    START_TIME/REQUEST_ID/EVENT_TYPE/CODE_RANGE/DURATION
    2010-11-12 01:42:04.0/abc/Junk/publicEntryPoint/2,003
    2010-11-12 01:42:04.0/abc/Junk/webServiceCall/947
    2010-11-12 01:42:04.0/abc/Junk/webServiceCall/969

    Another similar request with REQUEST_ID = 'def' means:

    START_TIME/REQUEST_ID/EVENT_TYPE/CODE_RANGE/DURATION
    2010-11-12 00:22:13.0/def/junk/webServiceCall/788
    2010-11-12 00:22:13.0/def/junk/webServiceCall/1,128
    2010-11-12 00:22:13.0/def/junk/publicEntryPoint/2,003

    What follows is an excerpt simplified query I have a problem with:

    Select value start_time request_id event_type, code_range, duration, case code_range
    When "publicEntryPoint" then length * 2 - sum (duration) over (partition by request_id)
    of another-1
    end inner_duration from MYTABLE where EVENT_TYPE = 'spam' and trunc (START_TIME) = to_date('2010-11-12','yyyy-mm-dd')
    and rownum < 1000;

    Notice the couple of unconventional functions used here, the ' case/when' and 'sum() over (partition).

    This property returns a bunch of lines (count: 999), but here are the two with the particular REQUEST_ID values:

    START_TIME/REQUEST_ID/EVENT_TYPE/CODE_RANGE/DURATION/INNER_DURATION
    2010-11-12 01:42:04.0/abc/junk/publicEntryPoint/2,003/2,003
    2010-11-12 00:22:13.0/def/junk/publicEntryPoint/2,003/87

    The second line is correct. The first line has an unexpected value of INNER_DURATION of 2003. It should be 87 as the second row. I don't understand why this is happening.

    I think that 'and rownum '.<1000" must="" be="" the="" problem.="" it="" must="" be="" excluding="" some="" of="" the="" rows="" needed="" for="" the="" sum.="" the="" analytic="" function="" will="" be="" applied="" after="" this="" condition--see="" the="" sql="">

    Analytical functions are the last set of operations performed in a query, except for the
    final ORDER BY clause. Every joint and every WHERE, GROUP BY and HAVING clauses are
    completed before the analytical functions are processed

    Have you tried the query without this condition?

    Kind regards
    Bob

  • Windows 7 Installer error "Setup could not use the existing system partition because it does not contain the required free space.

    Repeatedly tried to install the upgrade to windows 7 and pure install and get the error message on all partitions available "Setup could not use the existing system partition because it does not contain the required free space.  All 3 partitions on a single disk have over 90 GB and separated from the disc more than 65 GB of free space according to the properties of the disk and initial screen during installation.  Tried to reformat a partition empty all reinstall Xp sp3 without result.  What can I do?

    Remove the data cable of all drives except the drive that you want to install Windows 7 on.

    Remove all external devices.

    Delete all partitions on the disk leave all of the disc as "unallocated".

    Boot from the Windows 7 DVD and then install, when you reach the point where it asks you to select a drive, click the "Advanced" option and create a new partition (at least 50 GB) to install Windows and continue with the installation process.

    Also: http://social.technet.microsoft.com/Forums/nb-NO/w7itproinstall/thread/1b1adc74-3d94-4897-a3c1-7aabde44fe4b

    JS
    http://www.PAGESTART.com

Maybe you are looking for