INSERT SELECT statement in Oracle 11G

后端 未结 5 395
醉梦人生
醉梦人生 2020-11-30 13:40

I\'m trying to run a very simple sql statement in Oracle 11g.

 insert into table1 (col1, col2) values (select t1.col1, t2.col2 from oldtable1 t1, oldtable2 t         


        
相关标签:
5条回答
  • 2020-11-30 14:02

    You don't need the 'values' clause when using a 'select' as your source.

    insert into table1 (col1, col2) 
    select t1.col1, t2.col2 from oldtable1 t1, oldtable2 t2;
    
    0 讨论(0)
  • 2020-11-30 14:05

    for inserting data into table you can write

    insert into tablename values(column_name1,column_name2,column_name3);
    

    but write the column_name in the sequence as per sequence in table ...

    0 讨论(0)
  • 2020-11-30 14:13

    Your query should be:

    insert into table1 (col1, col2) 
    select t1.col1, t2.col2 
    from oldtable1 t1, oldtable2 t2
    

    I.e. without the VALUES part.

    0 讨论(0)
  • 2020-11-30 14:14

    There is an another option to insert data into table ..

    insert into tablename values(&column_name1,&column_name2,&column_name3);
    

    it will open another window for inserting the data value..

    0 讨论(0)
  • 2020-11-30 14:17

    Get rid of the values keyword and the parens. You can see an example here.

    This is basic INSERT syntax:

    INSERT INTO "table_name" ("column1", "column2", ...)
    VALUES ("value1", "value2", ...);
    

    This is the INSERT SELECT syntax:

    INSERT INTO "table1" ("column1", "column2", ...)
    SELECT "column3", "column4", ...
    FROM "table2";
    
    0 讨论(0)
提交回复
热议问题