我在SELECT语句中使用序列时遇到了一些问题.
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
;
Run Code Online (Sandbox Code Playgroud)
给我一个错误:
- 00000 - "此处不允许序列号"*原因:声明中指定的序列号(CURRVAL或NEXTVAL)不合适.*操作:删除序列号.
这可能是显而易见的我做错了所以希望这将是一个简单的答案.
Qua*_*noi 14
您不能在查询中使用序列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
Run Code Online (Sandbox Code Playgroud)