The dynamic table name passed modifications to the table, I'm here mainly demo oracle empty table can not be exported

First, the use entityManager can dynamically pass the table name, you first need to check out all the empty tables

 @Query(value = "select 'alter table ' || a.table_name || ' allocate extent' from user_tables a where a.table_name not in (select segment_name from user_segments where segment_type = 'TABLE')", nativeQuery = true)
 List<String> findTables();

Second, create a Query object by entityManager, and perform sql

        List<String> list = versionDao.findTables();
                if (!list.isEmpty() && list != null) {
                    for (String str : list) {
               //Str : alter table RECORD allocate extent,截取RECORD String reg
= "alter table (.*?) allocate extent"; Pattern compile = Pattern.compile(reg); Matcher matcher = compile.matcher(str); while (matcher.find()) { String sql = "alter table " + matcher.group(1) + " allocate extent"; Query query = entityManager.createNativeQuery(sql); query.executeUpdate(); } } }

 

Guess you like

Origin www.cnblogs.com/ZeroLife/p/11977847.html