一、使用entityManager可以动态传入表名,首先需要查询出所有空表

 @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();

二、通过entityManager创建Query对象,并执行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(); } } }
12-17 21:56