Ordering of query results in Oracle

Source: Internet
Author: User

1, using ORDER BY

Chinese character coding rules, there is a reference to the following sentence: "First-class Chinese characters, is the most commonly used Chinese characters, alphabetical alphabetical order, a total of 3,755, two-level Chinese characters, belong to the second commonly used Chinese characters, according to the order of the Radicals of the two, a total of 3,008, Order using ASCII encoding to sort the Ming so that the number in front of the letter, the letter in front of the Chinese character, the general Chinese characters are a first-level Chinese characters, is based on pinyin, so mistakenly thought order is pinyin, actually not, you can specify the order.

Sort by Pinyin

ORDER by Nlssort (NAME, ' nls_sort=schinese_pinyin_m ')

According to the radical order

ORDER by Nlssort (NAME, ' nls_sort=schinese_radical_m ')

Sort by strokes

ORDER by Nlssort (NAME, ' nls_sort=schinese_stroke_m ')

The general default is to sort in ascending order, you can specify the sort

SELECT ename,hiredate from emp ORDER by hiredate DESC ;

DESC is descending, ASC is ascending

If you want to sort multiple columns

SELECT ename,deptno,hiredate from emp ORDER by deptno,hiredate;

Sort by Depptno first, if Deptno is equal, press HireDate

You can also sort the combined results, such as the product sort for a two-row

      1. SELECT empno, ename, Sal*months_between (sysdate,hiredate) as total from emp
      2. ORDER by Total ;

2 in the course of the project, encountered an uncommon word, in the composition of JSON data, the use of bubble sort, the JSON array inside a field to sort, the rare word in other characters commonly used form to sort, get the result specific code for

     PublicJsonarray Bubblesort (Jsonarray args)throwsJsonexception, Unsupportedencodingexception {//Bubble Sort Algorithm         for(intI=0;i<args.length () -1;i++){                for(intJ=i+1;j<args.length (); j + +) {Jsonobject strResult1=NewJsonobject (); STRRESULT1=Args.getjsonobject (i); String S1= Strresult1.getstring ("StreetName"); Jsonobject STRRESULT2=NewJsonobject (); STRRESULT2=Args.getjsonobject (j); String S2= Strresult2.getstring ("StreetName"); if(S1.equals ("FA tou"))) S1= "Hair Head"; if(S2.equals ("FA tou"))) S2= "Hair Head";                    String S3,s4; byte[] B1 =NULL; byte[] B2 =NULL; StringBuffer SB1=NewStringBuffer (); StringBuffer SB2=NewStringBuffer (); B1= S1.getbytes ("gb2312"); B2= S2.getbytes ("gb2312");  for(intk = 0; K < B1.length; k++) {sb1.append (integer.tohexstring (b1[k)& 0xFF)); }                      for(intk = 0; K < B2.length; k++) {sb2.append (integer.tohexstring (b2[k)& 0xFF)); } S3=sb1.tostring (); S4=sb2.tostring (); if(S3.compareto (S4) >0) {args.put (I, STRRESULT2);                                                                   Args.put (J, STRRESULT1); }               }         }         returnargs; }    

Ordering of query results in Oracle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.