实现功能如下:
insert into [xxx](a,b,c,d,e)
values('','','','','')其中:
 select a from [aaa] where ...
 select b from [bbb] where ...:
 ...
 select e from [eee] where ...:
如上的sql能不能写成一条?像这样,
insert into [xxx](a,b,c,d,e)
values(select a from [aaa] where ...,select b from [bbb] here ...,'','','')
但是会报错的。
该怎么解决。

解决方案 »

  1.   

    insert into [xxx](a,b,c,d,e)
    values(
    select (select a from [aaa] where ...),(select b from [bbb] here ...),'','',''
      from dual)
    试试
    我在家没法调试,大致是这个思路,写在一个查询里,每个字段是一个字查询
      

  2.   

    可以。
    第一种方法:
    例如:
    insert into [xxx](a,b,c,d,e)
    values(select a from [aaa] where ...),(select b from [bbb] here ...),'select 才 from [ccc] here ...','select d from [ddd] here ...','select e from [eee] here ...')但是必须保证每个查询返回的都是一条记录。如果不能保证是一条记录,则需要用 条件限制rownum<=1建议用另一种方法(insert 语句 + 一个对应的查询):insert into [xxx](a,b,c,d,e)
    select a,b,c,d,e from ???(1) 如果五个表的数据有关联的话,我们可以这样
    insert into [xxx](a,b,c,d,e)
    select a,b,c,d,e from v_testv_test是一个由 aaa,bbb,ccc,ddd,eee 产生的一个视图。(2) 如果没有关联。则可以用 类似 zqz117(南瓜少爷) 的方法,返回一个查询。