import cx_Oracle import os if False: #当Oracle服务是手动运行时,将False改为True os.system('net start OracleVssWriterORCL') os.system('net start OracleDBConsoleorcl') os.system('net start OracleOraDb11g_home1TNSListener') os.system('net start OracleServiceORCL') orcl = cx_Oracle.connect('system/username@localhost:1521/orcl'.decode('utf8')) cur = orcl.cursor() sql = '''select * from test1 ''' cur.execute(sql.decode('utf8')) records = cur.fetchall() lines = len(records) for i in range(lines): print records[i] cur.close()