最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于python連接oracle導(dǎo)并出數(shù)據(jù)文件

 更新時(shí)間:2020年04月28日 09:45:15   作者:道法自然﹑  
這篇文章主要介紹了基于python連接oracle導(dǎo)并出數(shù)據(jù)文件,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

python連接oracle,感覺table_list文件內(nèi)的表名,來卸載數(shù)據(jù)文件

主腳本:

import os
import logging
import sys
import configparser
import subprocess
import cx_Oracle

#判斷輸入?yún)?shù)個(gè)數(shù)
class param():
  def check_para(self):
    if len(sys.argv) != 1:
       print("請(qǐng)輸入正確的參數(shù):yyyymmdd")
       exit(1)
    else:
      print("繼續(xù)執(zhí)行")

#根據(jù)配置文件獲取登錄信息
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("沒有那個(gè)配置文件")
      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)
          
#導(dǎo)出表數(shù)據(jù)
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("開始導(dǎo)出數(shù)據(jù): 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配置文件內(nèi)容:

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

運(yùn)行結(jié)果:

[oracle@master2 tmp]$ python3 c.py
繼續(xù)執(zhí)行
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 - 開始導(dǎo)出數(shù)據(jù): 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 - 開始導(dǎo)出數(shù)據(jù): 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 - 開始導(dǎo)出數(shù)據(jù): 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 - 開始導(dǎo)出數(shù)據(jù): 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 - 開始導(dǎo)出數(shù)據(jù): 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 - 開始導(dǎo)出數(shù)據(jù): 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 - 開始導(dǎo)出數(shù)據(jù): 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 - 開始導(dǎo)出數(shù)據(jù): 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 - 開始導(dǎo)出數(shù)據(jù): 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 - 開始導(dǎo)出數(shù)據(jù): 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

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • python高效的素?cái)?shù)判斷算法

    python高效的素?cái)?shù)判斷算法

    這篇文章主要介紹了python高效的素?cái)?shù)判斷算法,研究算法的同學(xué)一定要看一下
    2021-04-04
  • python Dejavu庫(kù)快速識(shí)別音頻指紋實(shí)例探究

    python Dejavu庫(kù)快速識(shí)別音頻指紋實(shí)例探究

    這篇文章主要為大家介紹了python Dejavu庫(kù)快速識(shí)別音頻指紋實(shí)例探究,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2024-01-01
  • Python內(nèi)置函數(shù) next的具體使用方法

    Python內(nèi)置函數(shù) next的具體使用方法

    這篇文章主要介紹了Python內(nèi)置函數(shù) next的具體使用方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-11-11
  • python使用calendar輸出指定年份全年日歷的方法

    python使用calendar輸出指定年份全年日歷的方法

    這篇文章主要介紹了python使用calendar輸出指定年份全年日歷的方法,涉及Python使用calendar模塊操作日期的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-04-04
  • Python + selenium + crontab實(shí)現(xiàn)每日定時(shí)自動(dòng)打卡功能

    Python + selenium + crontab實(shí)現(xiàn)每日定時(shí)自動(dòng)打卡功能

    這篇文章主要介紹了Python + selenium + crontab實(shí)現(xiàn)每日定時(shí)自動(dòng)打卡功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-03-03
  • python辦公自動(dòng)化之excel的操作

    python辦公自動(dòng)化之excel的操作

    在我們?nèi)粘9ぷ髦?,?jīng)常會(huì)使用 Word、Excel、PPT、PDF 等辦公軟件但是,經(jīng)常會(huì)遇到一些重復(fù)繁瑣的事情,這時(shí)候手工操作顯得效率極其低下;通過 Python 實(shí)現(xiàn)辦公自動(dòng)化變的很有必要
    2021-05-05
  • Python基于pillow庫(kù)實(shí)現(xiàn)生成圖片水印

    Python基于pillow庫(kù)實(shí)現(xiàn)生成圖片水印

    這篇文章主要介紹了Python基于pillow庫(kù)實(shí)現(xiàn)生成圖片水印,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-09-09
  • Python Selenium庫(kù)的基本使用教程

    Python Selenium庫(kù)的基本使用教程

    這篇文章主要給大家介紹了關(guān)于Python Selenium庫(kù)的基本使用教程,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • 記錄Python腳本的運(yùn)行日志的方法

    記錄Python腳本的運(yùn)行日志的方法

    這篇文章主要介紹了記錄Python腳本的運(yùn)行日志的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • TensorFlow和Numpy矩陣操作中axis理解及axis=-1的解釋

    TensorFlow和Numpy矩陣操作中axis理解及axis=-1的解釋

    在調(diào)用numpy庫(kù)中的concatenate()時(shí),有遇到axis=-1/1/0的情況,下面這篇文章主要給大家介紹了關(guān)于TensorFlow和Numpy矩陣操作中axis理解及axis=-1解釋的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-03-03

最新評(píng)論

红安县| 乐亭县| 福鼎市| 沧州市| 治县。| 佛山市| 张家川| 玉山县| 双辽市| 久治县| 徐州市| 瑞昌市| 鲁山县| 麻江县| 祁门县| 自贡市| 南充市| 和静县| 杭州市| 平遥县| 基隆市| 陵水| 奉贤区| 陆河县| 郸城县| 祥云县| 赤城县| 东兰县| 阳原县| 石泉县| 洪湖市| 绥阳县| 宜宾市| 伊金霍洛旗| 大关县| 佛山市| 汽车| 江孜县| 石阡县| 邮箱| 富源县|