How to merge (combine) 2 columns into 1 in oracle?

94,761

Solution 1

concatenate?

select col1 || ' ' || col2 from tablex

Solution 2

This is a very vague requirement. Concatenate the values maybe?

insert into sometable( Column1 )
values ( Column1 || Column2 );

If you need to specify the table name to INSERT into, then you will need to use dynamic SQL to achieve this. Would you need to specify the target column name as well? This example assumes you would use PL/SQL, which may not be appropriate in your case.

sql_stmt := 'INSERT INTO '|| specified_table || '(' || merge_column || ') VALUES ( :1 )';
EXECUTE IMMEDIATE sql_stmt USING column1 || column2;

http://docs.oracle.com/cd/B13789_01/appdev.101/b10807/13_elems017.htm

Share:
94,761
abekmuratov
Author by

abekmuratov

Updated on July 09, 2022

Comments

  • abekmuratov
    abekmuratov almost 2 years

    I have 3 textfields where user types table name and 2 column names which need to be merged.

    How should I merge (combine) 2 column values into 1?

    I use oracle 11g enterprise