Sort Order for a VARCHAR2 Column

Hello Everyone,
This is probably quite simple, however I cannot see it. I am trying to sort on a varchar2 column that has numbers, text, dashes, tildes, carets and underscores which are mixed to compose a wire number. I have come up with an order by that changes the sort order from alpha to numeric satisfying one portion of the requirement.
select wirenbr,fromitem "from",frompin,diagnbr,sht,toitem,topin,effect
from acft_wires
order by decode(to_char(nvl(length(translate(wirenbr,'A1234567890','A')),0)),'0',lpad(wirenbr,18),wirenbr);
The select returns:
1
2
3
20
21
200
201
1000
A
ADT1
AEN1
AE1
AE9
AFA
B
1A
2U7230A-ZZ
2000A
213-22
22X100A20
220-11
The customer preferred sort looks like:
1
2
3
10
10A
11
200
201
201-01
202
1000
1000A
1001
I will build a shrine in my hall of honor to this forum if someone can point me in the right direction on how to solve this problem.
Thanks everyone for your help.

ok, start with this
order by
translate(substr(wirenbr,1,1),'1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ-','0000000000ZZZZZZZZZZZZZZZZZZZZZZZZZZZ')
, nvl(length(substr(wirenbr,1,instr(translate(wirenbr,'1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ-','1234567890XXXXXXXXXXXXXXXXXXXXXXXXXXX'),'X')-1)),length(wirenbr))
, to_number(translate(wirenbr,'1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ-','123456789000000000000000000000000000'))
First, all that start with number go to the beginning and all that start with a letter go to the end.
Next, sort by the length of the first numerical part, as per Al's first solution.
Next, sort by the numerical part.
I started getting what I think is the right sort by that point. However, I think that you'll also have to add
stuff to sort by the alpha part, mine was
, NVL(RTRIM(LTRIM(wirenbr,'0123456789'),'0123456789'),0)
The biggest problem I see is all of the different number-letter-number
number-letter-number-letter formats. How many levels of recursion you'll have to go through to get it perfectly sorted, could you have ZZ999ZZ99Z9Z9Z9Z99?
Any ideas for breaking this value up?

