1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
| select userenv('language') nls_lang from dual;
select nls_charset_name(to_number('0354','xxxx')) from dual;
select 'alter table '||table_name||' enable constraint '||constraint_name||';' from user_constraints where constraint_type='R'; select 'alter table '||table_name||' disable constraint '||constraint_name||';' from user_constraints where constraint_type='R';
SELECT 'alter trigger '|| OBJECT_NAME ||' disable;' FROM DBA_OBJECTS WHERE OBJECT_TYPE='TRIGGER' and owner='YO_ONLINE' order by OBJECT_NAME; SELECT 'alter trigger '|| OBJECT_NAME ||' enable;' FROM DBA_OBJECTS WHERE OBJECT_TYPE='TRIGGER' and owner='YO_ONLINE' order by OBJECT_NAME;
SELECT 'truncate table '||table_name||';' FROM ALL_TABLES WHERE OWNER='YO_TEST';
select 'drop table '||table_name||';' FROM ALL_TABLES WHERE OWNER='YO_TEST';
SELECT ATS.NUM_ROWS,ATS.TABLE_NAME FROM ALL_TABLES ATS WHERE ATS.OWNER='YO_ONLINE' ORDER BY ATS.TABLE_NAME ASC;
show pagesize; set pagesize 300; show linesize; set linesize 300;
sqlplus /nolog SQL>connect sys/sys as sysdba SQL>SHUTDOWN IMMEDIATE SQL>STARTUP MOUNT; SQL>ALTER SYSTEM ENABLE RESTRICTED SESSION; SQL>ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0; SQL>ALTER SYSTEM SET AQ_TM_PROCESSES=0; SQL>ALTER DATABASE OPEN; SQL>ALTER DATABASE CHARACTER SET INTERNAL_USE ZHS16GBK; //跳过超子集检测 SQL>ALTER DATABASE national CHARACTER SET INTERNAL ZHS16GBK; SQL>SHUTDOWN IMMEDIATE; SQL>STARTUP ================================= SQL> conn /as sysdba ====================================== Connected. ================================ SQL> shutdown immediate; ================================ Database closed.
Database dismounted.
ORACLE instance shut down. ================================ SQL> startup mount ================================ ORACLE instance started.
Total System Global Area 236000356 bytes
Fixed Size 451684 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted. ================================ SQL> ALTER SYSTEM ENABLE RESTRICTED SESSION; ================================ System altered. ================================ SQL> ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0; ================================ System altered. ================================ SQL> ALTER SYSTEM SET AQ_TM_PROCESSES=0; ================================ System altered.
SQL> alter database open;
Database altered. ================================ SQL> ALTER DATABASE CHARACTER SET AL32UTF8; ================================ ALTER DATABASE CHARACTER SET ZHS16GBK
*
ERROR at line 1:
ORA-12712: new character set must be a superset of old character set
提示我们的字符集:新字符集必须为旧字符集的超集,这时我们可以跳过超集的检查做更改: ================================ SQL> ALTER DATABASE character set INTERNAL_USE AL32UTF8; ================================ Database altered. ================================ SQL> select * from v$nls_parameters; ================================ 略
19 rows selected.
重启检查是否更改完成: ================================ SQL> shutdown immediate; ================================ Database closed.
Database dismounted. ORACLE instance shut down. ================================ SQL> startup ================================ ORACLE instance started. Total System Global Area 236000356 bytes Fixed Size 451684 bytes Variable Size 201326592 bytes Database Buffers 33554432 bytes Redo Buffers 667648 bytes Database mounted. Database opened. ================================ SQL> select * from v$nls_parameters; ================================ 略 19 rows selected.
D、client端字符集修改
在 /home/oracle与 /root用户目录下的.bash_profile中
添加或修改 export NLS_LANG="AMERICAN_AMERICA.UTF8" 语句
关闭当前ssh窗口。
exp imp cross_dev/sss@cross_test fromuser=cross_dev touser=cross_dev rows=y indexes=n ignore=y commit=y file=d:\cross_dev.dmp
select userenv('language') from dual;
用oracle的exp工具导出的dmp文件也包含了字符集信息,dmp文件的第2和第3个字节记录了dmp文件的字符集。如果dmp文件不大,比如只有几M或几十M, 可以用UltraEdit打开(16进制方式),看第2第3个字节的内容,如0354,然后用以下SQL查出它对应的字符集: select nls_charset_name(to_number('0354','xxxx')) from dual; 如果dmp文件很大,比如有2G以上(这也是最常见的情况),用文本编辑器打开很慢或者完全打不开,可以用以下命令(在unix主机上): cat exp.dmp |od -x|head -1|awk '{print $2 $3}'|cut -c 3-6 然后用上述SQL也可以得到它对应的字符集。
$echo $NLS_LANG
(1).数据库服务器字符集 select * from nls_database_parameters 来源于props$,是表示数据库的字符集。
(2).客户端字符集环境 select * from nls_instance_parameters 其来源于v$parameter,表示客户端的字符集的设置,可能是参数文件,环境变量或者是注册表
(3).会话字符集环境 select * from nls_session_parameters 来源于v$nls_parameters,表示会话自己的设置,可能是会话的环境变量或者是alter session完成,如果会话没有特殊的设置,将与nls_instance_parameters一致。
(4).客户端的字符集要求与服务器一致,才能正确显示数据库的非Ascii字符。 如果多个设置存在的时候,NLS作用优先级别:Sql function > alter session > 环境变量或注册表> 参数文件> 数据库默认参数
字符集要求一致,但是语言设置却可以不同,语言设置建议用英文。如字符集是zhs16gbk,则nls_lang可以是American_America.zhs16gbk。
============================导入数据=======================================================================================================
sqlplus / as sysdba;
select max(sequence#) from v$archived_log;
select name from v$datafile;
create tablespace yoonline datafile '/data/app/oracle/oradata/orcl/yoonline01.dbf' size 3072m;
create tablespace yoonline datafile '/data/app/oracle/oradata/yo/yoonline01.dbf' size 4096m;
create tablespace yotest datafile '/data/app/oracle/oradata/orcl/yotest01.dbf' size 4096m; 3000m指的是3000MB,10G
create user yo_online identified by yo_online123 default tablespace yoonline;
create user yo_test identified by yo_test123 default tablespace yotest;
grant dba,connect,resource to yo_online;
select userenv('language') from dual;
select 'drop table '||table_name||';' from cat where table_type='TABLE';
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
在命令窗口执行 @(sql文件位置)
select 'alter table '||table_name||' enable constraint '||constraint_name||';' from user_constraints where constraint_type='R'; select 'alter table '||table_name||' disable constraint '||constraint_name||';' from user_constraints where constraint_type='R';
SELECT 'alter trigger '|| OBJECT_NAME ||' disable;' FROM DBA_OBJECTS WHERE OBJECT_TYPE='TRIGGER' and owner='YO_ONLINE' order by OBJECT_NAME; SELECT 'alter trigger '|| OBJECT_NAME ||' enable;' FROM DBA_OBJECTS WHERE OBJECT_TYPE='TRIGGER' and owner='YO_ONLINE' order by OBJECT_NAME;
select 'ALTER TABLE '||TABLE_NAME||' MODIFY '||COLUMN_NAME||' VARCHAR2(1000);' from user_tab_columns where data_type='VARCHAR2' AND DATA_LENGTH>=100 AND DATA_LENGTH<1000 and TABLE_NAME like 'T%'; select 'ALTER TABLE '||TABLE_NAME||' MODIFY '||COLUMN_NAME||' VARCHAR2(200);' from user_tab_columns where data_type='VARCHAR2' AND DATA_LENGTH<100 and TABLE_NAME like 'T%';
### expdp导出 impdp导入数据 sqlplus / as sysdba execute dbms_metadata_util.load_stylesheets;
expdp yogs/yogsdbserver@orcl TABLES=t_bs_test dumpfile=expdp.dmp logfile=expdp.log DIRECTORY=dpdata;
|