Hutchison is a development Oralce string sorting encountered the pit

        A brief description of the case, is stored with a procedure of string type field as sorted number of patient visits, inexplicable results found after completion of call 11, 12 called No. 1 patients. User feedback is not necessarily accurate, added their own logs, and quickly copy the log to look at. It was found that the actual situation is like this, he spoke not right, side began to look at the code, a field sort of analysis used, after analysis found that because the field is so collation string is a character of a character comparison , write a separate statement to test, is really the case.

WITH T AS
(SELECT '11' STR
    FROM DUAL
  UNION ALL
  SELECT '2' STR FROM DUAL
  UNION ALL
  SELECT '3' STR FROM DUAL
  UNION ALL
  SELECT '21' STR FROM DUAL
  UNION ALL
  SELECT '30' STR FROM DUAL
  UNION ALL
  SELECT '1' STR FROM DUAL)
SELECT * FROM T ORDER BY STR;

Output:

1    1
2    11
3    2
4    21
5    3
6    30

 

Since the field stores Chinese characters, using the final state field and takes a string value is converted to a digital section, and then sorted. As for

Wherein the digital taking part, using regular expressions

to_number(regexp_substr(nvl(字段a,0),'[0-9]+'))

Record pit about their own problems, may be very simple, but easy to overlook. Diligent practice, willing to record, love to share.

Guess you like

Origin www.cnblogs.com/FreeLoopPowter/p/11325328.html