python-3.x - 如何在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()
解决方案
推荐阅读
- javascript - jQuery/Javascript/Ajax 可以将自己的会话 cookie 与浏览器 cookie 分开管理吗?
- flutter - longPress 减量超过 0
- regex - sed 中的正则表达式
- gradle - 带有重复文件的 Gradle Copy 任务问题
- python-3.x - 如何在 O(1) 时间复杂度中删除第 k 个元素
- scala - 增量表插入无法正常工作,使用 - org.apache.spark.sql.AnalysisException 读取错误:表不支持读取
- mysql - 如何使用动态 SQL (MySQL) 将查询结果存储到局部变量中?
- python - 为什么我的 API 模拟补丁不适用于 Python?
- angular - Angular slickgrid 多选编辑器字段需要在按下确定按钮时移除焦点而不更改数据
- python - python请求:为每个请求全局添加http标头