Using ROWID in the ORDER BY clause

Hi,
I can consider myself as a PL/SQL beginner. I need to query some existing tables created for audit scope.
These tables have more duplicate rows respect to the same audit date: the precision is at "hour and minute and second" level.
But I need to understand which is the more recent row for the same audit date. So I think to use in the SELECT statement
the clause ORDER BY in this manner:
SELECT ... FROM Audit_Table ORDER BY Audit_Date desc, ROWID desc.
I'd like to use this ORDER BY also for the ROW_NUMBER function.
Any suggests to me about this topic? Many thanks

I don't need to provide an example, I can do better by pointing you to the documentation:
http://docs.oracle.com/database/121/SQLRF/pseudocolumns008.htm#SQLRF00254
"If you delete a row, then Oracle may reassign its rowid to a new row inserted later" - for example
I can point you to asktom: https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:912210644860
"ROWIDs are NOT sortable" - for example
Your example just happened to work, but you are using the rowid semantically incorrect.

Similar Messages

  • Error : The ORDER BY clause is invalid in views, inline functions, derived

    Hi All,
    I am on 11g 6.2, Windows Server 2008, my db SQL server 2008, I am facing the error for the reports in which I am trying to edit one the column formula and do something like 'abc/sum(abc)*100'.
    10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 43119] Query Failed: [nQSError: 16001] ODBC error state: 37000 code: 8180 message: [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared.. [nQSError: 16001] ODBC error state: 37000 code: 1033 message: [Microsoft][ODBC SQL Server Driver][SQL Server]The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.. [nQSError: 16002] Cannot obtain number of columns for the query result. (HY000)
    One of the solutions to this which I have found is to edit the EXPRESSION_IN_ORDERBY_SUPPORTED feature in the db properties.
    I want to know what does EXPRESSION_IN_ORDERBY_SUPPORTED means?
    When I create a calculations in 11g like abc/sum(abc) in the column formula for a column then i get this error.
    What does this error mean? Does OBIEE 11g doesn't support using these expressions in the report and the fact that it applies the order by clause to the reports, the report fail?
    Could anybody please explain the issue. There is very limited information on this over the web.
    Thanks in advance.
    Ronny

    Thanks svee for the quick response, actually i had resolved the issue by unchecking the EXPRESSION_IN_ORDERBY_SUPPORTED option in the database. I want to understand how does that makes the difference?
    What does EXPRESSION_IN_ORDERBY_SUPPORTED mean? Does it mean that if I give any expression in my answers report and since obiee uses a order by for all the queries, the expression won't be supported?
    Please explain.

  • Can I use an expression in order by clause

    SELECT
    PERIOD_NUM, period_num *12,
    period_name,
    --TO_DATE(SUBSTR(PERIOD_NAME,1,3)| |SUBSTR(PERIOD_NAME,INSTR(PERIOD_NAME,'-'),3),'MON-RR'),
    TO_NUMBER(TO_CHAR(TO_DATE((SUBSTR(PERIOD_NAME,1,3)| |SUBSTR(PERIOD_NAME,INSTR(PERIOD_NAME,'-')+1,2)),'MONRR'),'RRRRMM'))
    FROM GL.GL_PERIODS
    order by 2--TO_NUMBER(TO_CHAR(TO_DATE(SUBSTR(PERIOD_NAME,1,3)| |SUBSTR(PERIOD_NAME,INSTR(PERIOD_NAME,'-')+1,2),'MONRR'),'RRRRMM'))
    desc
    gl_periods is a table, period_name consists of values like oct-01_fy-01 etc and oct01_01_fy-01
    I want to sort on this column based on period_name, so I am trying to convert into number like for oct-01_fy-01, the query gives
    200110 and so on. the recent period comes first, But my question is I can't use the same to_number(.....) in the order by clause. oracle gives an error
    ORA-01843: not a valid month.
    Let me know whether anyone come across with this kind of situation

    If you are sure the expression is correct, since you are using it in the select clause, give an alias and use the alias in the order by clause.
    null

  • Using bind varaible for order by clause

    Hello
    Can some one suggest for the following scenario?
    My order by clause will be constructed based on the selected fields in the form. And now the order by clause need to be passed as parameter to Excel report.
    When I use Ref cursor and OPEN-FOR-USING clause, data is not sorted.
    do we have any other alternate for this?
    Please observe the example code for the same. Block below resembles the code for to select the data for excel report.
    SQL> select * from t;
    T
    sdf
    der
    gdr
    ghft
    ytut
    lkrt
    rtrt
    tyrt
    SQL> declare
    2 l_order_by VARCHAR2 (100);
    3 l_test varchar2(10);
    4 TYPE TEST IS REF CURSOR;
    5 c_TEST test;
    6 L_string VARCHAR2(2000):= 'select * from t order by :pi_order';
    7 begin
    8 l_order_by := ' t DEsc';
    9 open c_test for l_string using l_order_By;
    10 loop
    11 fetch c_test into l_test;
    12 exit when c_TEST%notfound;
    13 dbms_output.put_line (l_test);
    14 end loop;
    15 close c_test;
    16 end;
    17 /
    sdf
    der
    gdr
    ghft
    ytut
    lkrt
    rtrt
    tyrt
    PL/SQL procedure successfully completed.
    Cheers
    Ram Kanala

    My order by clause will be constructed based on the selected fields in the formDoes this look like you need ?
    SQL> var so number
    SQL> exec :so := 1;
    PL/SQL procedure successfully completed.
    SQL> set serveroutput on
    SQL> declare
      2   rc sys_refcursor;
      3   type emprec is table of emp%rowtype index by pls_integer;
      4   erec emprec;
      5  begin
      6 
      7   open rc for 'select * from emp order by ' ||
      8   'decode(:p,1,ename,2,deptno,3,sal,null),' ||
      9   'decode(:p,4,ename,5,deptno,6,sal,null) desc' using :so,:so;
    10   fetch rc bulk collect into erec;
    11   close rc;
    12 
    13   for i in 1..erec.count loop
    14    dbms_output.put_line('Ename = ' || erec(i).ename || ', deptno = ' || erec(i).deptno || ', sal
    = ' || erec(i).sal);
    15   end loop;
    16  end;
    17  /
    Ename = ADAMS, deptno = 20, sal = 1100
    Ename = ALLEN, deptno = 30, sal = 1600
    Ename = BLAKE, deptno = 30, sal = 2850
    Ename = CLARK, deptno = 10, sal = 2450
    Ename = FORD, deptno = 20, sal = 3000
    Ename = JAMES, deptno = 30, sal = 950
    Ename = JONES, deptno = 20, sal = 2975
    Ename = KING, deptno = 10, sal = 5000
    Ename = MARTIN, deptno = 30, sal = 1250
    Ename = MILLER, deptno = 10, sal = 1300
    Ename = SCOTT, deptno = 20, sal = 3000
    Ename = SMITH, deptno = 20, sal = 800
    Ename = TURNER, deptno = 30, sal = 1500
    Ename = WARD, deptno = 30, sal = 1250
    PL/SQL procedure successfully completed.
    SQL> exec :so := 2
    PL/SQL procedure successfully completed.
    SQL> /
    Ename = CLARK, deptno = 10, sal = 2450
    Ename = KING, deptno = 10, sal = 5000
    Ename = MILLER, deptno = 10, sal = 1300
    Ename = JONES, deptno = 20, sal = 2975
    Ename = FORD, deptno = 20, sal = 3000
    Ename = ADAMS, deptno = 20, sal = 1100
    Ename = SMITH, deptno = 20, sal = 800
    Ename = SCOTT, deptno = 20, sal = 3000
    Ename = WARD, deptno = 30, sal = 1250
    Ename = TURNER, deptno = 30, sal = 1500
    Ename = ALLEN, deptno = 30, sal = 1600
    Ename = JAMES, deptno = 30, sal = 950
    Ename = BLAKE, deptno = 30, sal = 2850
    Ename = MARTIN, deptno = 30, sal = 1250
    PL/SQL procedure successfully completed.
    SQL> exec :so := 5;
    PL/SQL procedure successfully completed.
    SQL> /
    Ename = BLAKE, deptno = 30, sal = 2850
    Ename = TURNER, deptno = 30, sal = 1500
    Ename = ALLEN, deptno = 30, sal = 1600
    Ename = MARTIN, deptno = 30, sal = 1250
    Ename = WARD, deptno = 30, sal = 1250
    Ename = JAMES, deptno = 30, sal = 950
    Ename = SCOTT, deptno = 20, sal = 3000
    Ename = JONES, deptno = 20, sal = 2975
    Ename = SMITH, deptno = 20, sal = 800
    Ename = ADAMS, deptno = 20, sal = 1100
    Ename = FORD, deptno = 20, sal = 3000
    Ename = KING, deptno = 10, sal = 5000
    Ename = MILLER, deptno = 10, sal = 1300
    Ename = CLARK, deptno = 10, sal = 2450
    PL/SQL procedure successfully completed.Rgds.

  • The ORDER BY clause is invalid in views, inline functions, derived tables..

    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 43119] Query Failed: [nQSError: 16001] ODBC error state: 37000 code: 8180 message: [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared.. [nQSError: 16001] ODBC error state: 37000 code: 1033 message: [Microsoft][ODBC SQL Server Driver][SQL Server]The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.. [nQSError: 16002] Cannot obtain number of columns for the query result. (HY000)
    I have already tried to follow this thread below, but no change.
    HI
    In this specific report ran above the offending sql uses a CTE.
    I am on 11.1.1.6.1, Windows Server 2008
    Currently in testing phase in migration from 10g.
    I know what the error means, just not how to resolve it or what setting may be causing this.

    In Physical layer, go to specific database(Physical layer's) properties, database features tab -> Un check the EXPRESSION_IN_ORDERBY_SUPPORTED.
    For that failed report, go to Answers-> advance tab-> Look for 'Advanced SQL Clauses'
    Check this box to issue an explicit Select Distinct
    Let me know updates
    If helps Pls mark correct or helpful

  • How to change the order by clause of a standard VO in OAF

    Hi All,
          I need to change only the order by clause of a standard VO (Which is attached to a messageChoice item).
    Steps followed:
    1)Created a custom VO by extending the standard VO .
    2)VO Impl class files are not generated as seeded VO has no such class files.
    3)Created a substitution
    4)Imported it
    5)When I try access the specific page, getting Sys Admin error without any clue about the error.
    Even I tried to create the custom VO without extending the std VO ,
    Still getting the same error .
    Please provide your suggestions on this.
    Thanks,
    Thavam

    When I set the FND:Diagnostics profile option , I could see what was the exact error . It was SQL Wrapper exception error.
    The VO which is extended , has a dynamic where clause with bind variables. The binding style of the extended VO does not match with seeded VO. It works when the binding style is changed.
    Thanks,
    Thavam

  • Using ROWID in the WHERE clause of a SELECT statement

    hi all,
    my team is trying to select a value from a table using the rowid as the selection criterion
    e.g. select column_name from table_name where rowid > 'AAA112BBBCCC12A'
    this query does not appear to return accurate results e.g. it return rows instead of two. my questions are:
    1. is this a legitimate approach?
    2. should we convert the row id to varchar2? if so how should this be done?
    thanks!

    SQL> select rowid,ename
      2  from emp;
    ROWID              ENAME
    AAAs8KAA+AAAVXCAAA KING
    AAAs8KAA+AAAVXCAAB BLAKE
    AAAs8KAA+AAAVXCAAC CLARK
    AAAs8KAA+AAAVXCAAD JONES
    AAAs8KAA+AAAVXCAAE SCOTT
    AAAs8KAA+AAAVXCAAF FORD
    AAAs8KAA+AAAVXCAAG SMITH
    AAAs8KAA+AAAVXCAAH ALLEN
    AAAs8KAA+AAAVXCAAI WARD
    AAAs8KAA+AAAVXCAAJ MARTIN
    AAAs8KAA+AAAVXCAAK TURNER
    AAAs8KAA+AAAVXCAAL ADAMS
    AAAs8KAA+AAAVXCAAM JAMES
    AAAs8KAA+AAAVXCAAN MILLER
    AAAs8KAA+AAAVXCAAO erwer
    15 rows selected.
    SQL> select ename from emp where rowid = 'AAAs8KAA+AAAVXCAAH';
    ENAME
    ALLEN
    SQL> select ename from emp where rowid > 'AAAs8KAA+AAAVXCAAH';
    ENAME
    WARD
    MARTIN
    TURNER
    ADAMS
    JAMES
    MILLER
    erwer
    7 rows selected.1) using rowid to access a record is the quickest way so it is legitimate
    however using > has no real purpose as you point out you cannot get any meaningful results returned.
    2) No real need to convert however beware storing values in tables as Oracle does not guarantee to preserve the format in different versions so upgrading from 9i to 10g would invalidate your data.

  • Sorting technique used by oracle for "order by" clause.

    Hi All,
    it could be very help to me if you provide some information about sorting technique used by oracle engine for order by clause.
    Issue i am facing :
    Table : xx
    Line Date
    1 05-06-2013 00:00:00
    2 05-06-2013 00:00:00
    when we query above table using order by date, it is returning line 2 prior to line 1. we would like to know why it is returning line 2 first?
    Regards,
    Ram

    >
    it could be very help to me if you provide some information about sorting technique used by oracle engine for order by clause.
    >
    Well ok - but be warned that many people wind up being sorry they ask that question. Hopefully Hemant's answer is what you really wanted.
    See 'Linguistic Sorting and String Searching' in the Oracle® Database Globalization Support Guide
    http://docs.oracle.com/cd/B28359_01/server.111/b28298/ch5lingsort.htm
    Sorting will be controlled by the settings of NLS_LANGUAGE, NLS_SORT and NLS_COMP.
    Here is the doc page for NLS_SORT
    http://docs.oracle.com/cd/B28359_01/server.111/b28298/ch3globenv.htm#i1008393
    >
    NLS_SORT specifies the type of sort for character data. It overrides the default value that is derived from NLS_LANGUAGE.
    NLS_SORT contains either of the following values:
    NLS_SORT = BINARY | sort_name
    BINARY specifies a binary sort. sort_name specifies a linguistic sort sequence.
    >
    And the one for NLS_COMP
    http://docs.oracle.com/cd/B28359_01/server.111/b28298/ch3globenv.htm#i1008458
    >
    The value of NLS_COMP affects the comparison behavior of SQL operations.
    You can use NLS_COMP to avoid the cumbersome process of using the NLSSORT function in SQL statements when you want to perform a linguistic comparison instead of a binary comparison. When NLS_COMP is set to LINGUISTIC, SQL operations perform a linguistic comparison based on the value of NLS_SORT. A setting of ANSI is for backward compatibility; in general, you should set NLS_COMP to LINGUISTIC when you want to perform a linguistic comparison.

  • Help Urgent! RowIterator retrieval doesn't respect the order by clause.

    Hi,
    Jdev 10.2.2
    I'm using the RowIterator (source iterator) through a defined association to create rows in a destination RowIterator.
    The creation of those rows must respect the order clause defined for the ViewObject => source Iterator.
    I noticed that when I retrieve the rows through the RowIterator, the order clause is not respected?
    Example of implementation:
    Pre-defined weight levels for a postal tariff:
    Product A:
    From weight To weight
    0 - 10
    10 - 20
    The user will have enter a price for each level.
    I pre-create those rows so that only the price will have to be entered.
    As you see the order of display/creation is important.
    I there a way to make the RowIterator respect the Order Clause defined for the ViewObject?
    I am a bit worried, please tell it's not the default behaviour!
    Thanks
    Frederic
    For info my code:
    RowIterator deliveryWeightIt = weightGroupImpl.getDeliveryWeightAssoc(); // source rows
    if (deliveryWeightIt == null)
    throw new JboException(getClass().getName()+".setWeightGroupId Detail row generation,. System error. DeliveryWeightAssoc is null.");
    deliveryWeightIt.first();
    Row currentDeliveryRow = deliveryWeightIt.getCurrentRow();
    Row newPostalDetail = null;
    try
    while (currentDeliveryRow != null)
    newPostalDetail = postalDetailIt.createRow();
    SequenceImpl s = new SequenceImpl("SITE_POSTAL_REL_SEQ", getDBTransaction());
    Number newSeq = s.getSequenceNumber();
    System.out.println("numberOfGeneratedRows: "+numberOfGeneratedRows+", newSeq: "+newSeq+", FROMWEIGHT: "+currentDeliveryRow.getAttribute(DeliveryWeightImpl.FROMWEIGHT)); newPostalDetail.setAttribute(PostalDetailImpl.FROMWEIGHT,currentDeliveryRow.getAttribute(DeliveryWeightImpl.FROMWEIGHT));
    newPostalDetail.setAttribute(PostalDetailImpl.TOWEIGHT,currentDeliveryRow.getAttribute(DeliveryWeightImpl.TOWEIGHT));
    postalDetailIt.insertRow(newPostalDetail);
    numberOfGeneratedRows++;
    currentDeliveryRow = deliveryWeightIt.next();

    Ok I think I found my mystake.
    I was using the entity association instead of using a view link.
    I avoid using links because I encountered Class Cast exception => similar to thread 10.1.2: view Link accessors in entity object return ViewRow ??????
    Will there be patch available soon?
    Regards
    Frederic

  • How can you make photobook using photos in the order you have them titled

    I spent a lot of time renaming photos ("a1" through "z9") to get them in chrono order when viewing/sorting them by title.  Yet, when I go in to create a photobook it doesn't put them in this new order by title, but rather uses the old naming system which puts them out of order.  Anyone have any ideas how to get photobook to look at the photos by "new" renamed title?

    I put them in chrono order after all all were imported into iPhoto by naming them appropriately.
    No, that puts them in alphabetifcal order, not chronological order.
    What other post?
    I started to repy to this post earlier and somehow aborted the post instead of adding it. 
    If you use the Batch Change ➙ Date option with 1 minuted between photos on the photos as they are sorted by title they will go into the book in that order.

  • Using oracle function in order by clause

    Hello,
    can i use report query or report that generate query like this :
    select fname, lname from peoples order by dbms_random.value;
    dbms_random is an oracle function to generate random value.
    Thnaks

    add the following call to your query:
    query.addOrdering(query.getExpressionBuilder().getFunction("dbms_random.value"));
    --Gordon                                                                                                                                                                                                                                                                       

  • Column Security - Users can't see it, but need to use it in the query WHERE Clause

    I am looking at possible solutions (if any) on column security. We need to be able to restrict users from seeing certain columns, however, they will need these columns in the WHERE clause of queries.
    I thought about creating views, however, it would be a poor database design. Is there any way that this can be done on the database level. I know about Fine Granular Access Method, however, this just excludes the column completely. Which means that they can not be used in the WHERE clause.
    Any help would be greatly appreciated.
    Philip

    I too added 2nd apple ID when I tried to get Free app from apple store just to get to NONE on the credit card needed. It said it sent confirmation email to my new apple ID email that I have to confirm. Problem is I can not get to the new apple ID email account.  On my ipad it logs into my original email account and I see no where to log into another email account.  If I go to my laptop, the new apple ID I created does not let me log into email where apple said it was sent to.  It did not send to back up email account either.
    Can I log into 2 email accounts on my ipad where it says mail at bottom?
    Can I have 2 apple ids?
    If I created a 2nd apple id to get to NONE on credit card needed, can't I log into it also on another laptop in gmail?
    (won't let me)
    If I used my original apple id I created when I got my new ipad, it will not let me get free app without credit card, there is no where it says NONE needed. I am too new to apple to start with credit cards etc until I get use to it.

  • Where do I use flash in the order of things?

    So I am making an animated DVD menu. I want to be able to
    link the words in photoshop with a "#" in front of the name so they
    show up automatically in Encore. Do I do this all in Flash? Or do I
    do something in Photoshop first? Also should I use actionscript 1,
    2 or 3? Not really sure of the differences.

    Hi, Parthabe.
    Yes, I've seen this list. I suposse which one is my problem (because in the response, they didn't give me the ID), but I can't see more than the description of the problem, without solution . What do I have to do with this list? I feel so clumsy 
    I use LabView 8.5.
    I think this is the list, or not?
    http://zone.ni.com/devzone/cda/tut/p/id/6448
    Thanks again, Parthabe.
    Mensaje editado por Porras

  • Which clause is overridden by the ORDER By clause

    1. group by
    2. having
    3. select
    4. where
    5. from

    It implies that distinct, group by guarantees a
    sorted order. I have seen Tom Kyte disprove this lots
    of time....and 10.2 (in particular the hash group by) is going to screw up a lot of people who have mistakenly relied on this.
    SQL> with t as (
      2         select mod(rownum,10) as r
      3         from   user_objects
      4         where  rownum <= 100
      5         )
      6  select r
      7  from   t
      8  group  by r;
             R
             6
             7
             5
             8
             1
             2
             3
             4
             9
             0
    10 rows selected.
    SQL> with t as (
      2         select mod(rownum,10) as r
      3         from   user_objects
      4         where  rownum <= 100
      5         )
      6  select r
      7  from   t
      8  group  by r
      9  order  by r;
             R
             0
             1
             2
             3
             4
             5
             6
             7
             8
             9
    10 rows selected.

  • Materialized view and Order by clause

    Hi all. I'd like to have some information regarding the order by clause used in a materialized view.
    I'm using Oracle 9.2 and Win2003 server. I have a common view (my_common_view) on which a materialized view is based (my_materialized_view). Materialized view is built for fast refresh and is created in this way:
    create materialized view my_materialized_view as
    select * from my_common_view
    order by 1,2,3;
    My question is: if I query this materialized view without adding an order by clause in the statement, I will obtain always an ordered result set? So, is it useful to include the order by clause in the materialized view script or the order by has to be include in the statement used for quering the materialized view (for example like this: select * from my_materialized view order by ...)?
    Thank you very much.
    Ste.

    SQL> create table t
      2  (x int)
      3  /
    Table created.
    SQL> create view vw
      2  as
      3  select *
      4    from t
      5   order by x
      6  /
    View created.
    SQL> select *
      2    from v$version
      3  /
    BANNER
    Oracle9i Enterprise Edition Release 9.2.0.7.0 - 64bit Production
    PL/SQL Release 9.2.0.7.0 - Production
    CORE    9.2.0.7.0       Production
    TNS for IBM/AIX RISC System/6000: Version 9.2.0.7.0 - Production
    NLSRTL Version 9.2.0.7.0 - Production
    SQL>

