当前位置:网站首页>Remember that a development is encountered in the pit of origin string sorting
Remember that a development is encountered in the pit of origin string sorting
2022-07-07 22:17:00 【freelooppowter】
Briefly describe the situation , In the stored procedure, a field of string type is used as the sorting number of patient visits , The result is inexplicably found that the call is over 1 Called after the th 11、12 Wait for patients . User feedback may not be accurate , I added my own log , Copy the log quickly to observe . It turns out that the actual situation is like this , It's wrong to say , Start looking at the code , Fields used for analysis and sorting , After analysis, it is found that since this field is a string, the collation is a character by character comparison , Write a separate statement to test , Right enough .
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;
The output is as follows :
1 1
2 11
3 2
4 21
5 3
6 30
Because this field will store Chinese characters , In the end use state The numeric part of the field and the fetch string is converted to a numeric value , And then sort it . as for
Take the numerical part , Using regular expressions
to_number(regexp_substr(nvl( Field a,0),'[0-9]+'))
Record the pit you encountered , It could be very simple , But easy to ignore . Be diligent in practice 、 Willing to record , Love to share .
边栏推荐
- What if the win11u disk does not display? Solution to failure of win11 plug-in USB flash disk
- Leetcode SQL first day
- [advanced MySQL] index details (I): index data page structure
- Jerry's fast pairing does not support canceling pairing [article]
- How polardb-x does distributed database hotspot analysis
- 大数据开源项目,一站式全自动化全生命周期运维管家ChengYing(承影)走向何方?
- Codemail auto collation code of visual studio plug-in
- How to realize the movement control of characters in horizontal game
- OpenGL homework - Hello, triangle
- [开源] .Net ORM 访问 Firebird 数据库
猜你喜欢

How to make agile digital transformation strategy for manufacturing enterprises

Redis - basic use (key, string, list, set, Zset, hash, geo, bitmap, hyperloglog, transaction)

双塔模型的最强出装,谷歌又开始玩起“老古董”了?

客户案例|华律网,通过观测云大幅缩短故障定位时间

null == undefined

Matplotlib drawing interface settings

Crawler (17) - Interview (2) | crawler interview question bank

Overseas agent recommendation

Navicat connect 2002 - can't connect to local MySQL server through socket '/var/lib/mysql/mysql Sock 'solve
![[azure microservice service fabric] start the performance monitor in the SF node and set the method of capturing the process](/img/80/11c2b539c217ecd6ba55668d3e71e9.png)
[azure microservice service fabric] start the performance monitor in the SF node and set the method of capturing the process
随机推荐
[azure microservice service fabric] start the performance monitor in the SF node and set the method of capturing the process
Preparing for the interview and sharing experience
L2:ZK-Rollup的现状,前景和痛点
operator
为什么Win11不能显示秒数?Win11时间不显示秒怎么解决?
How to realize the movement control of characters in horizontal game
Tsconfig of typescript TS basics JSON configuration options
How to integrate Google APIs with Google's application system (1) -introduction to Google APIs
Pre sale 179000, hengchi 5 can fire? Product power online depends on how it is sold
Reinforcement learning - learning notes 9 | multi step TD target
【JDBC Part 1】概述、获取连接、CRUD
Ternary expressions, generative expressions, anonymous functions
Tcp/ip protocol stack
OpenGL configure assimp
Backup tidb cluster to persistent volume
使用 CustomPaint 绘制基本图形
Win11时间怎么显示星期几?Win11怎么显示今天周几?
Codemail auto collation code of visual studio plug-in
How does win11 unblock the keyboard? Method of unlocking keyboard in win11
Take the intersection of two sets