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

--创建表
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博客 ” ,链接:http://blog.itpub.net/9240380/viewspace-755336/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/9240380/viewspace-755336/

SELECT '155427848241370' || SEQ_KD_INDEX.nextval || 'GJ', a.PROBABLECAUSE, ( SELECT zhFUNc_GETNEWIDFORCIR ( id ) FROM gistar.tdn_switch ch WHERE ch.ipaddress = a.IP AND ROWNUM = 1 ), '1028200001', ( SELECT name FROM gistar.tdn_switch ch WHERE ch.ipaddress = a.IP AND ROWNUM = 1 ), ( SELECT code FROM gistar.tdn_switch ch WHERE ch.ipaddress = a.IP AND ROWNUM = 1 ), a.IP, a.ALARMTIME, a.alarmtext, SYSDATE, NULL, a.alarmid, a.createtime, a.perceivedseverity, a.moname FROM ( SELECT x.*, ( SELECT COUNT( DISTINCT re.coveraddressid ) FROM gistar.jr_customer_record @yjyx_zy re WHERE re.project_type IN ( 'FTTH宽带' ) AND re.oltip = x.IP ) AS oltcount FROM gistar.t_trouble_alarminfo x ) a WHERE a.specialty = 'PON' AND a.motype = 'OLT' AND IP IS NOT NULL AND a.PROBABLECAUSE = 'OLT网管脱网' AND ( SELECT substr( b.tt_number, 0, 2 ) FROM fwbz.t_trouble_ticket_new @GDOSSDB_SGDD b WHERE a.tt_id = b.tt_id ) = 'NM' AND ( SELECT title FROM fwbz.t_trouble_ticket_new @GDOSSDB_SGDD b WHERE a.tt_id = b.tt_id ) = 'OLT网管脱网' AND ( ( SYSDATE < '2021-05-01' AND a.oltcount >= 600 ) OR a.oltcount >= 400 ) UNION ALL SELECT '155427848241370' || SEQ_KD_INDEX.nextval || 'GJ', a.PROBABLECAUSE, ( SELECT zhFUNc_GETNEWIDFORCIR ( id ) FROM gistar.tdn_switch ch WHERE ch.ipaddress = a.IP AND ROWNUM = 1 ), '1028200001', ( SELECT name FROM gistar.tdn_switch ch WHERE ch.ipaddress = a.IP AND ROWNUM = 1 ), ( SELECT code FROM gistar.tdn_switch ch WHERE ch.ipaddress = a.IP AND ROWNUM = 1 ), a.IP, a.ALARMTIME, a.alarmtext, SYSDATE, a.cleartime, a.alarmid, a.createtime, a.perceivedseverity, a.moname FROM ( SELECT x.*, ( SELECT COUNT( DISTINCT re.coveraddressid ) FROM gistar.jr_customer_record @yjyx_zy re WHERE re.project_type IN ( 'FTTH宽带' ) AND re.oltip = x.IP ) AS oltcount FROM gistar.t_trouble_alarminfo x ) a WHERE a.specialty = 'PON' AND a.motype = 'OLT' AND IP IS NOT NULL AND a.PROBABLECAUSE = 'OLT网管脱网' AND ( SELECT substr( b.tt_number, 0, 2 ) FROM fwbz.t_trouble_ticket_new @GDOSSDB_SGDD b WHERE a.tt_id = b.tt_id ) = 'NM' AND ( SELECT title FROM fwbz.t_trouble_ticket_new @GDOSSDB_SGDD b WHERE a.tt_id = b.tt_id ) = 'OLT网管脱网' AND ( ( SYSDATE < '2021-05-01' AND a.oltcount >= 600 ) OR a.oltcount >= 400 ) AND a.cleartime IS NOT NULL AND a.alarmid IN ( SELECT alarm_id FROM olt_ALARM_BILL GROUP BY alarm_id, device_ip, alarm_time, create_time HAVING count( * ) = 1 );报错ORA-02287: sequence number not allowed here
06-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值