读取oracle注释
生活随笔
收集整理的這篇文章主要介紹了
读取oracle注释
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
#?coding=utf-8 __author__?=?'jspdba' u''' 讀取oracle注釋 ''' import?cx_Oracle????#?導(dǎo)入模塊SQL=r""" select?*?from?user_col_comments?t?where?1=1 and?t.comments?is?not?null and?t.table_name?=?'@TABLE' """ words=["custom","code","trans","mode","date","confirm","balance","amount","after","type","area","game","flow","is","big","win","status","flag","num","client","reward","id","before","sum","check","time","name","channel","father","content","open","bet","cash","pay","open"] def?conn():db?=?cx_Oracle.connect('username',?'password',?'192.168.1.101:1521/orcl')????#建立連接,3個(gè)參數(shù)分開(kāi)寫(xiě)print?db.versionreturn?db#?美化 def?prettify(str=None):global?wordsif?str!=None?and?len(str)>0:for?word?in?words:str?=?str.replace(word,word.capitalize())return?str[0].lower()+str[1:]def?run(table=None,db=None):if?table!=None:global?SQLtable?=?table.upper()SQL?=?SQL.replace("@TABLE",table)try:if?db==None:db?=?conn()tableComment(table,db=db,closeDb=False)cursor?=?db.cursor()????#建立一個(gè)cursorcursor.execute(SQL)????#?執(zhí)行一條sql#?row=cursor.fetchone()?#取一行結(jié)果,元組(a,b,c,d)row=cursor.fetchall()?#獲取所有結(jié)果,列表[(a,b,c,d),(e,f,g,h),...]print?'=='*100for?x?in?row:print?prettify(x[1].lower())+"\t"*4+x[2]#?cursor.rowcount()?#獲取輸出記錄數(shù)量print?'=='*100except?Exception,e:print?efinally:cursor.close()db.close()#?sql?=?"insert?into?person(name,?age,?telephone)?values(%s,?%s,?%s)"#?tmp?=?(('ninini',?89,?'888999'),?('koko',?900,?'999999'))#?conn.executemany(sql,?tmp)?#執(zhí)行多條sql """ 打印表注釋 """ def?tableComment(tableName=None,sql="select?*?from?user_tab_comments",db=None,closeDb=True):if?not?tableName==None:sql="select?*?from?user_tab_comments?where?TABLE_NAME='%s'"?%(tableName.upper())try:if?db==None:db?=?conn()cursor?=?db.cursor()????#建立一個(gè)cursorcursor.execute(sql)????#?執(zhí)行一條sqlrow=cursor.fetchone()if?row:print?prettify(row[0].lower())+"\t"*4+row[2]?if?row[2]!=None?else?''except?Exception?,?e:print?efinally:cursor.close()if?closeDb:db.close()#?打印單張表注釋及字段注釋 run("saleDetail") #?打印單張表注釋 #?tableComment("saleDetail") #?打印所有表注釋(無(wú)字段注釋) #?tableComment()轉(zhuǎn)載于:https://my.oschina.net/chworld/blog/516195
總結(jié)
以上是生活随笔為你收集整理的读取oracle注释的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Spring Task配置
- 下一篇: Zabbix 集成 OneAlert 实