欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

读取oracle注释

发布时间:2025/5/22 编程问答 29 豆豆
生活随笔 收集整理的这篇文章主要介绍了 读取oracle注释 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

2019独角兽企业重金招聘Python工程师标准>>>

# coding=utf-8 __author__ = 'jspdba' u''' 读取oracle注释 ''' import cx_Oracle    # 导入模块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个参数分开写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()    #建立一个cursorcursor.execute(SQL)    # 执行一条sql# row=cursor.fetchone() #取一行结果,元组(a,b,c,d)row=cursor.fetchall() #获取所有结果,列表[(a,b,c,d),(e,f,g,h),...]print '=='*100for x in row:print prettify(x[1].lower())+"\t"*4+x[2]# cursor.rowcount() #获取输出记录数量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) #执行多条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()    #建立一个cursorcursor.execute(sql)    # 执行一条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") # 打印所有表注释(无字段注释) # tableComment()


转载于:https://my.oschina.net/chworld/blog/516195

总结

以上是生活随笔为你收集整理的读取oracle注释的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。