Insert from CTE
P粉573809727
P粉573809727 2023-08-24 10:57:10
0
2
554
<p><pre class="brush:php;toolbar:false;">WITH DTL AS (SELECT CMPI_CODE, CMN_CDTY_MTRL, CMI_WT_FACTOR, CMI_CNTRCT_RATE, 'PL', PRESENT_PRICE, TRM_CODE, ROUND(((NVL(PRESENT_PRICE,1)*CMI_WT_FACTOR) / CMI_CNTRCT_RATE),2) AS PL_FACTOR FROM VW_CMD_MATERIAL WHERE TRM_CODE = 41) INSERT iNTO IPA_PRCADJ_HDR(TRM_CODE,IPAPH_ADJ_FACTOR,IPAPH_AMT_CUR,IPAPH_REMARKS) SELECT TRM_CODE,SUM(PL_FACTOR) AS PL_FACTOR,((SUM(PL_FACTOR)*10)) AS AMT_CUR,'asdf' FROM DTL GROUP BY (TRM_CODE);</pre> <p>显示错误 <code>ORA-00928: 缺少 SELECT 关键字</code></p>
P粉573809727
P粉573809727

reply all(2)
P粉450744515

It seems that Insert cannot be used as the first statement after a common table expression. Try this,

INSERT iNTO IPA_PRCADJ_HDR(TRM_CODE,IPAPH_ADJ_FACTOR,IPAPH_AMT_CUR,IPAPH_REMARKS)
    SELECT * FROM 
    (

      WITH DTL AS
      (SELECT CMPI_CODE,
             CMN_CDTY_MTRL,
             CMI_WT_FACTOR,
             CMI_CNTRCT_RATE,
             'PL',
             PRESENT_PRICE,
             TRM_CODE,
             ROUND(((NVL(PRESENT_PRICE,1)*CMI_WT_FACTOR) / CMI_CNTRCT_RATE),2) AS PL_FACTOR
      FROM VW_CMD_MATERIAL WHERE TRM_CODE = 41
      )
      SELECT TRM_CODE,SUM(PL_FACTOR) AS PL_FACTOR,((SUM(PL_FACTOR)*10)) AS AMT_CUR,'asdf' 
      FROM DTL GROUP BY (TRM_CODE)
    );
P粉738248522

This is the syntax for inserting into a table from a CTE:

-- CREATE TABLE tmp ( tmp_id NUMBER(10) );

INSERT INTO tmp( tmp_id )
  WITH cte AS (
    SELECT 1 AS tmp_id FROM dual
  )
  SELECT tmp_id
  FROM cte;
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template