Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've had the same problem, though mine was with apartment numbers like A1, A2, A3, A10, A11, etc, that they wanted to sort "right". If splitting up the version number into separate columns doesn't work, try this PL/SQL. It takes a string like A1 or A10and expands it into A0000001, A0000010, etc, so it sorts nicely. Just call this in ORDER BY clause, like</p> <p>select apt_num from apartment order by PAD(apt_num)</p> <pre><code>function pad(inString IN VARCHAR2) return VARCHAR2 --This function pads the numbers in a alphanumeric string. --It is particularly useful in sorting, things like "A1, A2, A10" --which would sort like "A1, A10, A2" in a standard "ORDER BY name" clause --but by calling "ORDER BY pkg_sort.pad(name)" it will sort as "A1, A2, A10" because this --function will convert it to "A00000000000000000001, A00000000000000000002, A00000000000000000010" --(but since this is in the order by clause, it will --not be displayed. --currently, the charTemplate variable pads the number to 20 digits, so anything up to 99999999999999999999 --will work correctly. --to increase the size, just change the charTemplate variable. If the number is larger than 20 digits, it will just --appear without padding. is outString VARCHAR2(255); numBeginIndex NUMBER; numLength NUMBER; stringLength NUMBER; i NUMBER; thisChar VARCHAR2(6); charTemplate VARCHAR2(20) := '00000000000000000000'; charTemplateLength NUMBER := 20; BEGIN outString := null; numBeginIndex := -1; numLength := 0; stringLength := length(inString); --loop through each character, get that character FOR i IN 1..(stringLength) LOOP thisChar := substr(inString, i, 1); --if this character is a number IF (FcnIsNumber(thisChar)) THEN --if we haven't started a number yet IF (numBeginIndex = -1) THEN numBeginIndex := i; numLength := 1; --else if we're in a number, increase the length ELSE numLength := numLength + 1; END IF; --if this is the last character, we have to append the number IF (i = stringLength) THEN outString:= FcnConcatNumber(inString, outString, numBeginIndex, numLength, charTemplate, charTemplateLength); END IF; --else this is a character ELSE --if we were previously in a number, concat that and reset the numBeginIndex IF (numBeginIndex != -1) THEN outString:= FcnConcatNumber(inString, outString, numBeginIndex, numLength, charTemplate, charTemplateLength); numBeginIndex := -1; numLength := 0; END IF; --concat the character outString := outString || thisChar; END IF; END LOOP; RETURN outString; --any exception, just return the original string EXCEPTION WHEN OTHERS THEN RETURN inString; END; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload