Oracle从select插入具有更多列的表

时间:2022-05-01 01:55:20

I want to insert to a table from a select statement, however, there are 3 columns returned from the select statement and the table has 4 columns, I would like to add 0 for all rows in the extra column. Can anyone give me a sample SQL query for that?

我想从select语句中插入到表中,但是,从select语句返回3列,表有4列,我想为额外列中的所有行添加0。有人能给我一个SQL查询示例吗?

Thank you!

谢谢你!

3 个解决方案

#1


124  

Just add in the '0' in your select.

只需要在select中添加“0”即可。

INSERT INTO table_name (a,b,c,d)
    SELECT
       other_table.a AS a,
       other_table.b AS b,
       other_table.c AS c,
       '0' AS d
    FROM other_table

#2


5  

Put 0 as default in SQL or add 0 into your area of table

在SQL中设置0作为默认值,或者在表的区域中添加0

#3


1  

just select '0' as the value for the desired column

只需选择“0”作为所需列的值。

#1


124  

Just add in the '0' in your select.

只需要在select中添加“0”即可。

INSERT INTO table_name (a,b,c,d)
    SELECT
       other_table.a AS a,
       other_table.b AS b,
       other_table.c AS c,
       '0' AS d
    FROM other_table

#2


5  

Put 0 as default in SQL or add 0 into your area of table

在SQL中设置0作为默认值,或者在表的区域中添加0

#3


1  

just select '0' as the value for the desired column

只需选择“0”作为所需列的值。