python连接oracle,感觉table_list文件内的表名,来卸载数据文件
主脚本:
import os import logging import sys import configparser import subprocess import cx_Oracle #判断输入参数个数 class param(): def check_para(self): if len(sys.argv) != 1: print("请输入正确的参数:yyyymmdd") exit(1) else: print("继续执行") #根据配置文件获取登录信息 class get_dbini(): def get_db(self): config=configparser.ConfigParser() filepath="db.ini" if os.path.exists(filepath): config.read_file(open(filepath)) dbinfo=[config.get("db_oracle","username"), config.get("db_oracle","password"), config.get("db_oracle","ip"), config.get("db_oracle","dbsid")] else: loginfo.info("没有那个配置文件") sys.exit(4) #声明使用全局变量 global username,password,ip,dbsid username=dbinfo[0] password=dbinfo[1] ip=dbinfo[2] dbsid=dbinfo[3] loginfo.info(username+password+ip+dbsid) #导出表数据 class exp_date(): def exp_table(self): with open('table_list','r') as f: list = f.readlines() for i in list: tablename = i.rstrip('\n') exportquery='sqluldr2 user='+username+'/'+password+'@'+ip+':1521/'+dbsid+' query="select * from '+tablename+';" head=no file='+tablename+'.dat field=0x03 record=0x030x0a safe=yes' loginfo.info("开始导出数据: exportquery= "+exportquery) flag= subprocess.check_call(exportquery,shell=True) loginfo.info(flag) #打印日志 class log_set(): def logger_set(self): logger=logging.getLogger('mylogger') logger.setLevel(logging.DEBUG) fh=logging.FileHandler('a.log','w') fh.setLevel(logging.INFO) ch=logging.StreamHandler() ch.setLevel(logging.ERROR) formatter = logging.Formatter('%(asctime)s -%(name)s -%(levelname)s - %(message)s') fh.setFormatter(formatter) ch.setFormatter(formatter) logger.addHandler(fh) logger.addHandler(ch) return logger if __name__=='__main__': loginfo=log_set().logger_set() param().check_para() get_dbini().get_db() exp_date().exp_table()
DB配置文件内容:
db.ini
[db_oracle]
username=c##scott
password=tiger
ip=192.168.1.250
dbsid=orcl
表名字的配置文件:
table_list
BONUS
DEPT
EMP
LEAD_TABLE
SALGRADE
T1
TB_USER
TEST
XGJ
XGJ_2
运行结果:
[oracle@master2 tmp]$ python3 c.py
继续执行
0 rows exported at 2019-01-22 17:51:51, size 0 MB.
output file BONUS.dat closed at 0 rows, size 0 MB.
0 rows exported at 2019-01-22 17:51:52, size 0 MB.
4 rows exported at 2019-01-22 17:51:52, size 0 MB.
output file DEPT.dat closed at 4 rows, size 0 MB.
0 rows exported at 2019-01-22 17:51:52, size 0 MB.
12 rows exported at 2019-01-22 17:51:52, size 0 MB.
output file EMP.dat closed at 12 rows, size 0 MB.
0 rows exported at 2019-01-22 17:51:52, size 0 MB.
10 rows exported at 2019-01-22 17:51:52, size 0 MB.
output file LEAD_TABLE.dat closed at 10 rows, size 0 MB.
0 rows exported at 2019-01-22 17:51:52, size 0 MB.
5 rows exported at 2019-01-22 17:51:52, size 0 MB.
output file SALGRADE.dat closed at 5 rows, size 0 MB.
0 rows exported at 2019-01-22 17:51:52, size 0 MB.
5 rows exported at 2019-01-22 17:51:52, size 0 MB.
output file T1.dat closed at 5 rows, size 0 MB.
0 rows exported at 2019-01-22 17:51:52, size 0 MB.
10 rows exported at 2019-01-22 17:51:52, size 0 MB.
output file TB_USER.dat closed at 10 rows, size 0 MB.
0 rows exported at 2019-01-22 17:51:52, size 0 MB.
8 rows exported at 2019-01-22 17:51:52, size 0 MB.
output file TEST.dat closed at 8 rows, size 0 MB.
0 rows exported at 2019-01-22 17:51:52, size 0 MB.
9 rows exported at 2019-01-22 17:51:52, size 0 MB.
output file XGJ.dat closed at 9 rows, size 0 MB.
0 rows exported at 2019-01-22 17:51:52, size 0 MB.
8 rows exported at 2019-01-22 17:51:52, size 0 MB.
output file XGJ_2.dat closed at 8 rows, size 0 MB.
查看日志:
[oracle@master2 tmp]$ more a.log
2019-01-22 17:51:51,858 -mylogger -INFO - c##scotttiger192.168.1.250orcl
2019-01-22 17:51:51,858 -mylogger -INFO - 开始导出数据: exportquery= sqluldr2 user=c##scott/tiger@192.168.1.250:1521/orcl query="select * from BONUS;" head=no file=BON
US.dat field=0x03 record=0x030x0a safe=yes
2019-01-22 17:51:51,949 -mylogger -INFO - 0
2019-01-22 17:51:51,949 -mylogger -INFO - 开始导出数据: exportquery= sqluldr2 user=c##scott/tiger@192.168.1.250:1521/orcl query="select * from DEPT;" head=no file=DEPT
.dat field=0x03 record=0x030x0a safe=yes
2019-01-22 17:51:52,038 -mylogger -INFO - 0
2019-01-22 17:51:52,038 -mylogger -INFO - 开始导出数据: exportquery= sqluldr2 user=c##scott/tiger@192.168.1.250:1521/orcl query="select * from EMP;" head=no file=EMP.d
at field=0x03 record=0x030x0a safe=yes
2019-01-22 17:51:52,129 -mylogger -INFO - 0
2019-01-22 17:51:52,129 -mylogger -INFO - 开始导出数据: exportquery= sqluldr2 user=c##scott/tiger@192.168.1.250:1521/orcl query="select * from LEAD_TABLE;" head=no fil
e=LEAD_TABLE.dat field=0x03 record=0x030x0a safe=yes
2019-01-22 17:51:52,299 -mylogger -INFO - 0
2019-01-22 17:51:52,300 -mylogger -INFO - 开始导出数据: exportquery= sqluldr2 user=c##scott/tiger@192.168.1.250:1521/orcl query="select * from SALGRADE;" head=no file=
SALGRADE.dat field=0x03 record=0x030x0a safe=yes
2019-01-22 17:51:52,401 -mylogger -INFO - 0
2019-01-22 17:51:52,402 -mylogger -INFO - 开始导出数据: exportquery= sqluldr2 user=c##scott/tiger@192.168.1.250:1521/orcl query="select * from T1;" head=no file=T1.dat
field=0x03 record=0x030x0a safe=yes
2019-01-22 17:51:52,490 -mylogger -INFO - 0
2019-01-22 17:51:52,490 -mylogger -INFO - 开始导出数据: exportquery= sqluldr2 user=c##scott/tiger@192.168.1.250:1521/orcl query="select * from TB_USER;" head=no file=T
B_USER.dat field=0x03 record=0x030x0a safe=yes
2019-01-22 17:51:52,578 -mylogger -INFO - 0
2019-01-22 17:51:52,578 -mylogger -INFO - 开始导出数据: exportquery= sqluldr2 user=c##scott/tiger@192.168.1.250:1521/orcl query="select * from TEST;" head=no file=TEST
.dat field=0x03 record=0x030x0a safe=yes
2019-01-22 17:51:52,665 -mylogger -INFO - 0
2019-01-22 17:51:52,665 -mylogger -INFO - 开始导出数据: exportquery= sqluldr2 user=c##scott/tiger@192.168.1.250:1521/orcl query="select * from XGJ;" head=no file=XGJ.d
at field=0x03 record=0x030x0a safe=yes
2019-01-22 17:51:52,771 -mylogger -INFO - 0
2019-01-22 17:51:52,771 -mylogger -INFO - 开始导出数据: exportquery= sqluldr2 user=c##scott/tiger@192.168.1.250:1521/orcl query="select * from XGJ_2;" head=no file=XGJ
_2.dat field=0x03 record=0x030x0a safe=yes
2019-01-22 17:51:52,856 -mylogger -INFO - 0
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
- 群星.2003-存为爱2CD【环球】【WAV+CUE】
- 韩磊《试音天碟》高清音频[WAV+CUE]
- 邓涛《寂寞蒲公英(黑胶CD)》[WAV]
- 江志丰.2011-爱你的理由【豪记】【WAV+CUE
- 群星《传承-太平洋影音45周年纪念版 (CD2)》[320K/MP3][140.01MB]
- 群星《传承-太平洋影音45周年纪念版 (CD2)》[FLAC/分轨][293.29MB]
- 首首经典《滚石红人堂I 一人一首成名曲 4CD》[WAV+CUE][2.5G]
- s14上单t0梯度怎么排名 s14世界赛上单t0梯度排行榜
- tes目前进了几次s赛 LPL队伍tes参加全球总决赛次数总览
- 英雄联盟巅峰礼赠什么时候开始 2024巅峰礼赠活动时间介绍
- 冯骥发文谈睡觉重要性 网友打趣:求求你先做DLC
- 博主惊叹《少女前线2》万圣节大雷皮肤:这真能过审吗?
- 《生化危机8》夫人比基尼Mod再引骂战:夸张身材有错吗?
- 江蕙.1994-悲情歌声【点将】【WAV+CUE】
- 戴娆.2006-绽放【易柏文化】【WAV+CUE】