# !/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()
xsql='select * from tlcb_mon_device'
r = cursor.execute(xsql)
print r
arr=[]
for x in r:
print x
print x[0]
print len(x[0])
#print x[1]
print x[1].decode('gbk').encode('utf-8')
print len(x[1])
y=x[1].decode('gbk').encode('utf-8')
print len(y)
print type(x)
arr.append(x[0])
arr.append(y)
print '-------------------------------------------------------------------------------------------------'
print arr
print type(arr)
for x in arr:
print x
C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/Django/a21.py
<cx_Oracle.Cursor on <cx_Oracle.Connection to system@192.168.137.2/serv>>
('192.168.137.3', '\xb2\xe2\xca\xd4\xd6\xf7\xbb\xfa')
192.168.137.3
13
測試主機
8
12
<type 'tuple'>
('192.168.137.4', '\xc9\xfa\xb2\xfa\xd6\xf7\xbb\xfa')
192.168.137.4
13
生產主機
8
12
<type 'tuple'>
-------------------------------------------------------------------------------------------------
['192.168.137.3', '\xe6\xb5\x8b\xe8\xaf\x95\xe4\xb8\xbb\xe6\x9c\xba', '192.168.137.4', '\xe7\x94\x9f\xe4\xba\xa7\xe4\xb8\xbb\xe6\x9c\xba']
<type 'list'>
192.168.137.3
測試主機
192.168.137.4
生產主機
Process finished with exit code 0
python 顯示為\xe6\xb5\x8b\xe8\xaf\x95\xe4\xb8\xbb\xe6\x9c\xba,實際取出後正常。