如何使用不存在插入?

时间:2015-12-30 08:26:15

标签: oracle oracle11g oracle10g

我正在尝试构建以下查询,但它总是给我错误“SQL命令未正确结束”。我该如何使用它?

  INSERT INTO PROGRAM_KPI (AMSPROGRAMID,MASTER_KPI_ID,LASTUPDATEDBYDATALOAD) 
  (SELECT 'PRG-026',MASTER_KPI_ID,to_char(sysdate,'dd-mon-yy hh.mi.ss') from kpi_master)
   WHERE NOT EXISTS(select * from insight_master
          where amsprogramid = V_PROGRAMID
          and inamsscope = 1
          and tickettype = 'INCIDENT'
          and TICKETSUBMITDATE is not null);

1 个答案:

答案 0 :(得分:1)

请尝试这个..(删除括号并格式化代码)

INSERT INTO program_kpi
                    (amsprogramid, master_kpi_id, lastupdatedbydataload)
           SELECT 'PRG-026', master_kpi_id, TO_CHAR (SYSDATE, 'dd-mon-yy hh.mi.ss')
           FROM   kpi_master
           WHERE  NOT EXISTS (
                     SELECT *
                     FROM   insight_master
                     WHERE  amsprogramid = v_programid AND inamsscope = 1
                            AND tickettype = 'INCIDENT'
                            AND ticketsubmitdate IS NOT NULL);

但表program_kpi和insight_master之间的关系是什么?

内部子查询和外部子查询之间似乎没有连接。