How to replace specific values in a oracle database column?

后端 未结 4 768
北恋
北恋 2020-12-04 11:15

I am looking to replace values in a particular column. For example the following column values

column name
----------
Test1
Test2
Test3
Test12
相关标签:
4条回答
  • 2020-12-04 11:47

    In Oracle, there is the concept of schema name, so try using this

    update schemname.tablename t
    set t.columnname = replace(t.columnname, t.oldvalue, t.newvalue);
    
    0 讨论(0)
  • 2020-12-04 11:53

    I'm using Version 4.0.2.15 with Build 15.21

    For me I needed this:

    UPDATE table_name SET column_name = REPLACE(column_name,"search str","replace str");
    

    Putting t.column_name in the first argument of replace did not work.

    0 讨论(0)
  • 2020-12-04 11:54

    Use REPLACE:

    SELECT REPLACE(t.column, 'est1', 'rest1')
      FROM MY_TABLE t
    

    If you want to update the values in the table, use:

    UPDATE MY_TABLE t
       SET column = REPLACE(t.column, 'est1', 'rest1')
    
    0 讨论(0)
  • 2020-12-04 11:58

    If you need to update the value in a particular table:

    UPDATE TABLE-NAME SET COLUMN-NAME = REPLACE(TABLE-NAME.COLUMN-NAME, 'STRING-TO-REPLACE', 'REPLACEMENT-STRING');
    

    where

      TABLE-NAME         - The name of the table being updated
      COLUMN-NAME        - The name of the column being updated
      STRING-TO-REPLACE  - The value to replace
      REPLACEMENT-STRING - The replacement
    
    0 讨论(0)
提交回复
热议问题