ora-00936缺少带有insert into子句的表达式

时间:2016-03-01 11:28:00

标签: sql sql-insert

获取ORA-00936:在以下查询中缺少表达式。 请帮忙。

INSERT INTO TT_FX_LADDER_INFO(DEAL_NUM,SPOT_RATE,FORWARD_RATE,LBS_RATE,DF_CCY1,DF_CCY2,FX_TYPE,TYPE,TRADING_BOOK_FBO_ID_NUM,ENTITY_FBO_ID_NUM,POS_CCY_PAIR,AS_ON_DATE,DECOMPOSE_DATE,CCY_ONE_AMOUNT,CCY_TWO_AMOUNT,CCY_1,CCY_2,IS_FX_MERCHANT_TRADE) VALUES  
(
    SELECT '0','0','0','0','0','0','FWD','OPENING POSITION',TRADING_BOOK_FBO_ID_NUM,ENTITY_FBO_ID_NUM,CURRENCY_PAIR,LADDER_DATE,DECOMPOSE_DATE,SUM(CCY_ONE_AMOUNT) CCY_ONE_POSITION,SUM(CCY_TWO_AMOUNT) CCY_TWO_POSITION,CCY_1,CCY_2,IS_FX_MERCHANT_TRADE 
    FROM 
    (
        SELECT hdg.TRADING_BOOK_FBO_ID_NUM TRADING_BOOK_FBO_ID_NUM,hdg.ENTITY_FBO_ID_NUM,hdg.CURRENCY_PAIR,
        TO_CHAR(elem.LADDER_DATE,'DD-MM-YYYY') LADDER_DATE,
        TO_CHAR(elem.LADDER_DATE,'DD-MM-YYYY') DECOMPOSE_DATE

        FROM TT_FX_HDG hdg,TT_FX_HDG_ELEMS elem
        WHERE elem.DEAL_NUM = hdg.DEAL_NUM 
        AND hdg.FX_TYPE = 'FWD'   

    )
    group by TRADING_BOOK_FBO_ID_NUM,ENTITY_FBO_ID_NUM,CURRENCY_PAIR,LADDER_DATE,DECOMPOSE_DATE,CCY_1,CCY_2,IS_FX_MERCHANT_TRADE
);

没有insert into子句的内部查询工作正常。

非常感谢帮助。

2 个答案:

答案 0 :(得分:0)

只需删除values即可。使用insert . . . select时无需任何操作。所以,假设其他一切都排好了:

INSERT INTO TT_FX_LADDER_INFO(DEAL_NUM, SPOT_RATE,FORWARD_RATE,LBS_RATE,DF_CCY1,DF_CCY2,FX_TYPE,TYPE,TRADING_BOOK_FBO_ID_NUM,ENTITY_FBO_ID_NUM,POS_CCY_PAIR,AS_ON_DATE,DECOMPOSE_DATE,CCY_ONE_AMOUNT,CCY_TWO_AMOUNT,CCY_1,CCY_2,IS_FX_MERCHANT_TRADE
                              )  
    SELECT '0','0','0','0','0','0', 'FWD', 'OPENING POSITION',
           TRADING_BOOK_FBO_ID_NUM, ENTITY_FBO_ID_NUM, CURRENCY_PAIR,
           LADDER_DATE, DECOMPOSE_DATE,
           SUM(CCY_ONE_AMOUNT) as CCY_ONE_POSITION,
           SUM(CCY_TWO_AMOUNT) as CCY_TWO_POSITION,
           CCY_1,CCY_2,IS_FX_MERCHANT_TRADE 
    FROM (SELECT hdg.TRADING_BOOK_FBO_ID_NUM TRADING_BOOK_FBO_ID_NUM, hdg.ENTITY_FBO_ID_NUM, hdg.CURRENCY_PAIR,
                 TO_CHAR(elem.LADDER_DATE,'DD-MM-YYYY') as LADDER_DATE,
                 TO_CHAR(elem.LADDER_DATE,'DD-MM-YYYY') as DECOMPOSE_DATE
          FROM TT_FX_HDG hdg JOIN
               TT_FX_HDG_ELEMS elem
               ON elem.DEAL_NUM = hdg.DEAL_NUM  AND hdg.FX_TYPE = 'FWD'   
          ) x
     GROUP BY TRADING_BOOK_FBO_ID_NUM, ENTITY_FBO_ID_NUM, CURRENCY_PAIR,
              LADDER_DATE, DECOMPOSE_DATE, CCY_1,CCY_2,
              IS_FX_MERCHANT_TRADE;

我还建议:

  • 编写您的查询,以便您可以阅读它们 - 分解不可能的长行并在逗号后使用空格。
  • 学习使用正确的JOIN语法。简单规则:从不FROM子句中使用逗号。
  • 不要在数字常量周围加上单引号。在某些情况下(虽然不在这里),这可能会导致性能问题。
  • 定义列别名时使用as

答案 1 :(得分:0)

您的查询完全错误。发现一些错误。

SUM(CCY_ONE_AMOUNT) CCY_ONE_POSITION,SUM(CCY_TWO_AMOUNT) CCY_TWO_POSITION,CCY_1,CCY_2,IS_FX_MERCHANT_TRADE 

在内部select语句中未选择上面的列。因此它不会起作用。