Similar Messages

  • Default column sort order for 11g table

    Could anyone give me some indication on how I would go about setting the default sort order for a table?
    I have a table with a few columns, and dataset returns in a particular order, but my table decides to sort if in any given order until I manually click on the column header and sort it.
    I would like to have it done by default on a particular field.
    Any info is appreciated.
    Thanks
    Jonny

    As Chris says, the easiest way and best re-use way is to use the order-by clause in your underlying model layer SQL query. For instance in ADF BC this would be in a View Object's query.
    However as you haven't dictated your model layer technology, there is another way in JDev 11g. In your web page that contains the ADF Faces RC table, select the binding tab at the bottom of the page, then double click on the iterator in the binding page, and in the Edit Iterator Binding dialog, select the Sort Criteria tab. This allows you to override the sort order on the iterator's columns.
    CM.

  • Persisting(MDS) Sort Order for af:column

    Hi All,
    I have a requirement where I would want to persist the sort order of a Rich column using MDS.
    Can I persist the ascending /descending order of a Rich Column into MDS ?
    Thanks and Regards
    Harish

    Todd,
    Not knowing what you're trying to sort, it is difficult to make specific suggestions. Basically, two approaches come to mind. 1) start the lines of the column you want to sort with some type of sort code or 2) place that sort code in another column and sort on two columns - possible hiding the one with the codes.
    The next problem is designing a code that fits your situation. In the example you gave something like 1L-,2L,3L,...,8H,9H may work because there are only 9 categories. If more than 9, two digit numbers may work but remember to use leading zeros to pad single digit numbers.
    The code could also be alpha characters with relevance such as "Auto", "Clot", "Food", "Hous", "Misc", etc. But again, if these alphabetic categories are not in the order you like you may have to precede them with some sequence device to get what you want. Maybe something like "aFood", "bClot", "cHous", etc. would work. Designing a code applicable to a given situation that one can easily remember is not always easy.
    Hope this gives to something to think about and if you care to give more details you'll surely get some specific suggestions.
    pw

  • Sort Order for Legend and X Axis

    Does anyone know of a way to keep a specific sort order for both the X Axis and the Legend. Both start with numbers and I can get one or the other to sort correcly on the chart but not both. Biggest problem is not all of the legend items are in the first X Axis item so the colors change on the bar graph depending on the legend items in the first X Axis item.

    If you tie bar colors with values, how you will differentiate the bars for different legends.
    Take an example, there are three columns Employee, Location and salery have following values
    Employee Location Salery
    A London 30000
    B Chicago 40000
    C London 50000
    D Chicago 60000
    if we keep Location as Legend and Employee in X Axis, and sort Legend first then Employee. Set Blue for Chicago and Red for London, First two blue bars for A and C will be displayed and then two red bars for B and D will be displayed. Order in X axis will be A,C,B and D. This is not in sequence but this is the way it will and it should work. If you sort by Employee instead if Location, you will get sequence in X axis, but the same colored bars wont be together.
    Thanks
    Swami

  • Default Sort Order for Library View

    It would be fantastic if there were a user defined preference for a default sort order in Library view. For example, some users may prefer to always view the images by File Name, or Rating, etc, without having to change the sort order for each individual folder they view via Lightroom.
    Thanks!

    Thanks for your suggestion Allan, but it doesn't work.
    I'm specifically referring to the defaults that Aperture 3 adopts when you use the "File, Import, Folders as Projects with the projects and albums setting.
    What I'm finding is regardless of the setting in the Library preferences, the default sort order for the project is Date and Manual for the album.
    Yet if I create a project manually the default sort order is as per the Library prefs. Strange.

  • Looking for a way to change sort order for albums

    I know how to set the sort order for each individual song (Sort tab on song info), but is there a way to set sort order for multiple tracks?

    Please help!

  • How to change sort order for Notes in iOS?

    When using Notes in OS 10.10, I can change the sort order. However, I cannot see how to change the sort order for Notes in iOS8 on my iPhone. I sync using iCloud, but the iPhone does not pick up the sort order (alpha) that I have chosen on my MBP.
    Is it possible to change the sort order on phones?
    Thanks.

    View > Sort By > Title

  • How do I change the Sort order for Music Video's on the iPad

    Hi All,
    Apologies if this has been dealt with elsewhere - I can find posts about sort order for TV Shows and Movies but not Music Video's.
    When I sync my music video's the appear in Track order in the video app and I cannot find how to change the sort order to 'by Artist' (or any other order come to that).
    Any ideas please>

    Hi!
    Im afraid I believe this cannot be done yet. Sorry!
    You can try submitting feedback to apple by clicking [here|http://www.apple.com/feedback/ipad.html] if you wish.
    Hope this helps!

  • Sort order for Simplified Chinese (pinyin)

    FrameMaker 10 (Windows)
    It seems that if I specify the sort order for Simplified Chinese (pinyin) on the reference page,
    index entries that start with "i" and "v" are not shown under their corresponding group titles.
    (I assume that this may be due to the fact that pinyin words never start with these letters.)
    If I have an entry that starts with an English word like "IP," it appears under the "J" group.
    I want the entry to appear under the "I" group. How can I do this?
    I have the IX reference page set up as follows:
    GroupTitlesIX paragraph
    Symbols[\];Numerics[0];A;B;C;D;E;F;G;H;I;J;K;L;M;N;O;P;Q;R;S;T;U;V;W;X;Y;Z;
    SortOrderIX paragraph
    <$symbols><$numerics><$alphabetics><$pinyin>
    I've also tried:
    SortOrderIX paragraph
    <$symbols><$numerics><$pinyin>
    Thanks in advance.
    Tak Osato

    I sort of found a workaround, but it may lead to other problems, so use it at your own risk.
    It also requires a bit of work.
    The idea is to use the sort order for Japanese by specifying the following in the IX reference page.
    Symbols[\ ];数字[0];A;B;C;D;E;F;G;H;I;J;K;L;M;N;O;P;Q;R;S;T;U;V;W;X;Y;Z;あ;い;う;え;お;か;き;く;け;こ;さ;し;す;せ;そ ;た;ち;つ;て;と;な;に;ぬ;ね;の;は;ひ;ふ;へ;ほ;ま;み;む;め;も;や;ゆ;よ;ら;り;る;れ;ろ;わ;ん;[ ]
    <$symbols><$numerics><$alphabetics><$kana>
    Then, you need to capitalize the first letter in the bracket used for sorting for every index entry.
    Example:
    Instead of
    画面[hua4mian4]
    specify
    画面[Hua4mian4]
    Now, I'm wondering if there is a way to do a search and replace on all index entries to capitalize the first letter...

  • Control of sort order for asian language navigation

    I am a help writer who is working with both development and a localization vendor to create localized javahelp. I am the most knowledgeable about javahelp, which is not saying much. It has come to me to figure out how to establish the correct sort order for Simplified Chinese and Japanese language Index and Glossary navigators, Could someone explain to me how this is done outside of tools like RoboHelp (which has caused us major headaches yet seems to be the only way the vendor knows how to do JavaHelp). In layman's terms, please.
    thanks,
    ellen

    Same issue here, and the bug syncs to my iPhone, so when I want to quickly text or e-mail someone, their phone numbers and e-mail addresses appear in the wrong order, Work or Home before iPhone or Mobile. How can we get this big fixed in the next Snow Leopard update?

  • Changing Search sort order for Simplified Chinese

    We're generating a Simplified Chinese WebHelp system using Robohelp 10 and we need to change the sort order in the Search results so that it follows the pinyin order instead of "Y, Z, M, T" (Referring to 仪,准,美,通). Is there a way to do this?

    I sort of found a workaround, but it may lead to other problems, so use it at your own risk.
    It also requires a bit of work.
    The idea is to use the sort order for Japanese by specifying the following in the IX reference page.
    Symbols[\ ];数字[0];A;B;C;D;E;F;G;H;I;J;K;L;M;N;O;P;Q;R;S;T;U;V;W;X;Y;Z;あ;い;う;え;お;か;き;く;け;こ;さ;し;す;せ;そ ;た;ち;つ;て;と;な;に;ぬ;ね;の;は;ひ;ふ;へ;ほ;ま;み;む;め;も;や;ゆ;よ;ら;り;る;れ;ろ;わ;ん;[ ]
    <$symbols><$numerics><$alphabetics><$kana>
    Then, you need to capitalize the first letter in the bracket used for sorting for every index entry.
    Example:
    Instead of
    画面[hua4mian4]
    specify
    画面[Hua4mian4]
    Now, I'm wondering if there is a way to do a search and replace on all index entries to capitalize the first letter...

  • TA26589 iphone 4s sort order for number in contacts

    iphone 4s How to sort order for numbers in contacts ?
    Like
    First - mobile
    Second - office
    Third - work
    Four - home
    It differs as you enter while as you enter / update.
    Can any one guide me.
    Thanks.

    All you do is hold down on any of the icons for a few seconds and they will start wiggling. You can then move them to your hearts content, either on the same page or to different pages. Just press the HOME button to return to normal mode.
    Glor

  • Default Column Sort Order For KM iViews

    By default, the KM iViews we're using sorts the documents within a folder based on the filename in descending order.  Is there a way that I can change the default sort order to be the Modified Column in reverse chronological order?
    Any help on this matter is appreciated.

    This can be done in the colection renderer of the iview's layout set. Simplye enter the property you want to sort on in 'Property for Sorting' field and 'Sorting Mode' as descending or ascending.
    The 'sorting Mode' option is only visible in the advanced mode. 

  • Controlling the sort order for a column?

    I have a column which uses strings that I want to sort on. But, I don't want to do simple string sorting. Can I effect the sort order somehow? Maybe enumerate the values and assign integers to them?
    For example, I want to use Low, Medium, and High. Or maybe: L-, L, L+, M-, M, M+, H-, H, H+
    Any pointers on how to do this?

    Todd,
    Not knowing what you're trying to sort, it is difficult to make specific suggestions. Basically, two approaches come to mind. 1) start the lines of the column you want to sort with some type of sort code or 2) place that sort code in another column and sort on two columns - possible hiding the one with the codes.
    The next problem is designing a code that fits your situation. In the example you gave something like 1L-,2L,3L,...,8H,9H may work because there are only 9 categories. If more than 9, two digit numbers may work but remember to use leading zeros to pad single digit numbers.
    The code could also be alpha characters with relevance such as "Auto", "Clot", "Food", "Hous", "Misc", etc. But again, if these alphabetic categories are not in the order you like you may have to precede them with some sequence device to get what you want. Maybe something like "aFood", "bClot", "cHous", etc. would work. Designing a code applicable to a given situation that one can easily remember is not always easy.
    Hope this gives to something to think about and if you care to give more details you'll surely get some specific suggestions.
    pw

  • Update a list item based sort order of created by column value

    HI
    using powershell script how to sort a list column before update a list  item.
    here i created a document library and uploaded some documents and update ProcessNo column based sort order of created column
    value.
    Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
    $webURL = "http://tspmcwfe:91" $listName = "Courts"
    Get the SPWeb object and save it to a variable
    $web = Get-SPWeb $webURL
    $list = $web.Lists[$listName] 
    $items = $list.items
    Go through all items
    foreach($item in $items)
    $item["ProcessNo"] = 1
    $item.Update()
    $web.Dispose()

    Hi,
    According to your description, my understanding is that you want to sort the list items order before updating items using PowerShell.
    I suggest you can use the Sort-Object command to sort the list items.
    Here are some detailed articles for your reference:
    Better SharePoint Lists and List Items in PowerShell
    Sort-Object
    Thanks
    Best Regards
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

Maybe you are looking for

  • Keyboard wireless key not working after upgrading to windows 8.1

    Hello, I am having hp pavilion dv6-6165tx notebook, where keyboard having a wireless button that turns ON and OFF all wireless devices, After upgrading to windows 8.1, HP Connection Manager is not getting installed, as well as Key is not working, key

  • How do you compile a lifecycle module

    I want to develop a Lifecycle module for Sun Java System Application Server 8, Platform Edition. I have read through http://docs.sun.com/source/817-6087/dglfcycl.html#wp16956 . The bit of info that is missing from this document is the name of the jar

  • Java.exe error while running j2ee server in jre1.4.0 env

    Hi, i have been running j2ee 1.3.1 server in jdk1.4.0 enviromrnt. When i try to process large data (like retrieving around 100 records from the database, each having 150 attributes) in the form of XML , I get a runtime error generated by the jvm , wh

  • Help with mutiple files produced by sharing video to Itunes

    Hi All, As I continue to learn I am looking for some help. After importing DV video and then creating a movie in Imovie08 I shared the movie with Itunes. Looking through all the video files there are now two copies of everything on the drive.. Copy #

  • Partitioning Question

    How does a range-hash partition work with a local index? I have rebuilt my sales table which was range partitioned by ORDER_DATE (with local index on ORDER_DATE). The new sales table is now range partitioned by ORDER_DATE with 4 hash sup partitions o