---
title: "批量移动表和索引的表空间"
author: "foohsinglong"
date: "2011-01-26T15:38:06Z"
tags: ["SQL"]
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2011-01-26T15:38:06Z"
id: 897383
url: "https://foohsinglong.iteye.com/blog/897383"
---

```sql
--1.修改表的空间 
alter table table_Name move tablespace TABLESPACENAME 

--查询当前用户下的所有表 
select 'alter table  '|| table_name ||'  move tablespace cjlogistics;'  from user_all_tables; 

--2.修改表的索引的空间 
alter index INDEX_NAME rebuild tablespace TABLESPACENAME 

--查询当前用户下的所有索引 
select 'alter index '|| index_name ||' rebuild tablespace cjlogistics;' from user_indexes; 

--3.用于移动lob索引表空间
SELECT 'alter table ' || t.owner || '.' || t.table_name ||' move tablespace cjlogistics lob (' || t.column_name ||') store as(tablespace LOBTPS_NAME_MOVEBK);' v_sql FROM dba_lobs t 
 WHERE t.tablespace_name='CJLOGISTICS';
```