英文:
Oracle SQL: Massive update of multiple rows (also repeated rows)
问题
I have a tableX with two columns, some with repeated values like:
column1 | column2 |
---|---|
'1000 -- Some Text' | '2000 -- Some Text' |
'1000 -- Some Text' | '2000 -- Some Text' |
'1001 -- Some Text' | '2001 -- Some Text' |
'1002 -- Some Text' | '2002 -- Some Text' |
What i want to do is to update both columns and remain with only the digits part:
column1 | column2 |
---|---|
1000 | 2000 |
1000 | 2000 |
1001 | 2001 |
1002 | 2002 |
I thinked in this possibility(for only one column):
update tableX
set column1 = (
select regexp_replace(column1, '[^0-9]', '')
from tableX);
But this code gives me ORA-01427
What's the other way to do this update?
英文:
I have a tableX with two columns, some with repeated values like:
column1 | column2 |
---|---|
'1000 -- Some Text' | '2000 -- Some Text' |
'1000 -- Some Text' | '2000 -- Some Text' |
'1001 -- Some Text' | '2001 -- Some Text' |
'1002 -- Some Text' | '2002 -- Some Text' |
What i want to do is to update both columns and remain with only the digits part:
column1 | column2 |
---|---|
1000 | 2000 |
1000 | 2000 |
1001 | 2001 |
1002 | 2002 |
I thinked in this possibility(for only one column):
update tableX
set column1 = (
select regexp_replace(column1, '[^0-9]', '')
from tableX);
But this code gives me ORA-01427
What's the other way to do this update?
答案1
得分: 2
我觉得你想要
更新 表X
设置 列1 = regexp_replace(列1, ''[^0-9]'', '''');
ORA-01427 的原因是查询
从 表X
选择 regexp_replace(列1, ''[^0-9]'', ''')
返回表X中的所有行。
英文:
I think you want
update tableX
set column1 = regexp_replace(column1, '[^0-9]', '');
The ORA-01427 is caused because the query
select regexp_replace(column1, '[^0-9]', '')
from tableX
returns all rows from tableX.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论