sql - SQL ORACLE 按数字和字符串排序
问题描述
我尝试使用:
select * from list order by id;
select * from list order by LPAD(id, 4);
但它不起作用。
我在 oracle 表中有这个列表:
id (varchar2)
-----------
123
124
125
126
toto
bobo
koko
201
169
所以我需要这样的结果:
123
124
125
126
169
201
bobo
koko
toto
解决方案
我会建议:
order by (case when regexp_like(id, '^[0-9]+$')
then to_number(id)
end) asc nulls last,
id
这将以数字方式处理数字 id,即使它们的长度不同。
推荐阅读
- google-apps-script - 如何在移动设备上运行应用程序脚本,一个脚本工作另一个不工作
- angular - Angular - 如何使 canActivate 等待承诺响应?
- python - 在 Python 中从 SharePoint 加载文件
- android - 在 Android 7 上实现 androidx 生物识别库后字体缩放不起作用
- php - 防止 Select sql 从 DB PHP 中选择相同的数据
- javascript - 为什么我的 Javascript 回调未定义?
- database - 我有一个作为数据库连接的 CSV 文件,我想在任何地方使用自动化查询来更新列值而不是所有列
- forms - React 钩子表单未在控制台中显示对象 onsubmit
- python - 如何在类型验证之前访问序列化程序的字段数据?
- list - Groovy Map 中同一键的多个值