2301_77613792 2023-06-09 10:09 采纳率: 50%
浏览 268
已结题

insert语句报错

这段sql长这样

insert into t_track_pro_code (track_pro_code,track_pro_code_name) select (with tb1 as (
select distinct m.track_pro_code from ba_bgt_info_hz m where m.ori_bgt_id in (
      select t.bgt_id from ba_bgt_info_hz t where t.track_pro_code in (select distinct track_pro_code from ba_bgt_info_hz 
where bgt_doc_title like '%车辆购置税收入补助地方资金%' and is_deleted=2 and track_pro_code is not null and importtype not in (8,9)) 
and t.billstatus>=0 and t.importtype not in (8,9) 
    )  and m.importtype not in (8,9)  union  
    select distinct track_pro_code from ba_bgt_info_hz 
where bgt_doc_title like '%车辆购置税收入补助地方资金%' and is_deleted=2 and track_pro_code is not null and importtype not in (8,9)
) select distinct track_pro_code track_pro_code_name from tb1) track_pro_code,'车辆购置税收入补助地方资金' 
track_pro_code_name from dual

大概就是这样写的tab1只有两列哈。
insert into tab1 select (一个临时表),'名称' from dual;
这样报错,因为我临时表查出来是两行值 不重复的,然后name列我想写死。我想达到的效果是
1234 资金a
9876 资金a
//其中1234和9876是我从with表查出来的
有没有宝宝帮我改一下代码 达到我想要的效果!有偿!

  • 写回答

15条回答 默认 最新

  • macy0122 2023-06-09 11:08
    关注
    
    INSERT INTO t_track_pro_code (track_pro_code, track_pro_code_name) 
    WITH tb1 AS (
    SELECT DISTINCT m.track_pro_code, '车辆购置税收入补助地方资金' track_pro_code_name
    FROM ba_bgt_info_hz m
    WHERE m.ori_bgt_id IN (
          SELECT t.bgt_id
    FROM ba_bgt_info_hz t
    WHERE t.track_pro_code IN (SELECT DISTINCT track_pro_code
    FROM ba_bgt_info_hz
    WHERE bgt_doc_title LIKE '%车辆购置税收入补助地方资金%'
    AND is_deleted = 2
    AND track_pro_code IS NOT NULL
    AND importtype NOT IN (8, 9))
        AND t.billstatus >= 0
        AND t.importtype NOT IN (8, 9) 
        )
    AND m.importtype NOT IN (8, 9)
    UNION  
        SELECT DISTINCT track_pro_code, '车辆购置税收入补助地方资金' track_pro_code_name
    FROM ba_bgt_info_hz
    WHERE bgt_doc_title LIKE '%车辆购置税收入补助地方资金%'
    AND is_deleted = 2
    AND track_pro_code IS NOT NULL
    AND importtype NOT IN (8, 9)
    ) SELECT DISTINCT track_pro_code ,track_pro_code_name
    FROM tb1
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(14条)

报告相同问题?

问题事件

  • 系统已结题 6月24日
  • 已采纳回答 6月16日
  • 修改了问题 6月9日
  • 修改了问题 6月9日
  • 展开全部