Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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):

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

If anyone knows why this is, please help me.

like image 365
user968441 Avatar asked Jun 13 '12 11:06

user968441


People also ask

How do you check if a sequence exists in Oracle?

Best Answer Although you could find the sequences in a schema using the query :" select sequence_name from user_sequences;", You should use the query "select sequence_name from all_sequences;" to find out all sequences accessible to the schema user.

How do you check if a column has a sequence in Oracle?

There are no direct metadata links between Oracle sequences and any use in the database. You could make an intelligent guess if a column's values are related to a sequence by querying the USER_SEQUENCES metadata and comparing the LAST_NUMBER column to the data for the column.

WHERE are sequences stored in Oracle?

Answer: The values for a sequence are internal to Oracle but most guru's says that the values are stored in the SYS. SEQ$ table with supplemental parts in the OBJ$ table, with the OBJ# column as the join key.

What is sequence in Oracle 11g?

An Oracle Sequence is a database object, just like a table or view, that represents a sequence of integers that can be used by any table or view in the global database namespace. A Sequence's values can be accessed using the NEXTVAL, and CURRVAL pseudo-columns. A Sequence can be ascending or descending.


2 Answers

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

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' ;
like image 108
A.B.Cade Avatar answered Oct 25 '22 13:10

A.B.Cade


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

SELECT COUNT(*) FROM DBA_SEQUENCES;

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

Check Oracle docs.

like image 34
bkg Avatar answered Oct 25 '22 13:10

bkg