2013-07-24 37 views
0

我得到PostgreSQL的執行過程中出現以下錯誤: ERROR [HY000]錯誤:你只能使用一個目標列表下一頁價值函數錯誤

有什麼不對這個SQL中的「下一個值(S)」功能聲明:

SELECT TRFCON.ID  
     , 
     case when DDDCON.ID_CON = 0 
     then 
     NEXT VALUE FOR SEQ_DDD_CON 
     else 
     DWHCON.ID_CON 
     end ID_CON 

    FROM TTT_CONSUMPTION TTTCON 

join DDDDWH_CON DWHCON on TTTCON.ID_ORG = DDDCON.ID_ORG 
and TTTCON.ID_PRO = DDDCON.ID_PRO 
and TTTCON.ID_REF = DDDCON.ID_REF 

該序列的DDL如下:

CREATE SEQUENCE SEQ_DDD_CON AS BIGINT 
    START WITH 1 
    INCREMENT BY 1 
    NO MINVALUE 
    NO MAXVALUE 
    NO CYCLE; 
+0

您的語法和錯誤消息是MySQL的不是Postgresql的問題標籤 –

+0

@ClodoaldoNeto建議我想他是試圖將它從MySQL移植到PG,因爲MySQL沒有序列。 – DrColossos

+0

我使用的Netezza SQL和Netezza SQL是基於PostgreSQL的 – MasterX

回答

1

從文檔的CREATE SEQUENCE

Compatibility

CREATE SEQUENCE conforms to the SQL standard, with the following exceptions:

  • [...]
  • Obtaining the next value is done using the nextval() function instead of the standard's NEXT VALUE FOR expression.
+0

我用nextval但同樣的錯誤。情況下,當DDDCON.ID_CON = 0 然後 NEXTVAL( 'SEQ_DDD_CON') 別的 DWHCON.ID_CON 端ID_CON – MasterX

+0

嘗試'NEXTVAL( ' 「SEQ_DDD_CON」')'。 – DrColossos

+0

DDDCON.ID_CON = 0時的情況nextval(''SEQ_DDD_CON'''else else DWHCON.ID_CON end ID_CON - > same error:ERROR [HY000] ERROR:只能在目標中使用'next value(s)'函數list – MasterX