都取oracle注释i
发布时间:2020-12-17 17:24:27 所属栏目:Python 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 # coding=utf-8__author__ = 'jspdba'u'''读取oracle注释'''import cx_Oracle # 导入模块SQL=r"""select * from user_col_comments t where 1=1and t.
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考 # 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.version return db # 美化 def prettify(str=None): global words if 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 SQL table = table.upper() SQL = SQL.replace("@TABLE",table) try: if db==None: db = conn() tableComment(table,db=db,closeDb=False) cursor = db.cursor() #建立一个cursor cursor.execute(SQL) # 执行一条sql # row=cursor.fetchone() #取一行结果,元组(a,b,c,d) row=cursor.fetchall() #获取所有结果,列表[(a,d),(e,f,g,h),...] print '=='*100 for x in row: print prettify(x[1].lower())+"t"*4+x[2] # cursor.rowcount() #获取输出记录数量 print '=='*100 except Exception,e: print e finally: 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() #建立一个cursor cursor.execute(sql) # 执行一条sql row=cursor.fetchone() if row: print prettify(row[0].lower())+"t"*4+row[2] if row[2]!=None else '' except Exception,e: print e finally: cursor.close() if closeDb: db.close() # 打印单张表注释及字段注释 run("saleDetail") # 打印单张表注释 # tableComment("saleDetail") # 打印所有表注释(无字段注释) # tableComment() 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |