plsql基本操作 复制表 导出表 导出表结构 及其导入

上一片中介绍了安装instantclient +plsql取代庞大客户端的安装,这里说下plsql的基本操作

plsql操作界面图:

 

1、复制表

 语句:create table IGIS_COPY as select * from IGIS_LOCATION

2、查询前5行数据

select * from IGIS_LOCATION where rownum < 6

注意:与sql server的top 5 不同,前5行数据只能使用where rownum < 6

 

导出查询出来的数据。注意是.sql文件

 

下面是用txt打开上面导出的.sql文件,其原理是是对数据库进行insert

下面的数据表是

IGIS_LOCATION_COPY,是我将上面的
IGIS_LOCATION备份了一份,进行操作

prompt Importing table IGIS_LOCATION_COPY...
set feedback off
set define off
insert into IGIS_LOCATION_COPY (DEVICECODE, TYPE, LONGITUDE, LATITUDE, DATETIME)
values ('001FF92FABE165', 'man', 121.12, 31.12, to_date('26-04-2017 14:29:05', 'dd-mm-yyyy hh24:mi:ss'));

insert into IGIS_LOCATION_COPY (DEVICECODE, TYPE, LONGITUDE, LATITUDE, DATETIME)
values ('004999010640000', 'man', 121.12, 31.12, to_date('26-04-2017 14:29:05', 'dd-mm-yyyy hh24:mi:ss'));

insert into IGIS_LOCATION_COPY (DEVICECODE, TYPE, LONGITUDE, LATITUDE, DATETIME)
values ('012963007793321', 'man', 121.12, 31.12, to_date('26-04-2017 14:29:05', 'dd-mm-yyyy hh24:mi:ss'));

insert into IGIS_LOCATION_COPY (DEVICECODE, TYPE, LONGITUDE, LATITUDE, DATETIME)
values ('013437006991011', 'man', 121.12, 31.12, to_date('26-04-2017 14:29:05', 'dd-mm-yyyy hh24:mi:ss'));

insert into IGIS_LOCATION_COPY (DEVICECODE, TYPE, LONGITUDE, LATITUDE, DATETIME)
values ('013789000795180', 'man', 121.12, 31.12, to_date('26-04-2017 14:29:05', 'dd-mm-yyyy hh24:mi:ss'));

prompt Done.

3、导出整个表

右击表,点导出数据(或者单击工具--导出表)

选择第二个“SQL插入”,注意要选上:创建表,否者导出的.sql文件没有表结构,无法使用下一步中的“导入表”方法导入。

 

导出的.sql文件 

