在intersect中利用oracle sequence報錯_ora-02287
from c_chapter_info
union all
select lpad(seq_only_maxid.nextval,16,'0') chapter_id,a.*
from (
select *
from (
select part,version,version_id,subjectid,chapter_id from tmp_content where part is not null
)
) a
原文出處:
What causes this error?
An ORA-02287 occurs when you use a sequence where it is not allowed. The usage of a sequence is limited and it can be used only in few areas of PL/SQL and coding.
Where can one use sequences
The following are the cases where you can't use a sequence:
For a SELECT Statement:
In a WHERE clause
In a GROUP BY or ORDER BY clause
In a DISTINCT clause
Along with a UNION or INTERSECT or MINUS
In a sub-query
Other areas:
A sub-query of Update or Delete
In a View or snapshot
In a DEFAULT or CHECK Condition of a table definition
Within a single SQL statement that uses CURVAL or NEXTVAL, all referenced LONG columns, updated tables, and locked tables must be located on the same database.
How to fix it
If your statement fits one of the above said conditions, then you would see this error being raised. I have some possible solutions:
If you need the sequence value for a WHERE clause or a sub-query or order by, then fetch the sequence value into a variable and use the variable in the necessary places.
If you want the sequence value to be inserted into the column for every row created, then create a before insert trigger and fetch the sequence value in the trigger and assign it to the column
If you want to use a sequence in a view, then first create the view with all other columns and conditions without the sequence and then use the sequence when you actually type in "select a, b, c from view".
If you want to use a sequence in a select query with distinct clause, then you can use distinct in sub query and sequence.nextval in main query as follows -
insert into av_temp(col1, col2)
select t.col1, shift_allocation_seq.nextval
from (select distinct col1 from av_temp1) t;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-668132/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- ORACLE中union/union all/Intersect/Minus用法Oracle
- Oracle中的Union、Union All、Intersect、MinusOracle
- 在Hibernate中關於Oracle sequence的使用KHOracle
- Oracle中Sequence的使用Oracle
- oracle中sequence使用的限制Oracle
- Oracle 中Union、Union All、Intersect、Minus(並,交,差)Oracle
- Oracle中sequence cache的測試Oracle
- Oracle中sequence的使用方法Oracle
- ORACLE SQL的EXCEPT、INTERSECT用法OracleSQL
- ORACLE SEQUENCEOracle
- ORACLE SEQUENCE用法Oracle
- Oracle - Sequence序列Oracle
- Oracle Sequence NocacheOracle
- Oracle序列sequenceOracle
- JTable 在TCP傳輸中報錯TCP
- Oracle 11g使用MERGE報錯'ORA-02287..The specified sequence number (CURRVAL'Oracle
- oracle11g 在dg中standby檢視報ora-04045錯誤Oracle
- Oracle之Sequence(序列)Oracle
- Oracle Sequence Audses$研究Oracle
- oracle sequence語法Oracle
- oracle sequence 試用Oracle
- 在KYLIN中執行查詢報錯
- 在MySQL中建立實現自增的序列(Sequence)MySql
- oracle dg報錯Oracle
- oracle emctl 報錯Oracle
- oracle的scn及sequenceOracle
- 在Weblogic中建立域(含報錯解決)Web
- Oracle中Nextval用法SEQUENCE與SYS_GUID()OracleGUI
- 在Oracle 11.2.0.3.0中執行awrrpt.sql生成awr報告報ora-06502錯誤OracleSQL
- Oracle TNS報錯大全Oracle
- 連線oracle報錯Oracle
- 【轉】MySQL中增加sequence管理功能(模擬建立sequence)MySql
- oracle 19c dg搭建duplicate過程中報錯Oracle
- Oracle DBLink中CLOB報錯ORA-22992Oracle
- Oracle利用errorstack追蹤tomcat報錯ORA-00903 無效表名OracleErrorTomcat
- 關於vue、es6專案在IE中報錯Vue
- oracle 報大小寫錯誤Oracle
- Oracle 10.2.0.5 opatch報錯Oracle