#!/usr/bin/env python
# -*- coding: utf-8 -*-
import cx_Oracle
from pprint import pprint
import csv
import time
import re
import binascii
conn = cx_Oracle.connect('system/oracle@192.168.137.2/serv')
cursor = conn.cursor()
table_name="t300"
owner="system"
xsql='select process,sid from t300'
col=[]
r = cursor.execute(xsql)
for col in r:
#print col[0].decode('gbk')
if col[0].decode('gbk')==u'测试环境':
print col[0].decode('gbk')
print 1111
C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/oracle/t1.py
测试环境
1111
Process finished with exit code 0
widnows 环境:
>>> a='测试环境'
>>> a
'\xb2\xe2\xca\xd4\xbb\xb7\xbe\xb3'
>>> print a
测试环境
>>> print len(a)
8
>>>
>>> print '\xb2\xe2\xca\xd4\xbb\xb7\xbe\xb3'.decode('gbk')
测试环境
>>> b=u'测试环境'
>>> b
u'\u6d4b\u8bd5\u73af\u5883'
>>> print b
测试环境
>>> print len(b)
4
>>> print u'\u6d4b\u8bd5\u73af\u5883'.encode('gbk')
测试环境