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
- SELECT empno, ename, Sal*months_between (sysdate,hiredate) as total from emp
- 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