如何检查 Oracle 11g 中是否存在序列?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11013504/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 04:15:37  来源:igfitidea点击:

How do I check if a sequence exists or not in Oracle 11g?

oracleoracle11gsequence

提问by user968441

I am using Oracle 11g. I want to be able to determine whether a particular sequence exists or not. I have tried the code below but it is not working. (It is returning 0 as count value when there should be more):

我正在使用 Oracle 11g。我希望能够确定特定序列是否存在。我已经尝试了下面的代码,但它不起作用。(当应该有更多时,它返回 0 作为计数值):

SELECT COUNT(*)
FROM user_sequences
WHERE sequence_name = 'SCHEMA.SEQUENCE_NAME';

If anyone knows why this is, please help me.

如果有人知道这是为什么,请帮助我。

回答by A.B.Cade

If you are running the query as user MPthen try it like this:

如果您以用户身份运行查询,请MP尝试如下操作:

SELECT COUNT(*) 
FROM user_sequences 
WHERE sequence_name = 'SEQ_SSO_KEY_AUTHENTICATION';

else, try it like this:

否则,试试这样:

SELECT COUNT(*) 
FROM all_sequences 
WHERE sequence_name = 'SEQ_SSO_KEY_AUTHENTICATION'
AND sequence_owner = 'MP' ;

回答by bkg

Also, keep in mind that you may not be granted to see all sequences in DB. In this case scripts provided above may not work, and you should run something like

另外,请记住,您可能无权查看 DB 中的所有序列。在这种情况下,上面提供的脚本可能不起作用,您应该运行类似

SELECT COUNT(*) FROM DBA_SEQUENCES;

But this also may not work if you have no access to DBA_SEQUENCES view.

但是,如果您无权访问 DBA_SEQUENCES 视图,这也可能不起作用。

Check Oracle docs.

检查Oracle 文档