@@ -44,10 +44,16 @@ public class OracleMetaData extends DefaultMetaService implements MetaData {
4444 FROM ALL_OBJECTS
4545 WHERE OBJECT_TYPE IN ('PROCEDURE')
4646 AND OWNER = '%s'""" ;
47- public static final String TABLE_INDEX_DDL_SQL = """
48- SELECT DBMS_METADATA.GET_DDL('INDEX', index_name, table_owner) AS ddl
49- FROM all_indexes
50- WHERE table_owner = '%s' AND table_name = '%s'""" ;
47+ private static final String TABLE_INDEX_DDL_SQL = """
48+ SELECT DBMS_METADATA.GET_DDL('INDEX', index_name, table_owner) AS ddl,
49+ index_name AS INDEX_NAME
50+ FROM all_indexes
51+ WHERE table_owner = '%s' AND table_name = '%s'""" ;
52+ private static final String PU_INDEX_NAME_SQL = """
53+ SELECT DISTINCT AC.INDEX_NAME
54+ FROM ALL_CONSTRAINTS AC
55+ WHERE AC.OWNER = '%s' AND AC.TABLE_NAME = '%s'
56+ AND AC.CONSTRAINT_TYPE IN ('P', 'U')""" ;
5157
5258 @ Override
5359 public List <Procedure > procedures (Connection connection , String databaseName , String schemaName ) {
@@ -76,6 +82,7 @@ public String tableDDL(Connection connection, String databaseName, String schema
7682 String tableCommentSql = String .format (TABLE_COMMENT_SQL , schemaName , tableName );
7783 String tableColumnCommentSql = String .format (TABLE_COLUMN_COMMENT_SQL , schemaName , tableName );
7884 String tableIndexSql = String .format (TABLE_INDEX_DDL_SQL , schemaName , tableName );
85+ String PUIndexSql = String .format (PU_INDEX_NAME_SQL , schemaName , tableName );
7986 StringBuilder ddlBuilder = new StringBuilder ();
8087 SQLExecutor .getInstance ().execute (connection , sql , resultSet -> {
8188 try {
@@ -107,9 +114,22 @@ public String tableDDL(Connection connection, String databaseName, String schema
107114 }
108115 }
109116 });
110-
117+ List <String > indexNames = SQLExecutor .getInstance ().execute (connection , PUIndexSql , resultSet -> {
118+ List <String > PUIndexNames = new ArrayList <>();
119+ while (resultSet .next ()) {
120+ String indexName = resultSet .getString ("index_name" );
121+ if (StringUtils .isNotBlank (indexName )) {
122+ PUIndexNames .add (indexName );
123+ }
124+ }
125+ return PUIndexNames ;
126+ });
111127 SQLExecutor .getInstance ().execute (connection , tableIndexSql , resultSet -> {
112128 while (resultSet .next ()) {
129+ String indexName = resultSet .getString ("INDEX_NAME" );
130+ if (CollectionUtils .isNotEmpty (indexNames ) && indexNames .contains (indexName )) {
131+ continue ;
132+ }
113133 String ddl = resultSet .getString ("ddl" );
114134 if (StringUtils .isNotBlank (ddl )) {
115135 ddlBuilder .append ("\n " ).append (ddl ).append (";" );
0 commit comments