将 varchar2 转换为数字不会产生正确的结果顺序
你好,我正在开发一个oracle DB,它的表id为varchar2,实际上只保存数字,例如2000、30201。现在我需要将这些值作为数字进行比较,所以我使用TO_NUMBER()函数,但结果仍然不成功。示例代码如下。非常感谢任何帮助。
SELECT ID FROM facty WHERE to_number(ID)>2 ORDER BY ID
当前结果: 11, 4, 5, 6, 8, 9
我需要它来生成 4, 5, 6, 8, 9,11
Hello I am working on an oracle DB which has table id as varchar2 which actually holds numbers only e.g. 2000, 30201. Now I need to compare these values as numbers so I use the TO_NUMBER() function but the results still come out unsuccessfull. Example code is below. Any help is deeply appreciated.
SELECT ID FROM facty WHERE to_number(ID)>2 ORDER BY ID
current result:
11, 4, 5, 6, 8, 9
I need it to produce 4, 5, 6, 8, 9,11
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要使用 Oracle,但我猜您还需要在
ORDER BY
上包含to_number(id)
。您当前的查询ORDER BY
使用 varchar 字段,而不是数字转换。Don't use Oracle, but I'm guessing you need to include the
to_number(id)
on theORDER BY
as well. Your current queryORDER BY
uses the varchar field, not the numeric conversion.