Weird Sort Question


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Weird Sort Question

  1. #1
    Rob Guest

    Weird Sort Question


    I want to be able to create a select statement that will return a column of
    six digit numbers in reverse order but grouped by two. For example,

    111345
    234567
    245677


    would become

    451311
    674523
    775612

    I need to be able to do this in both ascending and decending order. I'm running
    against an Oracle 8i database.

    Thanks !

    Rob





  2. #2
    Rohit Wason Guest

    Re: Weird Sort Question


    Rob,

    I have applied some basic mathematical operations (like divide, modulo and
    integral-divide):

    (123456 mod 100) & (123456 \ 100) mod 100 & 123456 \ 10000

    will give me (in VB):

    563412 (is that what u wanted?)

    Convert this algorithm to whatever language you choose - Oracle/SQL Server.

    HTH,
    Cheers
    Rohit




    "Rob" <robertofor@yahoo.com> wrote:
    >
    >I want to be able to create a select statement that will return a column

    of
    >six digit numbers in reverse order but grouped by two. For example,
    >
    >111345
    >234567
    >245677
    >
    >
    >would become
    >
    >451311
    >674523
    >775612
    >
    >I need to be able to do this in both ascending and decending order. I'm

    running
    >against an Oracle 8i database.
    >
    >Thanks !
    >
    >Rob
    >
    >
    >
    >



  3. #3
    psit Guest

    Re: Weird Sort Question


    Hi, all
    That's a good idea Rohit, and I have another way by use SUBSTR function
    as I show below :

    1 select mod(123456,100) ||

    2 mod(trunc(123456/100,0),100) ||

    3 trunc(123456/10000,0) asMath,

    4 substr(ltrim(to_char(123456,'999999')),5,2) ||

    5 substr(ltrim(to_char(123456,'999999')),3,2) ||

    6 substr(ltrim(to_char(123456,'999999')),1,2) asString

    7* from dual

    The first part is doing by Rohit's way, and the second is use SUBSTR function.

    Psit

    "Rohit Wason" <rohitw@ggn.hcltech.com> wrote:
    >
    >Rob,
    >
    >I have applied some basic mathematical operations (like divide, modulo and
    >integral-divide):
    >
    >(123456 mod 100) & (123456 \ 100) mod 100 & 123456 \ 10000
    >
    >will give me (in VB):
    >
    >563412 (is that what u wanted?)
    >
    >Convert this algorithm to whatever language you choose - Oracle/SQL Server.
    >
    >HTH,
    >Cheers
    >Rohit
    >
    >
    >
    >
    >"Rob" <robertofor@yahoo.com> wrote:
    >>
    >>I want to be able to create a select statement that will return a column

    >of
    >>six digit numbers in reverse order but grouped by two. For example,
    >>
    >>111345
    >>234567
    >>245677
    >>
    >>
    >>would become
    >>
    >>451311
    >>674523
    >>775612
    >>
    >>I need to be able to do this in both ascending and decending order. I'm

    >running
    >>against an Oracle 8i database.
    >>
    >>Thanks !
    >>
    >>Rob
    >>
    >>
    >>
    >>

    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center