问题
I'm working on a project in which we may be using an Oracle 11g or an Oracle 12c database depending on what's available in various environments -- not ideal I know :(
My project is a Spring Boot application and I'm using Liquibase to manage the database objects.
My problem is that if I'm running on an Oracle 12c database, I'd like to take advantage of auto incrementing IDs while on Oracle 11g, I'll have to rely on a trigger and a sequence.
Is there a way to detect if the current version of Oracle supports auto incrementing or do I have to look at the version number?
The SQL that I currently have, which works, just looks at the version number:
SELECT
CASE
WHEN (TO_NUMBER(SUBSTR(version, 1, INSTR(version, '.') - 1)) >= 12) THEN
1
ELSE
0
END AS SUPPORTS_AUTO_INC
FROM
V$INSTANCE;
I'd much rather have some SQL which checks if the feature is available (same principal when using features in CSS).
Who knows, maybe Oracle will remove this feature in the future.
回答1:
I would check the version. Oracle does have a V$SQL_FEATURE
table and a DBA_FEATURE_USAGE_STATISTICS
table, but neither seem to have any entries specifically about identity columns.
Here is a really hokey way you could do it...
select decode(count(*),0,'N','Y') supports_identity_flag
from dba_tab_columns
where table_name = 'DBA_TAB_COLUMNS'
and column_name = 'IDENTITY_COLUMN';
来源:https://stackoverflow.com/questions/51179975/how-to-detect-if-oracle-database-supports-auto-increment