-- begin 
                 
             /*Select count(*)
              into count1
              From (select c.Channelitemid,c.Channelid from regentd.channel c  where 
              c.Name  like('%(闭)%') or c.name like ('%(闭)%')
              and c.Channelitemid ='5B3BD6900E834CBBBB443EA2FB8872C1' or  c.Channelitemid ='8B1DC268C6BC466BB73F083D14B46EEF'
              and c.incomecustomer is null) b 
              left Join regentd.Channelitemlist ct On b.Channelitemid =ct.Id;
              */
              --- whi`le count1>0 
                -- loop   
               insert into regentd.couponschannelsheet(
                        guid,channelid)
                Select v_coupon_id,b.Channelid
                --into v_channelid
                From (select c.Channelitemid,c.Channelid from regentd.channel c  where 
                c.Name  like('%(闭)%') or c.name like ('%(闭)%')
                and c.Channelitemid ='5B3BD6900E834CBBBB443EA2FB8872C1' or  c.Channelitemid ='8B1DC268C6BC466BB73F083D14B46EEF'
                and c.incomecustomer is null) b 
                left Join regentd.Channelitemlist ct On b.Channelitemid =ct.Id;
               --values(v_coupon_id,v_channelid); 
                --count1 := count1-1;   
              --end loop;   
              --end;     

首先查出来b.Channelid(多行数据),v_coupon_id(单行数据),他们的关系是一对的关系,我想要的结果是如下图

解决方案 »

  1.   


    insert into regentd.couponschannelsheet
      (guid, channelid)
      Select v_coupon_id, b.Channelid
      --into v_channelid
        From (select c.Channelitemid, c.Channelid
                from regentd.channel c
               where c.Name like ('%(闭)%')
                  or c.name like ('%(闭)%')
                 and c.Channelitemid = '5B3BD6900E834CBBBB443EA2FB8872C1'
                  or c.Channelitemid = '8B1DC268C6BC466BB73F083D14B46EEF'
                 and c.incomecustomer is null) b
        left Join regentd.Channelitemlist ct
          On b.Channelitemid = ct.Id;
    --values(v_coupon_id,v_channelid);
    图中有效语句,不会出现这个错误。过程中,还有其他的语句吧。
      

  2.   

    把结果查出来直接笛卡尔集。
    例如:
    select a.c1,b.c1 from a,b;