ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 关于sequence和nextval

关于sequence和nextval

原创 Linux操作系统 作者:itpubstream 时间:2008-09-08 17:24:49 0 删除 编辑
问题:
从一个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/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 论坛常用笔记
请登录后发表评论 登录
全部评论

注册时间:2008-08-05

  • 博文量
    9
  • 访问量
    7553