python連接oracle進行取數查詢

#coding:utf-8
import cx_Oracle                                               
conn=cx_Oracle.connect('username/passwod@IP:1521/myorcl')   
 


lookfor_ip='''select * from ip_scan  
  order by to_number(substr(ip_add, instr(ip_add, '.', 1, 1) + 1, instr(ip_add, '.', 1, 2) - instr(ip_add, '.', 1, 1))),
  to_number(substr(ip_add, instr(ip_add, '.', 1, 2) + 1, instr(ip_add, '.', 1, 3) - instr(ip_add, '.', 1, 2))),
  to_number(substr(ip_add, instr(ip_add, '.', 1, 3) + 1))'''
x=conn.cursor().execute(lookfor_ip)

counts=0
for l in x:
    print l
    if counts>20:
        break
    counts+=1

                                                    
conn.close()                                               

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章