oracle数据库批量插入数据,及pl/sql Developer、python连接教程 含源码 -- 数据库
2019-04-09 12:07
417 查看
版权声明:篇章限本人所有,转载请标明出处。 https://blog.csdn.net/qq_31779317/article/details/89139671
oracle数据库批量插入数据及python连接教程
一、oracle环境配置
https://www.2cto.com/database/201701/588135.html (转自jffhy2017的博客)
二、创建表
Keys
主键:唯一关键字(如:学生表中的学号)
外键:与其他表联系的字段(如除学生表外,还有一张选课表,若修改了学生表中的学号,选修表也需要变,则需要给选修表中的学号作为外键约束)
Indexes
唯一索引:在普通索引的基础上,增加唯一约束(即必须唯一值)(另:主键约束的列,会自动为该列创建唯一索引)
三、批量插入数据到表
根据如下几种命令方法在数据库表中插入数据:
- loop循环
declare x number; begin x := 0; loop x := x + 1; Exit when x>9; insert into HEYONGLIN select * from HEYONGLIN; end loop; end;
- for循环
declare x number; begin x := 0; For x in reverse 1..10 loop x := x + 1; insert into HEYONGLIN select * from HEYONGLIN; end loop; end;
- while循环
declare x number; begin x := 0; while x<10 loop x := x + 1; insert into HEYONGLIN select * from HEYONGLIN; end loop; end;
- goto循环
declare x number; begin x := 0; <<repeat_loop>> x := x + 1; insert into HEYONGLIN select * from HEYONGLIN; If x<9 then Goto repeat_loop end if; end;
- excel处理后复制粘贴
- 反复复制原数据
insert into tname select * from tname2 Insert into tname(a,b,c) select a,c,5 from tname2 #要求表tname必须存在 selcet * into tname from tname2 #要求表tname不存在
四、pl\sql Developer连接oracle数据库
本章使用oracle11g版本(python最低支持版本)
- 下载oracle数据库工具Instant Client,与pl\sql Developer(注:下载的版本需选择相应主机版本匹配如64位相应64位)
- Oracle数据库工具Instant Client官网下载地址:http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
下载后是压缩文件,解压后把instantclient_11_2放在指定目录,如:D:/instantclient_11_2 - pl\sql Developer官方下载地址:https://www.allroundautomations.com/bodyplsqldevreg.html
- 配置文件
在oracle路径中如x:\oracleapp\Administrator\product\11.2.0\dbhome_1\NETWORK\ADMIN\tnsnames.ora ,把配置好的tnsnames.ora文件复制放进instantclient_11_2文件夹中
附配置文件tnsnames.ora配置方法:
XE:数据库名称,随意起名
HOST:服务器ip
PORT:端口
SERVICE_NAME:服务器名称,随意起名
- plsql设置
打开plsql点Cancel进入主界面
在pl\sql中tools\perferences设置instantclient_11_2目录与oci.dll路径
重新登录连接即可。
五、python连接oracle数据库
import cx_Oracle # 建立连接 db = cx_Oracle.connect('STD2017/STD20171QAZ@218.16.100.87:8017/xe') # 数据库操作 cur = db.cursor() cur.execute('select * from hyl_table_a') result = cur.fetchall() # 关闭数据库 cur.close()
个人代码行已存储在github:https://github.com/onlyhyl/database/tree/master/oracle
相关文章推荐
- oracle 数据库的管理工具 PL/SQL_Developer 的简易使用 与Java 连接并查询显示出数据
- 本机重装数据库后pl/sql developer连接远程数据库报 ora-12368 无法验证身份的错误
- PL/SQL Developer 工具连接ORALCE数据库的方法
- PL/SQL Developer连接本地Oracle 11g 64位数据库
- 32位PL/SQL Developer连接64位oracle 11g数据库蛋疼的问题
- pl/sql developer等客户端本地连接Oracle数据库
- PL/SQL Developer连接本地Oracle 11g 64位数据库
- Oracle数据库的创建以及远程连接(PL/SQL Developer远程连接数据库)
- 本机不安装Oracle客户端,使用PL/SQL Developer连接远程数据库
- 使用instantclient_11_2和pl/sql Developer连接oracle远程数据库
- 本机不安装Oracle客户端就可使用PL/SQL Developer连接远程数据库
- PL/SQL Developer连接本地Oracle 11g 64位数据库(转)
- PL/SQL Developer 或Toad 不安装Oracle客户端连接数据库
- 本机不安装Oracle客户端,使用PL/SQL Developer连接远程数据库
- PL/SQL Developer快速连接数据库(不需要再在Oracle数据库安装文件下配置tnsnames.ora文件)
- pl/sql developer连接数据库
- PL/SQL Developer+Oracle 连接远端数据库
- PL/SQL Developer 如何连接远程 Oracle 数据库
- Oracle安装步骤及PL/SQL Developer连接数据库
- PL/SQL Developer连接本地Oracle 11g 64位数据库