prompt PL/SQL Developer import file
prompt Created on 2017年5月3日 by Administrator
set feedback off
set define off
prompt Creating IGIS_LOCATION_COPY...
create table IGIS_LOCATION_COPY
(
  devicecode VARCHAR2(50) not null,
  type       VARCHAR2(10) not null,
  longitude  NUMBER(10,2) not null,
  latitude   NUMBER(10,2) not null,
  datetime   DATE not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt Disabling triggers for IGIS_LOCATION_COPY...
alter table IGIS_LOCATION_COPY disable all triggers;
prompt Deleting IGIS_LOCATION_COPY...
delete from IGIS_LOCATION_COPY;
commit;
prompt Loading IGIS_LOCATION_COPY...
insert into IGIS_LOCATION_COPY (devicecode, type, longitude, latitude, datetime)
values ('001FF92FABE165', 'man', 121.12, 31.12, to_date('26-04-2017 14:29:05', 'dd-mm-yyyy hh24:mi:ss'));
insert into IGIS_LOCATION_COPY (devicecode, type, longitude, latitude, datetime)
values ('004999010640000', 'man', 121.12, 31.12, to_date('26-04-2017 14:29:05', 'dd-mm-yyyy hh24:mi:ss'));
insert into IGIS_LOCATION_COPY (devicecode, type, longitude, latitude, datetime)
values ('012963007793321', 'man', 121.12, 31.12, to_date('26-04-2017 14:29:05', 'dd-mm-yyyy hh24:mi:ss'));
insert into IGIS_LOCATION_COPY (devicecode, type, longitude, latitude, datetime)
values ('013437006991011', 'man', 121.12, 31.12, to_date('26-04-2017 14:29:05', 'dd-mm-yyyy hh24:mi:ss'));
insert into IGIS_LOCATION_COPY (devicecode, type, longitude, latitude, datetime)
values ('013789000795180', 'man', 121.12, 31.12, to_date('26-04-2017 14:29:05', 'dd-mm-yyyy hh24:mi:ss'));
insert into IGIS_LOCATION_COPY (devicecode, type, longitude, latitude, datetime)
values ('014583569411', 'car', 121.12, 31.12, to_date('26-04-2017 14:29:05', 'dd-mm-yyyy hh24:mi:ss'));
insert into IGIS_LOCATION_COPY (devicecode, type, longitude, latitude, datetime)
values ('049955', 'man', 121.12, 31.12, to_date('26-04-2017 14:29:05', 'dd-mm-yyyy hh24:mi:ss'));
insert into IGIS_LOCATION_COPY (devicecode, type, longitude, latitude, datetime)
values ('050846', 'man', 121.12, 31.12, to_date('26-04-2017 14:29:05', 'dd-mm-yyyy hh24:mi:ss'));
insert into IGIS_LOCATION_COPY (devicecode, type, longitude, latitude, datetime)
values ('050853', 'man', 121.12, 31.12, to_date('26-04-2017 14:29:05', 'dd-mm-yyyy hh24:mi:ss'));
insert into IGIS_LOCATION_COPY (devicecode, type, longitude, latitude, datetime)
values ('050859', 'man', 121.12, 31.12, to_date('26-04-2017 14:29:05', 'dd-mm-yyyy hh24:mi:ss'));
commit;
prompt 10 records loaded
prompt Enabling triggers for IGIS_LOCATION_COPY...
alter table IGIS_LOCATION_COPY enable all triggers;
set feedback on
set define on
prompt Done.

 

4、导入整张表

单击 “工具”--“导入表”

SQL*Plus就是上一篇博文中介绍的下载了sqlplus,如果安装的时候没下载,参考上篇

http://www.cnblogs.com/lelehellow/p/6801800.html

 

5、导出表结构

单击 “工具”--“导出用户对象”

记得选中表

使用上一步中的“导入表”方法来导入这个.sql文件可以导入一张空表,表结构还是跟这张表一样的。

打开导出的用户对象 .sql文件,发现其实就是导出了创建表的sql语句。

----------------------------------------------------
-- Export file for user SYSTEM                    --
-- Created by Administrator on 2017-5-3, 13:09:02 --
----------------------------------------------------

set define off
spool guanxi.log

prompt
prompt Creating table IGIS_LOCATION_COPY
prompt =================================
prompt
create table SYSTEM.IGIS_LOCATION_COPY
(
  devicecode VARCHAR2(50) not null,
  type       VARCHAR2(10) not null,
  longitude  NUMBER(10,2) not null,
  latitude   NUMBER(10,2) not null,
  datetime   DATE not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

spool off

6、使用“导入表”功能来导入第二步中导出的前5行数据

使用“导入表”功能来导入第二步中导出的前5行数据(.sql文件),发现导入无效。而第三步和第五步中同样是.sql文件,使用“导入表”功能都可以导入。

对边上面的.sql文件发现,其原因在于第二步中导出的.sql文件中没有定义表结构,也就是没有创建表。将其中的insert语句复制到第五步中的表结构sql文件中,就可以实现导入表了。

这样导入的表也就是只有原表中前5行数据的表了。

处理后的.sql文件如下:

----------------------------------------------------
-- Export file for user SYSTEM                    --
-- Created by Administrator on 2017-5-3, 13:09:02 --
----------------------------------------------------

set define off
spool guanxi.log

prompt
prompt Creating table IGIS_LOCATION_COPY
prompt =================================
prompt
create table SYSTEM.IGIS_LOCATION_COPY
(
  devicecode VARCHAR2(50) not null,
  type       VARCHAR2(10) not null,
  longitude  NUMBER(10,2) not null,
  latitude   NUMBER(10,2) not null,
  datetime   DATE not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

insert into IGIS_LOCATION_COPY (DEVICECODE, TYPE, LONGITUDE, LATITUDE, DATETIME)
values ('001FF92FABE165', 'man', 121.12, 31.12, to_date('26-04-2017 14:29:05', 'dd-mm-yyyy hh24:mi:ss'));

insert into IGIS_LOCATION_COPY (DEVICECODE, TYPE, LONGITUDE, LATITUDE, DATETIME)
values ('004999010640000', 'man', 121.12, 31.12, to_date('26-04-2017 14:29:05', 'dd-mm-yyyy hh24:mi:ss'));

insert into IGIS_LOCATION_COPY (DEVICECODE, TYPE, LONGITUDE, LATITUDE, DATETIME)
values ('012963007793321', 'man', 121.12, 31.12, to_date('26-04-2017 14:29:05', 'dd-mm-yyyy hh24:mi:ss'));

insert into IGIS_LOCATION_COPY (DEVICECODE, TYPE, LONGITUDE, LATITUDE, DATETIME)
values ('013437006991011', 'man', 121.12, 31.12, to_date('26-04-2017 14:29:05', 'dd-mm-yyyy hh24:mi:ss'));

insert into IGIS_LOCATION_COPY (DEVICECODE, TYPE, LONGITUDE, LATITUDE, DATETIME)
values ('013789000795180', 'man', 121.12, 31.12, to_date('26-04-2017 14:29:05', 'dd-mm-yyyy hh24:mi:ss'));

spool off

7、注意:假如发现自己使用plsql导出的表无法导入,极可能是因为在导出表的时候没有选上“创建表”这一项。上一步中的介绍可猜测,在导出前5行数据的时候,默认的没有创建表。

 

 

挂两个外链,管理员请不要删我文,如违规可联系我自行修改删除,QQ:919497132

苏州空调维修 苏州冰箱维修

posted @ 2017-05-03 15:15  总要有点追求吧  阅读(94136)  评论(0编辑  收藏  举报