oracle 用表的字段注释,给视图的字段添加注释

from u_工具 import *


oracle_conf = {
    "host": "192.168.1.102",
    "port": 1521,
    "user": "c##admin",
    "password": "admin",
    "db": "orcl"
}
dal = oracle(oracle_conf)

表名 = "student"
视图名 = "view_student"
用户名 = "admin"


sql = f'''
    select t.column_name, t.comments
    from all_col_comments t
    where
        t.owner = upper('{用户名}')
        and t.table_name = upper('{表名}')
'''
lines = dal.exec(sql).lines
原始列名_list = stream(lines).map(lambda i: i["COLUMN_NAME"]).collect()
注释列名_list = stream(lines).map(lambda i: i["COMMENTS"]).collect()

for (原始列名, 注释列名) in zip(原始列名_list, 注释列名_list):
    sql = f'''
        comment on column {视图名}.{原始列名} is '{注释列名}'
    '''
    dal.exec(sql)
dal.commit()

-- u_工具:https://github.com/hl-mio/u_util/tree/main/python3

猜你喜欢

转载自blog.csdn.net/u013595395/article/details/114382793