你用exp命令把数据从第一个表空间的用户的数据导出来后,再用imp命令导入到第二个表空间的第二个用户

解决方案 »

  1.   

    直接用create table as select * from  吧,,
      

  2.   

    Basically, there are 2 ways to do this. One way is to use oralce new feature alter table ...move. Another way is to use exp and imp. I beleave personnally ths 1st one is more helpful to move some objects on line, while the latter is a better choice for moving all objects belongs to a user between tablespaces offline. We will take at a look at both of them by giving an exmaple. Lets I have a user called rudolf at database test902. We try to move all objects belong to user rudolf which are in "USERS" to "TS". First, I try to find all segments which are in 'USERS':   rudolf@TEST902>select segment_name,segment_type from user_segments                               2  where tablespace_name = 'USERS'    3  /    SEGMENT_NAME                                                                      SEGMENT_TYPE  --------------------------------------------------------------------------------- ------------------  DEPT                                                                              TABLE  EMP                                                                               TABLE  BONUS                                                                             TABLE  SALGRADE                                                                          TABLE  T                                                                                 TABLE  LEADS                                                                             TABLE  PK_DEPT                                                                           INDEX  PK_EMP                                                                            INDEX    8 rows selected.  Generating the tablespace moving statements:   rudolf@TEST902>select 'alter '||segment_type||' '||segment_name    2            ||decode(segment_type,'TABLE',' MOVE ','INDEX',' REBUILD ',' OTHERS:cluster?mv?,please define by your self')    3            ||' tablespace ts;'    4  from user_segments;    'ALTER'||SEGMENT_TYPE||''||SEGMENT_NAME||DECODE(SEGMENT_TYPE,'TABLE','MOVE','INDEX','REBUILD','OTHER  ----------------------------------------------------------------------------------------------------  alter TABLE DEPT MOVE  tablespace ts;  alter TABLE EMP MOVE  tablespace ts;  alter TABLE BONUS MOVE  tablespace ts;  alter TABLE SALGRADE MOVE  tablespace ts;  alter TABLE T MOVE  tablespace ts;  alter TABLE LEADS MOVE  tablespace ts;  alter INDEX PK_DEPT REBUILD  tablespace ts;  alter INDEX PK_EMP REBUILD  tablespace ts;  alter INDEX T_PK REBUILD  tablespace ts;    9 rows selected.  If there are 'clusters, mvs...', please make up by yourself. And for easiness, you may like to spool all the above stmts into a file, so that you can execute it one time:   rudolf@TEST902>set term off verify off head off feedback off echo off  rudolf@TEST902>spool mvddl.sql  rudolf@TEST902>select 'alter '||segment_type||' '||segment_name    2  ||decode(segment_type,'TABLE',' MOVE ','INDEX',' REBUILD ',' OTHERS:cluster?mv?,please define by your self')    3  ||' tablespace ts;'    4  from user_segments;    alter TABLE DEPT MOVE  tablespace ts;  alter TABLE EMP MOVE  tablespace ts;  alter TABLE BONUS MOVE  tablespace ts;  alter TABLE SALGRADE MOVE  tablespace ts;  alter TABLE T MOVE  tablespace ts;  alter TABLE LEADS MOVE  tablespace ts;  alter INDEX PK_DEPT REBUILD  tablespace ts;  alter INDEX PK_EMP REBUILD  tablespace ts;  alter INDEX T_PK REBUILD  tablespace ts;  rudolf@TEST902>spool off  rudolf@TEST902>exit  rudolf@test9i:~ > vi mvddl.sql   Edit the file generated so that it could be executed.   rudolf@TEST902>@mvddl    Table altered.    Table altered.    Table altered.    Table altered.    Table altered.    Table altered.    Index altered.    Index altered.    Index altered.  And after this, you may rebuild all index based on the tables you have moved. Now, let's move the 2nd method. It is the method I prefer. Before we do anything, let's check the result: 
      rudolf@TEST902>select segment_name,tablespace_name from user_segments;    SEGMENT_NAME                   TABLESPACE_NAME  ------------------------------ ------------------------------  DEPT                           TS  EMP                            TS  BONUS                          TS  SALGRADE                       TS  T                              TS  LEADS                          TS  PK_DEPT                        TS  PK_EMP                         TS  T_PK                           TS    9 rows selected.  Our target is to move these object back to 'USERS' tablespace. here is how: exp rudolf/nix compress=n statistics=none file=rudolf Recreate user rudolf:   system@TEST902>  system@TEST902>drop user rudolf cascade;    User dropped.    system@TEST902>create user rudolf identified by nix    2  default tablespace users    3  temporary tablespace temp    4  quota 0 on system    5  quota unlimited on users    6  quota unlimited on indx;    User created.    system@TEST902>grant connect,resource to rudolf;    Grant succeeded.  After the user was recreated, we use imp to extract out our script for table recreation: imp rudolf/nix rows=n show=y file=rudolf.dmp indexfile=tabcre.sql Edit tabcre.sql, repace ABLESPACE "TS" with TABLESPACE "USERS", and you may remove the "rem" comments, delete some lines. 
      system@TEST902>@connect rudolf/nix  rudolf@TEST902>  rudolf@TEST902>@tabcre  Table created. .... IMP data now, and check the status: imp rudolf/nix file=rudolf.dmp ignore=y   rudolf@TEST902>select segment_name,tablespace_name from user_segments;       SEGMENT_NAME                   TABLESPACE_NAME  ------------------------------ ------------------------------  BONUS                          USERS  DEPT                           USERS  EMP                            USERS  LEADS                          USERS  SALGRADE                       USERS  T                              USERS  PK_DEPT                        USERS  PK_EMP                         USERS  T_PK                           USERS  You'll see we succeeded in switch the objects' tablespace from TS to USERS. Hope this is helpful you. 
      

  3.   

    hehe,楼上的格式错位,看到我头都晕了!
    突然想起来要做的不是这么回事,我要做的是从一个库把数据和表空间全部导到另一个库,呵呵,不知道alter方法行不行了!
      

  4.   

    "alter" is only used in the same database;
      

  5.   

    nnd...放这么多洋文,,假洋鬼子,,