Oracle 10g 中的 REPLACE 没有按我的预期工作,有人能解释一下吗?
我使用的是 Oracle 10g Express。
我有一个名为 arts_i_hate 的表,我已简化以更清楚地说明问题
ID | Name | Opinion
-----------------------------
11 | jamesblunt | i hate him
我运行语句
SELECT * FROM artists_i_hate WHERE to_char(ID)=REPLACE(to_char(1.1), '.');
为什么我得到“未找到数据”我在文档中的任何位置都找不到解释。
顺便说一句,我知道以下内容有效:
SELECT * FROM artists_i_hate WHERE to_char(ID)=REGEXP_REPLACE(to_char(1.1), '[^0-9]');
所以我认为另一个语句不起作用,因为它不喜欢替换某些符号。
编辑:
正在阅读前 2 个响应后对原始环境进行测试
I am using oracle 10g express.
I have a table named artists_i_hate, I have simplified to illustrate the problem clearer
ID | Name | Opinion
-----------------------------
11 | jamesblunt | i hate him
I run the statement
SELECT * FROM artists_i_hate WHERE to_char(ID)=REPLACE(to_char(1.1), '.');
Why do I get 'no data found' I can't find an explanation anywhere in the documentation.
btw I am aware that the following works:
SELECT * FROM artists_i_hate WHERE to_char(ID)=REGEXP_REPLACE(to_char(1.1), '[^0-9]');
So I am thinking the other statement doesn't work because it doesn't like replacing certain symbols.
edit:
Pending testing on original environment having read first 2 responses
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它可能取决于 NLS 设置,因为在某些语言中 .不是小数点分隔符,因此 to_char(1.1) 不会给出“1.1”,
在这种情况下,REPLACE 不会更改任何内容,因此 ID 不匹配。
附言。
如果这是问题所在,一种解决方法是
It may depend on NLS settings as, in some languages the . is not the decimal separator so to_char(1.1) would NOT give '1.1'
In which case the REPLACE wouldn't change anything and therefore the ID wouldn't match.
PS.
If this is the issue, one fix would be
下面这表明这两个表达式之间完全没有区别。它们是完全等效的,因此如果 REGEXP_REPLACE 有效,那么 REPLACE 也会有效。
输出:
This below shows that there is absolutely no difference between the two expressions. They are completely equivalent so if the REGEXP_REPLACE works, so will the REPLACE.
Output: