How to update a column with concatenate of two other column in a same table

jalal rasooly

I have a table with 3 columns a, b and c. I want to know how to update the value of third column with concatenate of two other columns in each row.

before update
 A    B    c 
-------------
1     4
2     5
3     6

after update
 A    B    c 
-------------
1     4    1_4
2     5    2_5
3     6    3_6

How can I do this in oracle?

Lalit Kumar B

Firstly, you are violating the rules of normalization. You must re-think about the design. If you have the values in the table columns, then to get a computed value, all you need is a select statement to fetch the result the way you want. Storing computed values is generally a bad idea and considered a bad design.

Anyway,

Since you are on 11g, If you really want to have a computed column, then I would suggest a VIRTUAL COLUMN than manually updating the column. There is a lot of overhead involved with an UPDATE statement. Using a virtual column would reduce a lot of the overhead. Also, you would completely get rid of the manual effort and those lines of code to do the update. Oracle does the job for you.

Of course, you will use the same condition of concatenation in the virtual column clause.

Something like,

Column_c varchar2(50) GENERATED ALWAYS AS (column_a||'_'||column_b) VIRTUAL

Note : There are certain restrictions on its use. So please refer the documentation before implementing it. However, for the simple use case provided by OP, a virtual column is a straight fit.

Update I did a small test. There were few observations. Please read this question for a better understanding about how to implement my suggestion.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Update a row if a column value is not the same on other table

From Dev

How to update column with another column in the same table?

From Dev

How to update a column of a table depending on the other column automatically in MySQL?

From Dev

how to merge two column from same table

From Dev

Apache Cassandra: Update value with value of other column in same table

From Dev

Update a column with the combined results of multiple other columns in the same table

From Java

How to update column based on another column in the same table

From Dev

How to write this SQL Server syntax to update a column based on the values of 2 other columns in that same table

From Dev

Updating a column that depends on two other colums all in the same table

From Dev

Update Table column with values for other column

From Dev

How do I update a column based on other columns in the same row

From Dev

How to UPDATE MySQL Rows with other values in the same column?

From Dev

Update value of one table with other values of same column with different condition in same table

From Dev

Update value of one table with other values of same column with different condition in same table

From Dev

Update table column based on columns in other table

From Dev

Update query, how to get column name from other table

From Dev

Mysql - How to get all records being in other column in the same table

From Dev

update column with other column

From Dev

Update column of one table from same table

From Dev

Concatenate two column in python

From Dev

SQL How to Update SUM of column over group in same table

From Dev

SQL How to Update SUM of column over group in same table

From Dev

How can I update a column with same value in another table ssms?

From Dev

How to update SQL column based on previous search result of the same table

From Dev

sql same table same column but two data

From Dev

SQL: How to concatenate two cells from one column of multiple rows if all of the other row's cells are equal

From Dev

How to update MySQL table by swapping two column values?

From Dev

How to get records from a table with two column have same value?

From Dev

SQL Update a column dependent on other two columns

Related Related

  1. 1

    Update a row if a column value is not the same on other table

  2. 2

    How to update column with another column in the same table?

  3. 3

    How to update a column of a table depending on the other column automatically in MySQL?

  4. 4

    how to merge two column from same table

  5. 5

    Apache Cassandra: Update value with value of other column in same table

  6. 6

    Update a column with the combined results of multiple other columns in the same table

  7. 7

    How to update column based on another column in the same table

  8. 8

    How to write this SQL Server syntax to update a column based on the values of 2 other columns in that same table

  9. 9

    Updating a column that depends on two other colums all in the same table

  10. 10

    Update Table column with values for other column

  11. 11

    How do I update a column based on other columns in the same row

  12. 12

    How to UPDATE MySQL Rows with other values in the same column?

  13. 13

    Update value of one table with other values of same column with different condition in same table

  14. 14

    Update value of one table with other values of same column with different condition in same table

  15. 15

    Update table column based on columns in other table

  16. 16

    Update query, how to get column name from other table

  17. 17

    Mysql - How to get all records being in other column in the same table

  18. 18

    update column with other column

  19. 19

    Update column of one table from same table

  20. 20

    Concatenate two column in python

  21. 21

    SQL How to Update SUM of column over group in same table

  22. 22

    SQL How to Update SUM of column over group in same table

  23. 23

    How can I update a column with same value in another table ssms?

  24. 24

    How to update SQL column based on previous search result of the same table

  25. 25

    sql same table same column but two data

  26. 26

    SQL: How to concatenate two cells from one column of multiple rows if all of the other row's cells are equal

  27. 27

    How to update MySQL table by swapping two column values?

  28. 28

    How to get records from a table with two column have same value?

  29. 29

    SQL Update a column dependent on other two columns

HotTag

Archive