Oracle: Update a datarow by adding to existing value Oracle: Update a datarow by adding to existing value oracle oracle

Oracle: Update a datarow by adding to existing value


All that is needed is to use the concatenation operator, ||. Update syntax does not require that you have a subquery to obtain column2gettingupdated for the value, 12233.

Also, with Oracle VARCHAR2's, you use single quotes and not double quotes. This results in this syntax for this statement:

UPDATE table   SET column2gettingupdated = 'prefix' || column2gettingupdated WHERE SpecificNumber        = 12233;

Here is an example from the example schema SCOTT:

SCOTT@dev> CREATE TABLE DEPT2 as (  2          SELECT *  3            FROM DEPT  4         );Table created.SCOTT@dev> commit;Commit complete.SCOTT@dev> UPDATE DEPT2  2     SET DNAME  = 'PRE '|| DNAME  3   WHERE DEPTNO = 20;1 row updated.SCOTT@dev> commit;Commit complete.SCOTT@dev> SELECT *  2    FROM dept  3   WHERE deptno = 20  4   UNION  5  SELECT *  6    FROM dept2  7   WHERE deptno = 20  8  SCOTT@dev> /    DEPTNO DNAME          LOC========== ============== =============        20 PRE RESEARCH   DALLAS        20 RESEARCH       DALLAS


Use concatenation for strings:

update <table_name>   set column2gettingupdated = 'Prefix-' || column2gettingupdated  where specificnumber = 12233; -- use NUMBER literal instead of string one