日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

ORA-02287: sequence number not allowed here

發(fā)布時(shí)間:2024/4/17 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ORA-02287: sequence number not allowed here 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

?http://devbbs.doit.com.cn/thread-11269-1-1.html

http://zsjg13.iteye.com/blog/737677

?

當(dāng)插入值需要從另外一張表中檢索得到的時(shí)候,如下語(yǔ)法的sql語(yǔ)句已經(jīng)不能完成該功能:
insert into my_table(id, name) values ((select seq_my_table.nextval from dual), ‘runto30′);
會(huì)報(bào)“ORA-02287: sequence number not allowed here”的錯(cuò)誤,可以使用如下語(yǔ)句來(lái)完成:
insert into my_table(id, name) select seq_my_table.nextval,
' runto30 ' from dual;

?

或者是

insert into my_table(id, name) values( seq_my_table.nextval, ' runto30 ' )

==========

ORA-02287
From Oracle FAQ
Jump to: navigation, search
ORA-02287: sequence number not allowed here

[edit] 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 SQL coding.

[edit] 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 CURRVAL or NEXTVAL, all referenced LONG columns, updated tables, and locked tables must be located on the same database.
[edit] 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 -

總結(jié)

以上是生活随笔為你收集整理的ORA-02287: sequence number not allowed here的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。