Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle UPDATE statement using the `REPLACE` function

I am trying to remember how form a proper REPLACE statement in Oracle SQL.

In essence, I need to perform a REPLACE over a few thousand records in which column1 and column2 may contain a value of '14'. If they do, I need to replace it with just a space character.

I know that the syntax is something like the following, but I can't seem to get it quite right:

UPDATE TABLE
SET ('column1', 'column2') = REPLACE(?????????????)
WHERE 'column1' IN ('14') AND 'column2' NOT LIKE ('4%')

Any help would be appreciated.

like image 604
Jared Avatar asked Sep 10 '12 15:09

Jared


People also ask

Can we use Replace in UPDATE query?

You can use REPLACE in an UPDATE statement.

Can we use UPDATE statement in function in Oracle?

The stored function may not modify database tables. It cannot execute an INSERT, DELETE, or UPDATE statement. A stored function that is called remotely or through a parallelized action may not read or write the values of package variables. The Oracle Server does not support side effects that cross user sessions.

What is the Replace function in Oracle?

An Oracle REPLACE Function is used to replace the string with a given string as the name suggests. It accepts a search string and replaces it with another given string but pattern-wise. It returns CHAR with every replaced with replacement string for the search string.


1 Answers

UPDATE TABLENAME
  SET COLUMN1 = ' ',
  SET COLUMN2 = ' '
WHERE COLUMN1='14' OR COLUMN2='14';

Assuming Column[1,2] are of Character type.

like image 192
djadmin Avatar answered Nov 15 '22 20:11

djadmin