Sequence within SQL Select

后端 未结 3 1039
旧时难觅i
旧时难觅i 2021-02-15 15:51

I\'m having a bit of a problem with using my sequence within a SELECT statement.

SELECT
     c.cust_name,
     c.site,
     customer_id_seq.nextval         


        
相关标签:
3条回答
  • 2021-02-15 16:25

    for IBM Imformix

    In a SELECT statement, you cannot specify NEXTVAL or CURRVAL in the following contexts:

    • In the projection list when the DISTINCT keyword is used
    • In the WHERE, GROUP BY, or ORDER BY clauses
    • In a subquery
    • When the UNION operator combines SELECT statements
    0 讨论(0)
  • 2021-02-15 16:30

    You cannot use sequences in queries with ORDER BY.

    Remove the ORDER BY or put in into a subquery:

    SELECT  q.*, customer_id_seq.nextval    
    FROM    (
            SELECT  c.cust_name,
                    c.site
            FROM    customer c
            WHERE   c.customer_id IS NULL
            ORDER BY
                    c.site_code ASC
            ) q
    
    0 讨论(0)
  • 2021-02-15 16:40

    Why don't you use rownum instead of fetching values from sequence?

    0 讨论(0)
提交回复
热议问题