首页 > 解决方案 > 如何在python中使用cx_Oracle模块生成oracle sql语句的html报告?

问题描述

我有下面的python脚本dbreport.py,我使用cx_Oracle模块连接oracle db,它工作正常。现在我有一些sql语句,我想运行并将其输出生成到html报告中。提到一些部分python脚本。这里的问题是我想在下面的python脚本函数中添加下面的sql以生成html格式的输出。我不知道如何实现这一点。

######Sql语句生成html报告#######

SET MARKUP HTML ON SPOOL ON PREFORMAT OFF ENTMAP ON -
HEAD "<TITLE>EMPLOYEE REPORT</TITLE> -
<STYLE type='text/css'> -
<!-- BODY {background: #FFFFC6} --> -
</STYLE>" -
BODY "TEXT='#FF00Ff'" -
TABLE "WIDTH='90%' BORDER='5'"
spool report2.html
Select * from hr.departments where date = '{}'.format(dt_string)
spool off

#######dbreport.py 脚本##########################

import cx_Oracle

def main(env_name):
    try:
       now datetime.now()
       dt_string = now.strftime("%Y%m%d")
       connection = Connection("ABC_DEV_KK","username", "pass")
       cursor = connection.cursor()
       cursor.execute()---------------------I tried here but not succesfull
       res = cursor.fetchall()
       print(res)
    except Exception as e:
       logging.info(e)


if _name_ == '_main_':
    main()

标签: python-3.xoraclecx-oracle

解决方案


推荐阅读