---
title: "ORACLE的常用知识技巧"
author: "Chevy"
date: "2010-12-06T09:58:22Z"
tags: []
categories: ["数据库"]
slug: "oracle"
draft: false
lastmod: "2010-12-06T10:24:48Z"
id: 834221
url: "https://chevy.iteye.com/blog/834221"
---

对数据表要进行备份可以在同一表空间里新建一张表：CREATE   TABLE   T\_BAK   AS   SELECT   *   FROM   T

如果要对某些表或视图建立同义词可以通过语句执行：

   

```
select 'create or replace public synonym '||table_name||' for user.'||table_name||';' from user_tables
select 'create or replace public synonym '||view_name||' for user.'||view_name||';' from user_views
select 'create or replace public synonym '||sequence_name||' for user.'||sequence_name||';' from user_sequences
```

同样可以利用这个语句执行删除：

 

```
select 'drop table '||table_name||';' from user_tables
where table_name like '%T%'

select 'drop PUBLIC SYNONYM '||table_name||';' from user_tables
where table_name like '%T%'
```

  

要导出用户下的表的方法：

 

```
exp user/password@Database file="D:\orcl.dmp" log="D:\orcl.log"
```

 

 

要导入用户下的某些表的方法：

```
imp user/password@Database file=D:\backup\oracle\tablebak.dmp fromuser = user1  tables=t_XXX touser=user
```

 

新建sequence

你首先要有CREATE SEQUENCE或者CREATE ANY SEQUENCE权限。

 

```
CREATE SEQUENCE emp_sequence 
INCREMENT BY 1 -- 每次加几个 
START WITH 1 -- 从1开始计数 
NOMAXvalue -- 不设置最大值 
NOCYCLE -- 一直累加，不循环 
CACHE 10; --设置缓存cache个序列，如果系统down掉了或者其它情况将会导致序列不连续，也可以设置为---------NOCACHE
```

 

更改表索引的表空间：

 

```
select 'alter index '||index_name||' rebuild tablespace T_INDEX;'
from user_indexes 
where owner='×××' and 
      table_name in ('×××', '×××');
```