此处不允许序号

  1. --=========因查询中用了group by,所以不能直接用序列值====
  2. select test.sequence.nextval,mgr,sum(sal) from emp group by mgr  
  3.    
  4. ORA-02287: 此处不允许序号  
  5.   
  6.    
  7.   
  8. 果然,在外面再包一层就可以了  
  9.   
  10. SQL> select test_sequence.nextval,mgr,sm from (select mgr,sum(sal) sm from emp group by mgr );  
  11.    
  12.    NEXTVAL   MGR         SM  
  13. ---------- ----- ----------  
  14.         27  7839       8275  
  15.         28  7782       1300  
  16.         29  7698       6550  
  17.         30  7902       5800  
  18.         31  7566       6000  
  19.         32  7788       1100  
  20.    
  21. 6 rows selected  
  22.   
  23.    
  24.   
  25. 看来序列使用时有限制的  
  26.   
  27. 看到书上说有这么多限制  
  28.   
  29. Restrictions on Sequence Values You cannot use CURRVAL and NEXTVAL in the  
  30. following constructs:  
  31. ■ A subquery in a DELETE, SELECT, or UPDATE statement  
  32. ■ A query of a view or of a materialized view  
  33. ■ A SELECT statement with the DISTINCT operator  
  34. ■ A SELECT statement with a GROUP BY clause or ORDER BY clause    --这个就是我遇到的那种情况  
  35. ■ A SELECT statement that is combined with another SELECT statement with the  
  36. UNION, INTERSECT, or MINUS set operator  
  37. ■ The WHERE clause of a SELECT statement  
  38. ■ The DEFAULT value of a column in a CREATE TABLE or ALTER TABLE statement  
  39. ■ The condition of a CHECK constrain  

猜你喜欢

转载自yhzhangdota.iteye.com/blog/2379782