日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

python如何操作oracle数据库_python操作oracle数据库

發(fā)布時(shí)間:2023/12/1 python 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python如何操作oracle数据库_python操作oracle数据库 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

搜索熱詞

下面是編程之家 jb51.cc 通過(guò)網(wǎng)絡(luò)收集整理的代碼片段。

編程之家小編現(xiàn)在分享給大家,也給大家做個(gè)參考。

# -*- mode: python; coding: utf-8 -*-

#

# python operate oracle,contain insert、delete、update、select.

#

# @author liyulin

# @date 2014-11-07

import cx_Oracle

class PythonOralceUtil:

def __enter__(self):

self.conn = cx_Oracle.connect('testuser/[email?protected]/CHROMEBOOK')

self.cursor = self.conn.cursor()

return self

def __exit__(self,type,value,traceback):

self.cursor.close()

self.conn.close()

############################################

# 查詢(xún)r(jià)eg_codes中的所有數(shù)據(jù)

############################################

def queryAll(self):

self.cursor.execute('select * from reg_codes')

results = self.cursor.fetchall()

for result in results:

print result

############################################

# 根據(jù)序號(hào)查詢(xún)r(jià)eg_codes中的一條數(shù)據(jù)

############################################

def queryBySeq(self,seq):

self.cursor.execute('select * from reg_codes where seq=:1',seq)

result = self.cursor.fetchone()

if (result is not None):

for index in range(0,6):

print result[index],############################################

# 向reg_codes中插入N條數(shù)據(jù)

############################################

def insertManay(self,insertValue):

self.conn.begin()

try:

self.cursor.executemany('insert into reg_codes(device,unique_code,group_code,input_file,sn,input_ts) values(:1,:2,:3,:4,:5,sysdate)',insertValue)

except AssertionError:

self.conn.rollback()

raise Warning,"invalid insertValue (%s)" % insertValue

self.conn.commit()

############################################

# 更新reg_codes中一條數(shù)據(jù)

############################################

def updateOne(self,sqe,input_file):

updateValue = [input_file,sqe]

self.cursor.execute('update reg_codes set input_file=:1 where seq=:2',updateValue)

############################################

# 更新reg_codes中N條數(shù)據(jù)

############################################

def updateManay(self,updateValues):

self.conn.begin()

try:

self.cursor.executemany('update reg_codes set input_file=:1 where seq=:2',updateValues)

except AssertionError:

self.conn.rollback()

raise Warning,"invalid insertValue (%s)" % updateValues

self.conn.commit()

############################################

# 刪除reg_codes中一條數(shù)據(jù)

############################################

def delete(self,sqe):

self.cursor.execute('delete from reg_codes where seq=:1',sqe)

############################################

# 刪除reg_codes中N條數(shù)據(jù)

############################################

def deleteManay(self,seqs):

self.conn.begin()

try:

self.cursor.executemany('delete from reg_codes where seq=:1',seqs)

except AssertionError:

self.conn.rollback()

raise Warning,"invalid seqs (%s)" % seqs

self.conn.commit()

############################################

# 執(zhí)行代碼

############################################

with PythonOralceUtil() as pythonOralceUtil:

# insertValue = [['jerry','unique_code2333','group_code2333','debug233','1111111111122'],# ['jerry','unique_code244','group_code244','debug244','22222222233'],'unique_code255','group_code255','debug255','33333333344'],'unique_code266','group_code266','debug266','44444444455'],'unique_code277','group_code277','debug277','55555555566']]

# pythonOralceUtil.insertManay(insertValue)

# pythonOralceUtil.updateOne('27','debug_updated')

# pythonOralceUtil.delete([27])

# pythonOralceUtil.deleteManay([[31],[44],[45]])

updateValues = [['debug_updated','46'],['debug_updated','47'],'48'],'34']]

pythonOralceUtil.updateManay(updateValues)

pythonOralceUtil.queryAll()

pythonOralceUtil.queryBySeq([27])

以上是編程之家(jb51.cc)為你收集整理的全部代碼內(nèi)容,希望文章能夠幫你解決所遇到的程序開(kāi)發(fā)問(wèn)題。

如果覺(jué)得編程之家網(wǎng)站內(nèi)容還不錯(cuò),歡迎將編程之家網(wǎng)站推薦給程序員好友。

相關(guān)文章

總結(jié)

如果覺(jué)得編程之家網(wǎng)站內(nèi)容還不錯(cuò),歡迎將編程之家網(wǎng)站推薦給程序員好友。

本圖文內(nèi)容來(lái)源于網(wǎng)友網(wǎng)絡(luò)收集整理提供,作為學(xué)習(xí)參考使用,版權(quán)屬于原作者。

如您喜歡交流學(xué)習(xí)經(jīng)驗(yàn),點(diǎn)擊鏈接加入交流1群:1065694478(已滿(mǎn))交流2群:163560250

總結(jié)

以上是生活随笔為你收集整理的python如何操作oracle数据库_python操作oracle数据库的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。