用python查询SQL
我尝试使用python查询SQL,但它返回问号 这是我的密码用python查询SQL,python,sql,oracle,Python,Sql,Oracle,我尝试使用python查询SQL,但它返回问号 这是我的密码 import cx_Oracle import importlib class CustomDatabase(object): ROBOT_LIBRARY_SCOPE = 'GLOBAL' def __init__(self): """ Initializes _dbconnection to None. """ self._dbconnection
import cx_Oracle
import importlib
class CustomDatabase(object):
ROBOT_LIBRARY_SCOPE = 'GLOBAL'
def __init__(self):
"""
Initializes _dbconnection to None.
"""
self._dbconnection = None
self.db_api_module_name = None
def GetDataFromDatabaseByRow(self, db_connect_string, selectStatement, row):
db_api_2 = importlib.import_module("cx_Oracle")
db_connect_string = 'db_api_2.connect(%s)' % db_connect_string
self.db_api_module_name = "cx_Oracle"
self._dbconnection = eval(db_connect_string)
row = int(row)
cur = None
try:
cur = self._dbconnection.cursor()
cur.execute(selectStatement)
res = cur.fetchone()
i = 0
while (i < row):
if cur.rowcount == row:
data = res
res = cur.fetchone()
i = i + 1
if i == row:
for x in data:
result=x
#return result.decode('iso-8859-11')
return result
finally :
if cur :
self._dbconnection.rollback()
Obj=CustomDatabase()
A=Obj.GetDataFromDatabaseByRow("'BELL', 'BELL#', '192.168.1.10:110/BELL'","select book_name from book where id='100'",1)
print A
这是以DB为单位的值
OOP แม่เจ้า
我希望期望值为OOPแม่เจ้า代码>(泰语)
您能帮助我吗?例如,在启动Python之前设置OracleNLS\u LANG
环境变量
export NLS_LANG=.AL32UTF8
(是的,在“=”之后有一个句号)
关于全球化的Oracle文档是
[更新]@anthony tuininga,您只需执行以下操作:
导入cx\u Oracle
conn=cx\u Oracle.connect(connectString,encoding=“UTF-8”,nencoding=“UTF-8”)
在本例中,不需要使用NLS_LANG
。如果您不使用NCHAR数据,则可以省略nencoding
选项。如果您将此选项“从id='100'的书中选择书名”
修改为“从id=100的书中选择书名”
,您需要修复编码。
export NLS_LANG=.AL32UTF8