如何检查 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
How do I check if a sequence exists or not in Oracle 11g?
提问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 MP
then 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 文档。