Does row_number() returns different result set every time?

Hi,
I have a query somewhat like the example:
select /*+ parallel (ftstm,4) */
ftstm. term,
sum(ftstm.revenue) revenue,
sum(ftstm.searches) searches,
row_number() over (order by sum(ftstm.revenue)desc) as depth_rank
from
fact_terms
group by
ftstm.term
ORDER BY
revenue DESC
where
depth_rank <= 100000
I have run this query 2-3 times and surprisingly- when I do MINUS on the result sets, I got few records.
Is that possible or am I doing some mistake with this query? Please help...

Nandini wrote:
Hi,
I have a query somewhat like the example:
select /*+ parallel (ftstm,4) */
ftstm. term,
sum(ftstm.revenue) revenue,
sum(ftstm.searches) searches,
row_number() over (order by sum(ftstm.revenue)desc) as depth_rank
from
fact_terms
group by
ftstm.term
ORDER BY
revenue DESC
where
depth_rank <= 100000
I have run this query 2-3 times and surprisingly- when I do MINUS on the result sets, I got few records.well what are you MINUSing from it?
You need to provide us with your database version, example data and expected output (or show us what you are getting)...
{message:id=9360002}

Similar Messages

  • Same query returning different result set

    hi all,
    i am using db 10g.
    i have a query like below
      SELECT SUM(EID_AMOUNT)amt,EID_INCR_CODE,EIH_EFF_DATE
         FROM EMP_INC_HEADER,EMP_INC_DETAILS
        WHERE EIH_EMP_CODE = EID_EMP_CODE
          AND EIH_EFF_DATE = EIH_EFF_DATE
          AND EIH_STATUS   = 'P'
          AND EID_EMP_CODE = '003848'
    GROUP BY EID_INCR_CODE,EIH_EFF_DATE
    ORDER BY EID_INCR_CODE,EIH_EFF_DATE;which is leading to the output
          AMT EID_INCR_CODE   EIH_EFF_D
         2000 BASIC           21-SEP-10
         2000 BASIC           23-SEP-10
         2000 BASIC           15-OCT-10
         2000 BASIC           21-OCT-10
         1200 HTRAN           21-SEP-10
         1200 HTRAN           23-SEP-10
         1200 HTRAN           15-OCT-10
         1200 HTRAN           21-OCT-10
          800 OTHERS          21-SEP-10
          800 OTHERS          23-SEP-10
          800 OTHERS          15-OCT-10
          800 OTHERS          21-OCT-10i have query
    SELECT SUM(EID_AMOUNT)amt,EID_INCR_CODE,EID_EFF_DATE
    FROM EMP_INC_HEADER,EMP_INC_DETAILS
    WHERE EIH_EMP_CODE = EID_EMP_CODE
    AND EIH_EFF_DATE = EID_EFF_DATE
    AND EIH_STATUS = 'P'
    AND EID_EMP_CODE = '003848'
    GROUP BY EID_INCR_CODE,EID_EFF_DATE
    ORDER BY EID_INCR_CODE,EID_EFF_DATE;
    leading to
          AMT EID_INCR_CODE   EID_EFF_D
          500 BASIC           21-SEP-10
          500 BASIC           23-SEP-10
          500 BASIC           15-OCT-10
          500 BASIC           21-OCT-10
          300 HTRAN           21-SEP-10
          300 HTRAN           23-SEP-10
          300 HTRAN           15-OCT-10
          300 HTRAN           21-OCT-10
          200 OTHERS          21-SEP-10
          200 OTHERS          23-SEP-10
          200 OTHERS          15-OCT-10
          200 OTHERS          21-OCT-10
    12 rows selected.what second query is returning is correct. as per the table.
    but my question what is the difference between my first and second query.
    in what way it is different(i am not getting any idea).
    if any one is having any clue please share with me.
    Thanks..

    what is the difference between my first and second queryLook like there's no difference.
    I think you really meant something like
    SELECT SUM(EID_AMOUNT) amt,EID_INCR_CODE,EIH_EFF_DATE
      FROM EMP_INC_HEADER EIH,
           EMP_INC_DETAILS EID
    WHERE EIH.EMP_CODE = EID.EMP_CODE
       AND EIH.EFF_DATE = EIH.EFF_DATE
       AND EIH.STATUS   = 'P'
       AND EID.EMP_CODE = '003848'
    GROUP BY EID.INCR_CODE,EIH.EFF_DATE
    ORDER BY EID.INCR_CODE,EIH.EFF_DATERegards
    Etbin

  • Returning Different Results Based on Input Criteria

    I have a complex nested select statement. Based on selection criteria I want to return different results. Say for instance I had an input parameter Called Products which could contain a Yes/No Flag. If the Flag was Yes then I would want the "top" select, statement to be The following:
    Select Product, Time_ID, Amt
    From
    My Complex Nested Select
    But if Product was set to "No", I would want the following:
    Select Time_ID, Amt
    From
    My Complex Nested Select
    I know, or course that I can have two COMPLETE set of SQL which are invoked based upon testing the value of the PRODUCT Parameter, but If I duplicate the "inner nested select" then I have 2 sets of select staments to maintain. Is there an alternative to this? Could I make the inner portion which does not change a function of some sort so that my code would look something like this?
    Select Product, Time_ID, Amt
    From
    Execute myNestedSelectFunction
    But if Product was set to "No", I would want the following:
    Select Time_ID, Amt
    From
    Execute myNestedSelectFunction
    This would atleast ensure that I only have to go one place to maintain the logic of the "static Nested Select" statement.
    Just want to make sure I do not have a real viable alternative to "duplicating code"
    Thanks

    Hi,
    Look in TFM for PIPELINED functions which will allow you to:SELECT Product, Time_ID, Amt FROM TABLE(myPipelinedFunctionReturningSelectResult()) T;
    SELECT Time_ID, Amt FROM TABLE(myPipelinedFunctionReturningSelectResult()) T;There are samples if you look on AskTom too.
    Regards,
    Yoann.

  • Avoid JDBC sender error: Execute statement did not return a result set

    Hi!
    My JDBC sender adapter towards MS SQL server works fine, with an Execute statement calling a stored procedure that returns the source data needed. The stored procedure itself updates the status of database table records, so that only the unread records are returned each time the stored procedure is called.
    However, the communication channel monitoring sets a red flag for the JDBC sender adapter, when there are no values to fetch from the database table (using the stored procedure). Message says: "Database-level error reported by JDBC driver while executing statement 'EXECUTE FetchMessage 1, 9000'. The JDBC driver returned the following error message: 'com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.'. For details, contact your database server vendor."
    This is not an error situation, as I do not expect there to be any values to fetch from the database at all times.
    I do not see how to change the stored procedure to avoid this error.
    Is there a parameter to be set on the JDBC adapter that I can use, so the red flag is avoided?
    Thanks for any input!
    Regards,
    Oeystein Emhjellen

    Hi Oeystein Emhjellen.
    The problem is Store Procedure that has to generate always a ResultSet (or cursor). If it doesn't have a output, you have to generate an Empty ResultSet.
    Like a SELECT Statement:
    If there are data, SELECT get an output result but if it get nothing the SELECT Statement get a empty ResultSet.
    Ask to your database team.
    I hope it helps you.
    Bruno.

  • To_char(adate,'dd.mm.yyyy')   returns different results  from  two oracle clients !!! Is it  possible?

    Dear all;
    We have only one Database server with some IIS's   as web servers on front . Each web server has own oracle client software in order connect to central database..
    The same following query used in C#  code  returns different results on each IIS server.(3 row, or  not data found )
    why?
    select     *    from    aTable    where        to_char( adate ,  'dd.mm.yyyy' )  =   :search_date
    regards
    Siya

    1006237 wrote:
    If adate is of DATE datatype, it will most likely has the time component. Therefore your SQL below is unlikely to return any data.
    select * from aTable where adate = to_date(:search_date, 'dd.mm.yyyy')
    Perhaps.....
    select * from aTable where TRUNC(adate) = to_date(:search_date, 'dd.mm.yyyy')
    Hi,
    not having any sample data from you I could not understand that you wanted to select the range 00:00:00 - 23:59:59 on search_date.
    Your method might not be efficient if you have an index on adate.
    Maybe something like this will be more efficient
    select * from aTable
    where adate >= to_date(:search_date, 'dd.mm.yyyy')
      and adate <  to_date(:search_date, 'dd.mm.yyyy') + 1;
    If you search_date is 30-Aug-2013 it will get records where adate >= 30-Aug-2013 00:00:00 and adate < 31-Aug-2013 00:00:00, so any time of date 30-Aug-2013.
    Try like this and let us know if you still have 2 different results.
    Regards.
    Alberto

  • Having problems us ng my ipod 7g Nike Fitness.  When running when I press the button between the volume buttons, I get a different action almost every time.

    I am having problems using my ipod 7g with Nike Fitness.  When running when I press the button between the volume buttons, I get a different action almost every time. And usually I end up either turrning volume up very high or ending the workout. I need to be able to pause workout, and get spoken feedback regarding time, distance, and pace, that's all. I'm using a Griffin brand armband, that covers all of the buttons.  I've read the online manual.  no help.  I'm just about ready to return it and go back to my 5th gen with its smaller song capacity and no blurry.  Any help or suggestions very welcome.

    Jeff:
    I have had both good and bad experiences with Acronis True Image. I got the recent copy of ATI via a Newegg.com bundle. I haven't tried it yet on any Windows 7 editing systems. ATI installs some services that I would rather not have running in the background.
    What made you change from ATI to ShadowProtect Desktop Edition?
    Are you running Windows 7?
    What do you see as advantages to running ShadowProtect Desktop Edition as opposed to Acronis True Image?
    Thanks

  • Please Help Urgent:Fast Search returning wrong result sets

    Hi All,
    We are facing below issue with fast search.
    Currently in My project  when  we are searching  for a phrase it is returning wrong result sets.
    For example if we search for “Endura”, It is returning documents related to
    Endura  as well as Centura.
    But the expected results are only Endura documents.
    When we look in to the documents we didn’t find the search term (“Endura” ) either inside document content or in its meta data.
    In order to resolve the issue we tried the below steps
    1-     
    We manually edited and saved the document, to ensure the appropriate Guid association to metadata.
    2-     
    Index reset
    3-     
    Full crawl
    But no luck  so far.
    Please help.Thanks in advance.
    Regards
    Subrat

    Subrat,
    This may be related to spellchecking or may be synonym. Spellcheck is based on indexed terms.
    The best test would be to run the queries from qrserver (13280) and then look at the spellcheck query transformations. If spellchecking is not doing it, then you must have a synonym setup .Check your keyword/synonyms from the SharePoint side. 

  • Does break work for result set ?

    while(rs.next())
    if(true)
    break; // does break work for result set ?
    break is not working when i wanted to go out of while loop like above. how can i go out when condition matches ?

    Well this is what i learned and i'm learning in
    school.So what does your school tell you is the only correct indenting style?
    The "break or not" discussion has been around ever since, and there is no agreed-upon solution that says "always do it" or "never do it".
    You don't have to write nice code. The important
    thing is that you code's performance! This is complete bullshit.
    You client will never read your code, (only if it is
    open source or a script).But the guy who maintains it. Sorry, but this is really ignorant. Unclear code will lead to bugs that are difficult to find and resolve. "Optimizations" will lead to more bugs.
    This all leads to longer development time, late project and increased project and maintenance costs. Ask your customer if he really wants that.

  • Callable Statatement returning multiple Result Sets

    Hello all,
    I've got a stored procedure that will be returning multiple result sets and i was wondering if someone could show me how to pull the multiple result sets out of the CallableStatement object. Any help would be greatly appreciated.

    Here is a sample that does what you want. You will have to substitute the call to DBConn.getConnection() with your own DB connection. Also remove the import of com.ovotron.util.*.import com.ovotron.util.*;
    import java.sql.*;
    public class MultiSQL {
        private static Connection conn = null;
        public static void main(String[] args) {
            // Just gets a connection to the DB.
            conn = DBConn.getConnection();
            getResults(conn);
        * Cycles through multiple result sets returned from a stored procedure.
        * Only the first column is output.
        * <p>
        private static void getResults(Connection conn) {
            // Not sure which DBMS you are using. This is the syntax for
            // SQLServer V7.0.
            String            sql     = "{call getMultiResults}";
            CallableStatement stmt    = null;
            ResultSet         rs      = null;
            int               setNo   = 0;
            try {
                stmt = conn.prepareCall(sql);
                boolean found = stmt.execute();
                while (found) {
                    setNo++;
                    rs = stmt.getResultSet();
                    while (rs.next()) {
                        System.out.println("Result set " + setNo +
                                           ": value: " + rs.getString(1));
                        System.out.flush();
                    rs.close();
                    found = stmt.getMoreResults();
            catch (SQLException e) {
                e.printStackTrace();
            finally {
                try {
                    if (rs   != null) rs.close();
                    if (stmt != null) stmt.close();
                catch (SQLException e) {
                    // Tried already to clean up.
    }The procedure I used is:CREATE PROCEDURE [getMultiResults] AS
    select  col1 from tab1;
    select col2 from tab1;
    select col3 from tab1;Of course you will need to create and populate tab1.

  • How to Create a new column from two different result sets

    How to Create a new column from two different result sets, both the result set uses the different date dimensions.

    i got solutions for this is apply filters in column formula it self, based on the requirement.

  • Why does adobe Premiere Pro CC Crash every time I export a movie file?

    Why does adobe Premiere Pro CC Crash every time I export a movie file?

    Please hand type your posts directly into the browser window.  Copy/Paste leaves unwanted code throughout.
    span style="color: #ffffff; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #000000;"

  • Returning a result set/record from a dynamic query

    There seems to be plenty of examples for using Native Dynamic Sql to formulate and execute a dynamic query, however there are no examples of returning a result set or records which contain the rows of data that are retrieved by executing the query. Could someone give us an example?

    Welcome to the Oracle forum....
    CREATE OR REPLACE PACKAGE curspkg_join AS
    TYPE t_cursor IS REF CURSOR ;
    Procedure open_join_cursor1 (n_EMPNO IN NUMBER, io_cursor IN OUT t_cursor);
    END curspkg_join;
    Create the following Oracle package body on the Oracle server:
    CREATE OR REPLACE PACKAGE BODY curspkg_join AS
    Procedure open_join_cursor1 (n_EMPNO IN NUMBER, io_cursor IN OUT t_cursor)
    IS
    v_cursor t_cursor;
    BEGIN
    IF n_EMPNO <> 0
    THEN
    OPEN v_cursor FOR
    SELECT EMP.EMPNO, EMP.ENAME, DEPT.DEPTNO, DEPT.DNAME
    FROM EMP, DEPT
    WHERE EMP.DEPTNO = DEPT.DEPTNO
    AND EMP.EMPNO = n_EMPNO;
    ELSE
    OPEN v_cursor FOR
    SELECT EMP.EMPNO, EMP.ENAME, DEPT.DEPTNO, DEPT.DNAME
    FROM EMP, DEPT
    WHERE EMP.DEPTNO = DEPT.DEPTNO;
    END IF;
    io_cursor := v_cursor;
    END open_join_cursor1;
    END curspkg_join;
    Dim Oraclecon As New OracleConnection("Password=pwd;" & _
    "User ID=uid;Data Source=MyOracle;")
    Oraclecon.Open()
    Dim myCMD As New OracleCommand()
    myCMD.Connection = Oraclecon
    myCMD.CommandText = "curspkg_join.open_join_cursor1"
    myCMD.CommandType = CommandType.StoredProcedure
    myCMD.Parameters.Add(New OracleParameter("io_cursor", OracleType.Cursor)).Direction = ParameterDirection.Output
    myCMD.Parameters.Add("n_Empno", OracleType.Number, 4).Value = 123
    Dim myReader As OracleDataReader
    Try
    myCMD.ExecuteNonQuery()
    Catch myex As Exception
    MsgBox(myex.Message)
    End Try
    myReader = myCMD.Parameters("io_cursor").Value
    Dim x, count As Integer
    count = 0
    Do While myReader.Read()
    For x = 0 To myReader.FieldCount - 1
    Console.Write(myReader(x) & " ")
    Next
    Console.WriteLine()
    count += 1
    Loop
    MsgBox(count & " Rows Returned.")
    myReader.Close()
    Oraclecon.Close()
    The above code is working in one of our application; which is using ref cursor as result set and get from procedure. I hope you can found more code by google and/or search in this forum as well; if above code is not useful to you.
    HTH
    Girish Sharma

  • Xquery does not return any results on 10.2.0.4, does work on 10.2.0.5

    I have a Xquery statement that works as expected on Oracle 10.2.0.5 but does not return any results on Oracle 10.2.0.4.
    Is this the result of a badly written query? A bug in 10.2.0.4?
    Is there a way to rewrite the query so that is does work on 10.2.0.4?
    Testcode:
    declare
       l_xml xmltype;
       -- Select layers with TileMatrixSet EPSG:28992
       cursor c_layer(p_xml xmltype) is
          select t.*
            from xmltable(xmlnamespaces(default 'http://www.opengis.net/wmts/1.0'
                                       ,'http://www.opengis.net/ows/1.1' as "ows"
                                        ,'http://schemas.opengis.net/gml' as "gml"
                                        ,'http://www.w3.org/1999/xlink' as "xlink"
                                        ,'http://www.w3.org/2001/XMLSchema-instance' as "xsi")
                          ,'for $d in //Layer[TileMatrixSetLink/TileMatrixSet="EPSG:28992"] return $d' passing
                          p_xml columns title varchar2(100) path 'ows:Title'
                          ,format varchar2(100) path 'Format'
                          ,style xmltype path 'Style') as t;
    begin
       l_xml := xmltype.createxml('<?xml version="1.0" encoding="UTF-8"?>
    <Capabilities xmlns="http://www.opengis.net/wmts/1.0"
    xmlns:ows="http://www.opengis.net/ows/1.1"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:gml="http://www.opengis.net/gml" xsi:schemaLocation="http://www.opengis.net/wmts/1.0 http://schemas.opengis.net/wmts/1.0/wmtsGetCapabilities_response.xsd"
    version="1.0.0">
    <Contents>
      <Layer>
        <ows:Title>brtachtergrondkaart</ows:Title>
        <ows:Identifier>brtachtergrondkaart</ows:Identifier>
        <Style isDefault="true">
          <ows:Identifier>_null</ows:Identifier>
        </Style>
        <Format>image/png8</Format>
        <TileMatrixSetLink>      <TileMatrixSet>EPSG:28992</TileMatrixSet>
        </TileMatrixSetLink>  </Layer>
      <Layer>
        <ows:Title>top10nl</ows:Title>
        <ows:Identifier>top10nl</ows:Identifier>
        <Style isDefault="true">
          <ows:Identifier>_null</ows:Identifier>
        </Style>
        <Format>image/png8</Format>
        <TileMatrixSetLink>      <TileMatrixSet>EPSG:28992</TileMatrixSet>
        </TileMatrixSetLink>  </Layer>
      <Layer>
        <ows:Title>bgt</ows:Title>
        <ows:Identifier>bgt</ows:Identifier>
        <Style isDefault="true">
          <ows:Identifier>_null</ows:Identifier>
        </Style>
        <Format>image/png8</Format>
        <TileMatrixSetLink>      <TileMatrixSet>EPSG:28992</TileMatrixSet>
        </TileMatrixSetLink>  </Layer>
    </Contents>
    </Capabilities>');
       for r_layer in c_layer(l_xml)
       loop
          dbms_output.put_line(r_layer.title);
       end loop;
    end;Result on 10.2.0.5:
    brtachtergrondkaart
    top10nl
    bgt

    This one's strange indeed.
    I can reproduce on 10.2.0.4 and one of the following seems to fix it :
    1) Specifying the column list in the SELECT, instead of t.* :
       -- Select layers with TileMatrixSet EPSG:28992
       cursor c_layer(p_xml xmltype) is
          select t.title, t.format, t.style
            from xmltable(or,
    2) Using an extended FLWOR expression :
    for $d in //Layer
    where $d/TileMatrixSetLink/TileMatrixSet = "EPSG:28992"
    return $dMaybe you've already noticed but the problem only occurs within a PL/SQL context.
    The same query run from SQL is OK.

  • Select statement returns different results from 9i and 10g

    Hi all,
    Would appreciate if someone could help to solve this puzzle here:
    I have the exact the statements running on Oracle 9i and 10g, why do they return different results?
    Select unique(GroupDesc) , GroupSeq from Module where ModuleId in (Select ModuleId from User_Access where UserId='admin') and Status='A'
    In Oracle 9i:
    Both columns returned as follows...
    GroupDesc | GroupSeq
    In Oracle 10g:
    Only one column returned, the column with unique keyword was missing...
    GroupSeq
    Could anyone enlighten me?

    yes, the table structure... actually the CREATE TABLE statement...
    with some sample data (INSERT INTO)
    and the actual queries (both of them - copy-paste them from each separate environment)
    you can use tags around the statements this will format it to a fixed font - making it easier to read
    Edited by: Alex Nuijten on Feb 20, 2009 10:05 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Design a procedure which returns a result set of a select Query

    Hi...
    Can some one help me out with a brief design or work around for creating a stored procedure which runs a select Query and Returns a result set...
    If not a stored procedure, at least a function which makes the job simple....
    Awaiting help in this regard ........

    Hi...
    I am sorry for providing insufficient Info...
    Actually I am using Oracle 10G DB...
    I have a select Query..
    Since I am a part of team which is building a Complete Data Driven site, Even an SQL Query and a PL/SQL function body was stored in the Table itself to bring in some kind of Dynamism in the site.... But the master table was loaded with a lot of data and hence Now we decided to Store everythin in a generic package..
    I used REF CURSORS to store a result set of a simple SELECT Query.... and declaring it as an out parameter in my Procedure body so that the JAVA team can directly access the Procedure from the JAVA layer....
    Now I want to know can I do anything more efficient to carry out the above operation....

Maybe you are looking for

  • RB_Split option not found for message split

    Hi all, We're configuring to split a single XML with multiple records into multiple single record XML files. We have referenced the blog: /people/jin.shin/blog/2006/02/07/multi-mapping-without-bpm--yes-it146s-possible but, during interface determinat

  • How to I get my Apple TV to charge to my loaded gift cards instead of my visa

    How to I get my Apple TV to charge to my gift cards already loaded into I-Tunes instead of charging my Visa account?

  • Turn off compatibility mode in Itunes

    Ho do I turn off Compatibility mode in Itunes?

  • CUCM Load Balancing Problem

    Hi All, I have two CUCM 6.1.3 ( I Pub & 1 Sub). All phones registers with sub and all phones use pub for tftp. I am trying to force some phones to register with pub but have no success even new CM group created has pub as first choice & sub as second

  • Windows 2012 R2 Terminal Server

    Hello I have Install Terminal Server on a Windows 2012 R2 Server. My question is how i can hide or disable (connect to a remote  pc) I will not that the user can connect direct to the server.. run only the  App Thox for your help and support