표시

2017-09-18 5 views
-1
count1= cur.rowcount 
print count1 
count=0 
for vari in cur: 
    print count 
    str=cur.fetchone() 
    #print str[0] 
    #print str[1] 
    #print str[2] 
    #print str[3] 
    #print str[4] 
    #print str[5] 
    if str[2]=='Extract': 
    word='This report '+' is about '+str[0] 
    else: 
    word='This '+ str[2] +' is about '+str[0] 
    count+=1 
print count 

인쇄는 테이블에 총 NOF 기록의 수를 보여줍니다 cur.rowcount를 사용하여 내 테이블의 레코드에는 총 없지만 언제 하나 기록을 인출 한 다음 내 카운트 변수를 증가시 이유는 무엇입니까?표시

답변

0

동시에 하나의 행을 가져 오는 중입니다. 두 가지 다른 방법을 사용하여 내부 커서 캐시를 사용하여 행을 이중 페치 할 수도 있습니다.

cur.fetchone() 호출을 제거

for row in cur: 
    if row[2]=='Extract': 
     word = 'This report is about ' + row[0] 
    else: 
     word = 'This '+ row[2] +' is about ' + row[0] 
    count+=1 

for row in cur: 루프는 행 하나 하나를 처리하는 데 필요한 모든 것입니다.