python调用sqlplus执行_如何在python3.4中运行sqlplus查询

我是python新手,我正在尝试如何连接到远程oracledb并使用python脚本运行select查询。以下是我要达到的目标:1) Connect to oracle db and run select query

2) Write the result to the file.

这是我使用的常规连接字符串:

^{pr2}$

不太清楚如何在python3.4中实现,在2.7mysqldb模块/库中使用。在**Here is my blueprint:**

#!/bin/python

import sqlite3

import sys

import os

config = {

'user': 'user',

'password': '*****',

'host': '127.0.0.1',

'database': 'test',

'raise_on_warnings': True,

}

conn = sqlite3.connect('config') # not sure how to pass user and password

c = conn.cursor()

c.execute('select * from employees where employ_id=12')

2)而且我不知道如何在文件中写入它,我的第一个猜测是使用stdin和stdout进行操作,我相信有一种更有效的方法可以做到这一点。在orig_stdout = sys.stdout

out = open("/output.txt", 'w')

sys.stdout = out

c.execute('select * from employees where employ_id=12')

sys.stdout = orig_stdout

out.close()

有人能就更好的解决办法提出建议吗?在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值