多个表的Oracle SQL Insert语句

时间:2013-08-20 20:28:41

标签: sql database oracle sql-insert

我有两个表格Alpha_SettingBeta_View,如下所示

Alpha_Setting

ID ( Sequence )
VIEW_ID
VIEW_TYPE
VIEW_VALUE

Beta_View

ID
VIEW_NAME
VIEW_TYPE
VIEW_CHECK

我想在Beta_View中将VIEW_ID中的多个ID插入Alpha_Setting,我应该如何更正我的SQL

insert into alpha_setting 
('',  
(select ID from beta_view where view_type = 'HERO' and (view_name = 'GREEN-All' or view_name = 'GREEN-New'),  
'super_power',   
'1000000');

1 个答案:

答案 0 :(得分:1)

尝试这种方式:

insert into alpha_setting (ID,VIEW_ID,VIEW_TYPE,VIEW_VALUE)
select '' /* or seq_name.nextval*/, ID,'super_power','1000000'
from beta_view 
where view_type = 'HERO' 
and view_name in('GREEN-All','GREEN-New','super_power','1000000');

insert into alpha_setting (ID,VIEW_ID,VIEW_TYPE,VIEW_VALUE)
select '' /* or seq_name.nextval*/, ID,'super_power','1000000'
from beta_view 
where view_type = 'HERO' 
and (view_name = 'GREEN-All' or view_name in('GREEN-New','super_power','1000000'));

我不确定view_name列的哪个条件对你有好处。