执行:
insert into table1(con1,con2,con3) values ((select max(con1)+1 from table2),(select con2 from table3),'0,0,0,1,0,0');
报错:
ERROR at line 1:
ORA-01427: single-row subquery returns more than one row怎么处理?
谢谢!

解决方案 »

  1.   

    --不知道是这个需求不?
    insert into table1(con1,con2,con3) 
    valuse
    select (select max(con1)+1 from table2) col1,
            con2 col3,
           '0,0,0,1,0,0' col3
    from table3
      

  2.   

    select con2 from table3 这里返回了多个值
      

  3.   

    insert into table1 (con1,con2,con3)
    select max(table2.con1)+1,table3.con2 ,'0,0,0,1,0,0' from table2,table3
    group by table3.con2不知道是不是这样的?
      

  4.   


    insert into table1 (con1,con2,con3)
    select max(table2.con1)+1,table3.con2 ,'0,0,0,1,0,0' from table2,table3
    group by table3.con2
      

  5.   


    create table table1(
           con1 number(5),
           con2 varchar2(10),
           con3 varchar2(15));
    create table table2(
           con1 number(5),
           con2 varchar2(10),
           con3 varchar2(10));
    create table table3(
           con1 varchar2(10),
           con2 varchar2(10),
           con3 varchar2(10));
    SQL> select * from table2;
    /*
      CON1 CON2       CON3
    ------ ---------- ----------
        50 阿凡达     3D电影
        66 未来警察   科幻片
        15 天天向上   综艺节目
    */
    SQL> select * from table3;
    /*
    CON1       CON2       CON3
    ---------- ---------- ----------
    太贵了     宝马       7系
    中等价     奥迪       A4
    跑车       宝马       Z4
    豪华车     奔驰       C200K
    概念车     路虎       LRX
    */
    SQL> insert into table1(con1,con2,con3)
      2  values ((select max(con1)+1 from table2),(select con2 from table3),'0,0,0,1,0,0');ORA-01427: single-row subquery returns more than one row
    /*
    你的select max(con1)+1 from table2只返回一个数据,
    但是select con2 from table3就返回多条数据,
    而每个insert into table语句一次只能插入一条数据,
    你的这条插入语句解释下来就是这么的:
    insert into table1(con1,con2,con3) 
    values(来自table2的一条数据,来自table3的多条数据,'0,0,0,1,0,0');
    所以你会碰到这个错误
    */
    SQL> insert into table1(con1,con2,con3)
      2         select max(table2.con1)+1,
      3                table3.con2,
      4                '0,0,0,1,0,0'
      5         from table2,table3
      6         group by table3.con2;4 rows insertedSQL> select * from table1;
    /*
      CON1 CON2       CON3
    ------ ---------- ---------------
        67 奥迪       0,0,0,1,0,0
        67 宝马       0,0,0,1,0,0
        67 奔驰       0,0,0,1,0,0
        67 路虎       0,0,0,1,0,0
    */
      

  6.   

    select con2 from table3 --这个单独执行。看看是几条数据
      

  7.   

    当返回多条记录时,不要用values