ITPub博客

首页 > Linux操作系统 > Linux操作系统 > group by与ORA-02287: sequence number not allowed here

group by与ORA-02287: sequence number not allowed here

原创 Linux操作系统 作者:wisdomone1 时间:2013-03-05 22:31:25 0 删除 编辑

--创建表
SQL> create table t_test(a int);
 
Table created

--插入数据
SQL> insert into t_test values(1);
 
1 row inserted
 
SQL> commit;
 
Commit complete
 
SQL> insert into t_test values(2);
 
1 row inserted
 
SQL> commit;
 
Commit complete
 
SQL> select * from t_test;
 
                                      A
---------------------------------------
                                      1
                                      2
--正常group by运行正常
SQL> select a,count(a) from t_test group by a;
 
                                      A   COUNT(A)
--------------------------------------- ----------
                                      1          1
                                      2          1
--添加常量字符串列也可用于group by
SQL> select a,count(a),'x' from t_test group by a;
 
                                      A   COUNT(A) 'X'
--------------------------------------- ---------- ---
                                      1          1 x
                                      2          1 x
 
--创建序列
SQL> create sequence seq_rpt start with 1;
 
Sequence created

--group by不能直接使用序列
SQL> select a,count(a),'x',seq_rpt.nextval from t_test group by a;
 
select a,count(a),'x',seq_rpt.nextval from t_test group by a
 
ORA-02287: sequence number not allowed here
 
--包装group by可使用sequence
SQL> select a,juji,x,seq_rpt.nextval from (select a,count(a) as juji,'x' as x from t_test group by a);
 
                                      A       JUJI X    NEXTVAL
--------------------------------------- ---------- - ----------
                                      1          1 x          1
                                      2          1 x          2

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9240380/viewspace-755336/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
提供针对oracle初学者及进阶的数据库培训,欢迎大家咨询: 微信: wisdomone 微信公众号: lovedb 工作经历: 中国普天 北京科蓝 北京云和恩墨 北京神州新桥

注册时间:2008-04-04

  • 博文量
    2189
  • 访问量
    12686901