SQL Select中的顺序 [英] Sequence within SQL Select

查看:81
本文介绍了SQL Select中的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SELECT语句中使用我的序列时遇到了一些问题.

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    
FROM
     customer c
WHERE
     c.customer_id IS NULL
ORDER BY
     c.site_code ASC
;

给我一​​个错误:

  1. 00000-此处不允许使用序列号" *原因:指定的序列号(CURRVAL或NEXTVAL)为 不当 在声明中. *操作:删除序列号.
  1. 00000 - "sequence number not allowed here" *Cause: The specified sequence number (CURRVAL or NEXTVAL) is inappropriate here in the statement. *Action: Remove the sequence number.

这很明显是我做错了,因此希望这是一个简单的答案.

It's probably something obvious I'm doing wrong so hopefully this will be an easy answer.

推荐答案

您不能在使用ORDER BY的查询中使用序列.

You cannot use sequences in queries with ORDER BY.

删除ORDER BY或放入子查询中:

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

这篇关于SQL Select中的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