$ exp username/password file=expdat.dmp tables=tablename

这是一条经历了磨难的语句,然而最终也还是修成正果 

最开始报错:

EXP-00008: ORACLE error 904 encountered
ORA-00904: “DBMS_JAVA”.”LONGNAME”: invalid identifier
Export terminated successfully with warnings.

重新运行了$ORACLE_HOME/rdbms/admin/catexp.sql,无效,错误依旧。

然后运行$ORACLE_HOME/javavm/install/initdbj.sql,重新创建dbms_java包,这个错误消失了。

再次运行exp,报错:

Export done in US7ASCII character set and UTF8 NCHAR character set
server uses UTF8 character set (possible charset conversion)

EXP-00008: ORACLE error 6552 encountered
ORA-06552: PL/SQL: Compilation unit analysis terminated
ORA-06553: PLS-553: character set name is not recognized
Export terminated successfully with warnings.

检查系统环境,发现在props$中字符集是UTF8,但是操作系统环境变量没有设置NLS_LANG,于是:
NLS_LANG=AMERICAN_AMERICA.UTF8;export NLS_LANG

再次运行exp,仍然报错:

Export done in UTF8 character set and UTF8 NCHAR character set

EXP-00008: ORACLE error 6552 encountered
ORA-06552: PL/SQL: Compilation unit analysis terminated
ORA-06553: PLS-553: character set name is not recognized
Export terminated successfully with warnings.

于是询问客户是否有做过字符集的修改,果然,在很久很久以前,他们手动update props$表修改了字符集(手动修改props$是oracle7的招数,在oracle8和oracle9中虽然也能修改,但是会留下修改不干净的隐患)

首先,确认字符集是否修改的不彻底。

SELECT DISTINCT (NLS_CHARSET_NAME(CHARSETID)) CHARACTERSET,
                DECODE(TYPE#,
                       1,
                       DECODE(CHARSETFORM,
                              1,
                              'VARCHAR2',
                              2,
                              'NVARCHAR2',
                              'UNKOWN'),
                       9,
                       DECODE(CHARSETFORM,
                              1,
                              'VARCHAR',
                              2,
                              'NCHAR VARYING',
                              'UNKOWN'),
                       96,
                       DECODE(CHARSETFORM, 1, 'CHAR', 2, 'NCHAR', 'UNKOWN'),
                       112,
                       DECODE(CHARSETFORM, 1, 'CLOB', 2, 'NCLOB', 'UNKOWN')) TYPES_USED_IN
  FROM SYS.COL$
 WHERE CHARSETFORM IN (1, 2)
   AND TYPE# IN (1, 9, 96, 112);
 
CHARACTERSET         TYPES_USED_IN
-------------------- -------------
AL16UTF16            NCHAR
AL16UTF16            NCLOB
AL16UTF16            NVARCHAR2
UTF8                 CHAR
UTF8                 VARCHAR2
WE8ISO8859P1         CHAR
WE8ISO8859P1         CLOB
WE8ISO8859P1         VARCHAR2
 
8 rows selected.
确实在数据库的列属性中仍然存在着多个字符集的设定,这是导致exp失败的原因。下面解决这个问题。

SHUTDOWN IMMEDIATE;
STARTUP MOUNT;
ALTER SYSTEM ENABLE RESTRICTED SESSION;
ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;
ALTER SYSTEM SET AQ_TM_PROCESSES=0;
ALTER DATABASE OPEN;
 
 
COL VALUE NEW_VALUE CHARSET SELECT VALUE FROM NLS_DATABASE_PARAMETERS WHERE PARAMETER='NLS_CHARACTERSET';
COL VALUE NEW_VALUE NCHARSET SELECT VALUE FROM NLS_DATABASE_PARAMETERS WHERE PARAMETER='NLS_NCHAR_CHARACTERSET';
 
--INTERNAL_USE是没有写在文档中的参数,用以强制完成字符集一致化
ALTER DATABASE CHARACTER SET INTERNAL_USE &CHARSET;
ALTER DATABASE NATIONAL CHARACTER SET INTERNAL_USE &NCHARSET;
 
 
SHUTDOWN IMMEDIATE;
STARTUP;
-- 再次启动数据库一遍
SHUTDOWN IMMEDIATE;
STARTUP;
按照上面的步骤,一步一步来,一步不要少,完成以后,重新检索col$表。

CHARACTERSET         TYPES_USED_IN
-------------------- -------------
UTF8                 CHAR
UTF8                 CLOB
UTF8                 NCHAR                         
UTF8                 NCLOB
UTF8                 NVARCHAR2
UTF8                 VARCHAR2
干净了,再次运行exp,大功告成。

Export terminated successfully without warnings.

 http://www.dbform.com/html/2007/309.html   EXP错误逐个击溃