加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

都取oracle注释i

发布时间:2020-05-24 23:47:11 所属栏目:Python 来源:互联网
导读:都取oracle注释i

下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。

脚本之家小编现在分享给大家,也给大家做个参考。

# 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()

以上是脚本之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读