Maybe you are looking for

  • How to create universe folder in BO XI via SDK

    Hi all, I'm just starting to use the BOXI SDK. I've used the sample to create new folders, it worked perfectly. But now I would like to create new universe folders but I have no idea how to do it. Here is the sample to create a folder : int addFolder

  • Extra-ordinary depreciation is not shown on the Asset History Sheet

    Hi, When doing a disposal of assets via transaction ABAVN, the extra-ordinary depreciation is not shown on the asset history sheet in the "Deprec for the year" column. How can I show it on the asset history sheet? Thank you for your feedback. Kind re

  • How to re-download Apps when you have canceled and then restarted a membership

    Hi There, I recently (in the last two weeks) canceled a membrship, and then started a new membership. In that time my apps expired so I deleted them from my harddrive. Today, I wanted to reinstall apps, but when I did via the CC Downloader it had all

  • Filter recordset with session variable

    This has never happened to me before, but for some reason, my recordset that drives a dynamic table won't filter results based on a session variable. I know session variables are working because I have the session variable echo on the page (dragged-n

  • Number of pages in new spool request

    Hello. I use FM RSPO_RETURN_ABAP_SPOOLJOB to extract lines from a given spool. Then I open a new spool with FM RSPO_SR_OPEN. Each line of the table coming out of RSPO_RETURN_ABAP_SPOOLJOB is written to the new spool. Afterwards i close the new spool