Interesting Sort using ORDER BY

I would like to sort by footnote names in our table which should be sorted as below:
2a,2b,2c,3a,3b,3c,8,10,15,18
When I use ORDER BY FOOTNOTE_NAME, Oracle sorts the result like this:
10,15,18,2a,2b,2c,3a,3b,3c,8
which is not what I want.
Any ideas. Will I need to strip characters, convert the remaining part to Int and then sort. Does Oracle let you specify your own sort rules?
Thanks in advance.

Assuming that the footnote names only have letters and numbers, then something like:
SQL> SELECT * FROM t;
COL
2a
2b
3b
3c
8
15
18
3a
2c
10
SQL> SELECT * FROM t
  2  ORDER BY TO_CHAR(TRANSLATE(UPPER(col),'1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ',
  3                                      '1234567890'),'0000')||
  4           TRANSLATE(UPPER(col),'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',
  5                              'ABCDEFGHIJKLMNOPQRSTUVWXYZ');
COL
2a
2b
2c
3a
3b
3c
8
10
15
18TTFN
John

Similar Messages

  • Sorting of Date field in the SQL Query useing ORDER BY

    Hi
    I am facing a problem when I am getting the results of a query from the ORacle 8i database using jdbc connection.
    The query is having a date field and I have to sort the query results using ORDER By for the Date field. The query is giving exact results in the SQL PLus interface.
    When I am getting this results in the GUI where servlets are being used an Exception is coming as not supported RefreshRow method.
    If anyone has faced this problem and have got the solutions please let me know.
    thanks
    sulfy

    That doesn't sound at all like an SQL problem.
    More like you trying to do updates on the resultset which is not allowed ...
    send a some code (not to much pls :) and we'll be
    able to help more
    cu
    Spieler

  • Using order by in the select query

    Hi All,
    I have query in which I need the latest record. To get the latest record, I can
    1) Select all entries into an internal table and sort them descending and get the first one
    2) Select all entries into an internal table and order by in the select statement itself.
    Then read the first one.
    Which approach should be better as for as the performance is concern.
    The query is on MKPF table and I have the material document number. I need the latest entry.
    Regards,
    Shahu

    Hi,
    The first one would be better.At the most we should not use order by in select statement bcoz it directly sorts the data according to that in database itself reverting performance issues.
    Otherwise you can use select max* if records are less.
    Reward points if helpful.
    Thanks,
    Ponraj.s.

  • Using ORDER BY in UNION clause in cursor

    Hi Everybody,
    I have one situation and i need your help guys. I have to use ORDER BY in UNION of two queries and return value in cursor.
    OPEN cursor FOR
    SELECT ID, DESC,SID, ITID, SID_DESC
    FROM (SELECT A.ID,
    A.DESC,
    B.SID,
    NULL AS ITID,
    B.SID_DESC
    FROM TABLEA A, TABLEB B
    WHERE A.ID = B.ID
    order by A.SORTORDER asc,B.SORTORDER)
    UNION
    SELECT ID, DESC, ,SID,ITID, ITID_DESCRIPTION,
    FROM (SELECT A.ID,
    A.DESC,
    NULL AS SID,
    C.ITID,
    C.ITID_DESC,
    FROM TABLEA A,
    TABLEC C
    WHERE A.ID = C.ID
    order by A.SORTORDER asc,C.SORTORDER)
    I SORT ORDER is column in all three tables. TABLEA has unique number for each record as sort order. TABLEB has sortorder as 1 for each id. If id is two times then its 1 and 2 for each id. TABLEC has sort order as TABLEB, 1 for each id and if id is two times then it is 1 and 2 and id id is three times, it is 1, 2, 3.
    I am not getting correct sorting as i cant use order by like this in UNION. Please let me know how i can handle this.
    Thank you in advance to everybody.
    I will really appreciate your comments and responses.

    Hi,
    You can use ORDER BY in a sub-query, but there's usually no point in doing so, because the super-query won't necessarily preserve that order. You need to make the columns that you want to ORDER BY available to the main query, so that they can be used there.
    Try this:
    SELECT      ID, DESC,SID, ITID, SID_DESC
    FROM      (
             SELECT    A1.ID,
                        A1.DESC,
                    B.SID,
                    NULL          AS ITID,
                    B.SID_DESC,
                    A1.SORTORDER     AS sortorder_1
                    B.SORTORDER     AS sortorder_2
             FROM      TABLEA     A1,
                        TABLEB     B
             WHERE     A1.ID = B.ID
        UNION
             SELECT    A2.ID,
                        A2.DESC,
                    NULL          AS SID,
                           C.ITID,
                    C.ITID_DESC,
                    A2.SORTORDER     AS sortorder_1
                    B.SORTORDER     AS sortorder_2
             FROM      TABLEA          A2,
                        TABLEC         C
             WHERE     A2.ID = C.ID
    order by  SORTORDER_1     ASC     -- ASC is the default, but it doesn't hurt to say it
           SORTORDER_2This assumes that tableb.sortorder and tablec.sortorder have the same, or at least similar, data types. If not, explicitly convert sortorder_1 in one branch of the UNION to the type of sortorder_2 in the other branch.
    Using the same alias to mean different things in the same query is just asking for trouble. I changed the table alias a (which was used in different places to mean two different things) to A1 and A2, each of which means only one thing.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.

  • How to use "Order by" clause dynamically on LOV values in 10g r2 forms

    Hi ,
    I have following requirement,please guide me.
    1 Create a List Of Values with 2 fields, Code and Description
    2. Do not use order by clause in record Group Query
    3. Attach this LOV to a field in Form
    4. When user invokes the LOV user will see two fields in LOV with header as Code and Description
    5. Now when user clicks on Column Header “Code” then LOV should be sorted on Code
    6. And if User clicks on Column Header “Description” then LOV should be sorted on Description
    Thanks in Advance.

    Kindly post this problem in this forum ->
    [Forms Forum|http://forums.oracle.com/forums/forum.jspa?forumID=82]
    And, close this thread by marked it as answered. ;)
    Regards.
    Satyaki De.

  • With out using order by clause

    display the details of the employees with sal in descending order, without using order by clause

    Don't forget that it's just for fun :)Well it's not entirely for fun :-)
    There are real life users who might have real production problems and the rely and input/feedback from this forum.
    I do not :)You spread untested answers/knowledge that might be wrong.
    I can't imagine where you can see cartesian. It's
    equijoin by primary key.I suggest you test it.
    JFUI hierarchy is built after joining. And this
    hierarchy is bamboo-tree. So result must be sorted
    acording hierarchy.I know what hierarchical ordering is :-)
    And here's a little test i did on your behalf, on the EMP table :-)
    select e1.*
    from e e1,
    ( select e2.id, count(*) as rn from e e2, e e3
    where e3.sal >= e2.sal
    and e3.id >= e2.id
    group by e2.id
    ) e4
    where e1.id = e4.id
    start with e4.rn = 1
    connect by e4.rn = prior e4.rn + 1
    SQL*Plus: Release 10.1.0.4.2 - Production on Wed Jul 25 16:02:19 2007
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Enter user-name: scott/tiger
    Connected to:
    Oracle Database 10g Release 10.2.0.1.0 - Production
    SCOTT@ORCL> set lines 1000
    SCOTT@ORCL>
    SCOTT@ORCL>
    SCOTT@ORCL> select emp1.*
      2    from emp emp1,
      3    ( select emp2.empno, count(*) as rn from emp emp2, emp emp3
      4        where emp3.sal >= emp2.sal
      5          and emp3.empno >= emp2.empno
      6        group by emp2.empno
      7    ) emp4
      8    where emp1.empno = emp4.empno
      9    start with emp4.rn = 1
    10    connect by emp4.rn = prior emp4.rn + 1;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7839 KING       PRESIDENT            17-DEC-80       5000                    10
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7788 SCOTT      ANALYST         7566 09-DEC-82       3000                    20
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
          7876 ADAMS      CLERK           7788 12-JAN-83       1100                    20
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
          7902 FORD       ANALYST         7566                 3000                    20
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7788 SCOTT      ANALYST         7566 09-DEC-82       3000                    20
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
          7876 ADAMS      CLERK           7788 12-JAN-83       1100                    20
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
          7934 MILLER     CLERK           7782                 1301                    10
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7788 SCOTT      ANALYST         7566 09-DEC-82       3000                    20
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
          7876 ADAMS      CLERK           7788 12-JAN-83       1100                    20
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
    42 rows selected.
    SCOTT@ORCL>Regards,
    Tony

  • How do I sort the order of bookmark folders themselves?

    I see plenty of instructions on how to sort marks ''within'' a folder, but I'm unable to find how to sort the order of the bookmark folders themselves. Ideally, I'd like to alphabetize them, but on occasion I might prefer sorting by the date the folder was created.
    Thanks for your suggestions
    Jonathan1000

    Don't use the Views menu to sort as that is only for viewing bookmarks in the bookmarks manager (hence the name of the menu item).<br />
    To sort items you need to use Sort By Name in the right-click context menu in the right pane.
    *http://kb.mozillazine.org/Sorting_and_rearranging_bookmarks_-_Firefox

  • Group sort using 2 fields

    Is there any way that I can have two fields as a group sort in order that the first group sort field will repeat when the second field changes?
    Thanks.
    Leah

    One possibility would be to create a calculated item (ItemA||ItemB), and use that as a hidden group sort. Not sure about your platform, but in Desktop, you need to specify the item as a 'group' sort, then change it to 'hidden'. You would still display your original items, but don't sort on them.

  • SQL Insert from "Select Query" Not Work when use Order By

    Hai every body...
    I have a problem with T-SQL. I use SQL Server 2012 Express with SP2 on Windows 7 32-bit SP1.
    This is the problem
    -- first, create table
    create table dtoth.tableA (
    id_data TINYINT PRIMARY KEY,
    kd_data VARCHAR(20),
    nm_data VARCHAR(200)
    -- then, insert values
    INSERT INTO dtoth.tableA VALUES (0,'100.001','KAS');
    INSERT INTO dtoth.tableA VALUES (1,'110.001','BANK');
    INSERT INTO dtoth.tableA VALUES (2,'120.001','PIUTANG DAGANG');
    INSERT INTO dtoth.tableA VALUES (3,'121.001','PIUTANG GIRO');
    INSERT INTO dtoth.tableA VALUES (4,'130.001','PERSEDIAAN BARANG DAGANGAN');
    -- then, i create a temporary table
    create table dtoth.temp_tableA (
    kd_data VARCHAR(20),
    nm_data VARCHAR(200)
    -- then, i create a store procedure to call data from temporary table
    CREATE procedure dtoth.report
    AS
    BEGIN
    DELETE FROM dtoth.temp_tableA;
    INSERT INTO dtoth.temp_tableA SELECT kd_data, nm_data FROM dtoth.tableA ORDER BY kd_data desc;
    SELECT * FROM dtoth.temp_tableA;
    END
    GO
    When i execute the the store procedure with
    EXEC dtoth.report;
    the result is not accurate like this (kd_data not sorted desc):
    I want the column "kd_data" sort descending because i use ORDER BY kd_data DESC in insert statement on the store procedure.
    By the way, if i execute code like :
    SELECT kd_data, nm_data FROM dtoth.tableA ORDER BY kd_data desc;
    the result is correct like this
    So, what solution for my code in the store procedure ?
    Thanks.

    to get the data sorted, you should order by in your select in the stored procedure
    sorting while inserting does not guarenatee order..
    remove the order by in insert statement and put that in the select statement
    so, your procedure should be 
    -- then, i create a store procedure to call data from temporary table
    CREATE procedure dtoth.report
    AS
    BEGIN
    DELETE FROM dtoth.temp_tableA;
    INSERT INTO dtoth.temp_tableA SELECT kd_data, nm_data FROM dtoth.tableA;
    SELECT * FROM dtoth.temp_tableA ORDER BY kd_data desc;
    END
    GO
    Hope it Helps!!

  • How can i use Order by inside a sub query in Oracle

    Hi!,
    Please help me, it's an urgent... how can i use Order by clause
    SELECT SalesProductKeyID,ActualUnitPrice,BillDateKeyID,ProductKeyID
    ,Qty,Profit,DD.dDate
    , (SELECT nvl(S.Qty,0) FROM Stock S , DateDimension DD1
    WHERE S.DateKeyID = DD1.DateKeyID AND
    S.ProductKeyID = SF.ProductKeyID AND
    DD1.dDate <= DD.dDate and rownum=1
    ORDER BY DD1.dDate DESC*) as StockQty
    , (SELECT nvl(SUM(Qty),0) from salesfact SF2,DATEDIMENSION DD2
    WHERE SF2.BillDateKeyID=DD2.DatekeyID AND SF2.ProductKeyID=SF.ProductKeyid
    AND DD2.dDate > DD.dDate
    AND DD2.dDATE=DD.dDate
    ) as TotalQtySold
    FROM SalesFact SF INNER JOIN DATEDIMENSION DD
    ON SF.billdatekeyid =DD.Datekeyid
    WHERE
    IsProfitCalculated = 1 AND
    IsSalesFactSuppPopulated =0 AND
    Qty > 0;
    kindly help
    Thank you.

    Actually I'm converting Procedures from SQL Server to Oracle.
    Actual Stored Procedure in SQL Server is as follows.
    SELECT --top 10000 
    SalesProductKeyID,ActualUnitPrice,BillDateKeyID,ProductKeyID
    ,Qty,Profit,DD.Date
    , (SELECT TOP 1 ISNULL(S.Qty,0) FROM dbo.Stock S , dbo.DateDimension DD1
    WHERE S.DateKeyID = DD1.DateKeyID AND
    S.ProductKeyID = SF.ProductKeyID AND
    DD1.Date <= DD.Date
    ORDER BY DD1.Date DESC) as StockQty
    , (SELECT ISNULL(SUM(Qty),0) from salesfact SF2,DATEDIMENSION DD2
    WHERE SF2.BillDateKeyID=DD2.DatekeyID AND SF2.ProductKeyID=SF.ProductKeyid
    AND DD2.Date > DD.Date
    AND DD2.DATE=DD.Date
    ) as TotalQtySold
    --INTO TEMP_Salesfact          
    FROM dbo.SalesFact SF INNER JOIN DATEDIMENSION DD
    ON SF.billdatekeyid =DD.Datekeyid
    WHERE
    IsProfitCalculated = 1 AND
    IsSalesFactSuppPopulated =0 AND
    Qty > 0

  • How to use order by within Group by clause

    Hi All,
    I need a help as to how should i use the Order by clause so that the data should be in order with respect to one column, and at the same time whole data is grouped by some other column...like
    Select RaceNo,Venue,FP,BP from Race group by RaceNo
    Here I want to order by FP in ascending order for each group. When i am using it , whole order is changing.
    Can anybody suggest me how to use order by clause that would apply to each group of data.
    Thanks .

    order by clause should be used at the last in any query.......but in group by clause u can't use use that becoz u group according to column then no ordering is needed there......if u want to filter something then u can use having clause and later if u need to arrange then u can use order by clause.........
    i hope this eg.l gives u some clarification....
    e.g
    select deptno,count(empno)
    from dept
    group by deptno
    having count(empno) > 10
    order by deptno

  • Can I share my iCloud storage with my wife? I'm interested in using the storage for both phones, hers and mine.

    Can I share my iCloud storage with my wife? I'm interested in using the storage for both phones, hers and mine.

    You will not want to do that and you should just have two 5GB free accounts.
    Too much risk of merging or losing data.

  • How to use order by in stored procedure base block?

    How to use order by in stored procedure base block? I need to change order by dynamically

    Use SET_BLOCK_PROPERTY('BLOCK_NAME',ORDER_BY,'COLUMN_NAME1, COLUMN_NAME2');

  • Issue in Batch import of Configuration orders using order Import

    Hi All,
       I am trying to import Configuration orders into Oracle R12 using Order import. As per Oracle white paper on this, I ahve populated all the required fields like top_model_line_ref,link_to_line_ref, item_type_code etc. But order import is giving error "Item ABC not found in BOM of Model XYZ".
    Is there any setup or profile I am missing?
    Please help me on this also is there any other approach to import Batch configuration orders?
    Thanks!!

    you have to customize tha availability check on MM movements in OMCP

  • Replace default table sort with order by on the view object

    The Jdeveloper help for af:table says:
    If the underlying model is not a CollectionModel , the Table automatically examines the actual data to determine which properties are sortable. Any column that has data that implements java.lang.Comparable is sortable. This automatic support cannot be nearly as efficient as coding sorting directly into a CollectionModel (for instance, by translating the sort into an "ORDER BY" SQL clause), but is sufficient for small data sets.
    I have a database table with varchar2 columns that can contain string, date or number values. So in the af:table I want to sort the columns either in string, date or number order.
    I tried creating a sort listener and in that listener set the view object order by clause and execute the query, but it does not affect the row order - it is always sorted as a string. I assume that the collection is doing its sort after I do the query, and overwriting the query order. I have tried disabling the sort in the listener by setting the sortcriteria to null but it has no effect.
    Can anyone suggest how to stop the default sort re-ordering the rows, or else how to code sorting directly into the CollectionModel as suggested in the help.
    Hugh Nelson

    By running in debug I discovered that when you click on a column heading to sort by the column values it actually sets the order by clause on the view object and executes a query. The help says that the default sorting is not as efficient as setting the order by clause - perhaps the help is out of date because default sorting does set the order by clause.
    This means that you cannot do a column sort on a transient attribute. The attribute being sorted on must exist in the table/query.
    The easiest solution is to override the setOrderByClause method on the view object. The string parameter is the column to order by eg "COLUMNA". If this column holds date values I can change it to something like "TO_CHAR(TO_DATE(COLUMNA,'DD-MON-YYYY'),'YYYYMMDD')". For numbers I do "LPAD(COLUMNA,10,'0')".
    This works OK.
    Hugh Nelson

Maybe you are looking for

  • Page numbers in pages

    Dear collegues. I have a 20 page document. I want to start numbering the pages but only on the third page and starting with the page number 24. Is there a way in pages to do that? Thanks for your help.

  • Formatting LaCie External Hard Drive for MAC and PC

    Hi, I just recently purchased a LaCie 500 GB Hard Drive from the Apple Store in order to back up and store most of my PC (Window) files. Most of my files that I need to back up are on CD, DVD, and USB mini drives. I was thinking of transferring the f

  • How to Use Associated App to open a file in Linux command line?

    Hi all, I know in windows i call always run: Runtime.exec("start aPicture.jpg");in order to use the default picture viewer to view the pictures Runtime.exec("start aEmail.eml");in order to use the default email viewer to view the .eml file is there a

  • Service of newly created database won't start if XE service already started

    Hi all, I install OracleXE 10g on WinXP SP1 and the default database (XE) is running well. Then I created a new database through TOAD but its window service won't start if XE service already started. If I shutdown the XE service than I can start the

  • Licesnisng Query

    Customer query Licensing query on Windows 2008 R2 Std edn. (3 Servers) There would be 2 terminal servers are in same domain then can we apply/activate the RDP license for 10 user CALs on Domain Server and redirect these RDP licenses through the domai