SQLPlus中的COPY指令学习
来源:互联网 发布:md5判断密码正确java 编辑:程序博客网 时间:2024/05/02 04:15
SQLPlus中的COPY指令学习
最近看同事操作数据库,用到了copy命令,惊叹自己之前竟然不知道。赶紧看了一下,虽然这么命令很简单,但是确实是很有用。
首先看一下文档里的语法定义:
COPY {FROM database | TO database | FROM database TO database}{APPEND|CREATE|INSERT|REPLACE} destination_table [(column, column, column, ...)]USING query
下面对语法逐一说明:
1、DATABASE
database 对应以下的语法格式是:username[/password]@connect_identifier
注意:如果不加密码,则sqlplus会提示你输入密码。考虑到安全性,则应该不写密码。
2、FROM|TO子句
可以注意到,在这个语法里,FROM 和 TO 两个子句都是可以单独出现的(当然一起出现是最常见的情况)。当没有指定 FROM/TO 子句,则使用当前连接的数据库。
无论是 FROM 还是 TO 子句中连接的数据库,都不能是 SYSDBA 或 SYSOPER 权限的用户。
3、COPY类型
APPEND
--表存在则INSERT,不存在则CREATE
--表存在则INSERT,不存在则CREATE
Inserts the rows from query into destination_table if the table exists. If destination_table does not exist, COPY creates it.
CREATE
--新建一个表,如果表存在则出错
Inserts the rows from query into destination_table after first creating the table. If destination_table already exists, COPY returns an error.
INSERT
--向表中插入记录
--向表中插入记录
Inserts the rows from query into destination_table. If destination_table does not exist, COPY returns an error. When using INSERT, the USING query must select one column for each column in destination_table.
REPLACE
--无论表是否存在,均清空然后CREATE
Replaces destination_table and its contents with the rows from query. If destination_table does not exist, COPY creates it. Otherwise, COPY drops the existing table and replaces it with a table containing the copied data.
Replaces destination_table and its contents with the rows from query. If destination_table does not exist, COPY creates it. Otherwise, COPY drops the existing table and replaces it with a table containing the copied data.
4、destination_table
注意指定目标表的同时,是可以指定其字段的,但是其字段数目和类型(如果已经存在)必须与后面的query中相一致,否则报错。
------------------------------------
下面举例说明:
SQL> COPY FROM HR/HR @HQ TO JOHN/kkk @WEST REPLACE WESTEMPLOYEES USING SELECT * FROM EMPLOYEES;
别的没什么可说的,但是要注意如果使用新建表的时候,新建的表的字段属性,都是与原表相同的。在一般的情况下这都是没有什么问题的,但是会有一种比较特殊的情况,就是例如:原始库的字符集为ZHS16GBK,而目标库的字符集为UTF-8,因为UTF-8中一个汉字占3个字节,而ZHS16GBK是2个。所以当原始库中的一个属性为varchar2(2)且为一个汉字的字段,就无法导入到UTF-8库中了,会报错:ORA-12899: value too large for column ...
遇到这种情况,建议修改原始库的字段属性,如果没有权限,则可以在目标库中手工建立一下表,将字段属性调整到合适,然后使用INSERT或者APPEND类型COPY。
另注:select * from nls_database_parameters; 查看字符集
- SQLPlus中的COPY指令学习
- SQLPlus中的COPY指令学习
- SQLPlus中的COPY指令学习
- sqlplus copy
- Oracle数据库间的数据复制 - SQLPlus中的COPY命令
- SQLPLUS相关指令
- sqlplus基本指令
- Oracle SqlPlus 常用指令
- Oracle sqlplus copy命令用法
- Oracle.sqlplus中copy命令
- Dockerfile中的COPY和ADD指令详解与比较
- docker学习笔记16:Dockerfile 指令 ADD 和 COPY介绍
- docker学习笔记16:Dockerfile 指令 ADD 和 COPY介绍
- SQLPLUS 常用指令小收集
- SQLPLUS 常用指令小收集
- sqlplus 中set指令集合
- oracle sqlplus中copy命令的用法
- SQLPLUS中的feedback设置
- POJ 3159 Candies 差分约束 spfa+栈+邻接表
- [每日一题] 11gOCP 1z0-052 :2013-09-20 BIGFILE | SMALLFILE TABLESPACE.....................B43
- VC6 + OpenCV1.0实现图片缩放显示
- 手工冷备份脚本
- CLOSE_WAIT
- SQLPlus中的COPY指令学习
- Linux高性能服务器编程(笔记1)
- 黑马程序员_java基础加强(一) JDK1.5新特性
- 格雷码
- Polya 原理 着色问题
- hdu_3729 I'm Telling the Truth 二分图匹配
- 线程实现生产者消费者实验
- hdu_1528 Card Game Cheater 二分图匹配
- 素数和分解