问题:
从一个sequence中连续取出5个值, 然后降序排列, 居然无法用一句SQL实现, 可能吗?
我的测试环境为 10g:
从一个sequence中连续取出5个值, 然后降序排列, 居然无法用一句SQL实现?
先别上机实验, 你觉得这可能吗?
解答:
感觉就是.nextval 出现在了SQL中就用不了order by. 不知道是不是这样的
Uses and Restrictions of NEXTVAL and CURRVAL
CURRVAL and NEXTVAL can be used in the following places:
VALUES clause of INSERT statements
The SELECT list of a SELECT statement
The SET clause of an UPDATE statement
CURRVAL and NEXTVAL cannot be used in these places:
A subquery
A view query or materialized view query
A SELECT statement with the DISTINCT operator
A SELECT statement with a GROUP BY or ORDER BY clause
A SELECT statement that is combined with another SELECT statement with the UNION, INTERSECT, or MINUS set operator
The WHERE clause of a SELECT statement
DEFAULT value of a column in a CREATE TABLE or ALTER TABLE statement
The condition of a CHECK constraint
问题2:
在不上机测试的情况下,请给出答案。
create sequence s;
select s.nextval from dual;
select s.currval , s.nextval , s.nextval from dual;
标准答案是 2 2 2
放在一起,只引用一次,值是nextvalue
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/15081535/viewspace-442406/
,如需转载,请注明出处,否则将追究法律责任。