Oracle SQL: 大规模更新多行(包括重复行)

huangapple go评论59阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年3月15日 20:17:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75744581.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定