2012-09-26 5 views
0

cx_oracle을 사용하여 Python에서 Oracle에 액세스하려고합니다.oracle 오류 코드 처리 cx_oracle

행을 반환하지 않는 select 문이 있습니다. 즉; NO_DATA_FOUND .. 그리고 이것은 오류 상태를 처리하는 방법입니다.

나는이 코드 조각을 실행하면 오류 NO_DATA_FOUND가 cx_oracle.error 또는 cx_oracle.Databaseerror 또는 cx_oracle.Warning에 의해 사로 잡았되지 ..

은 어떻게 NO_DATA_FOUND 조건을 처리하나요?

code.py

이것은 당신의 예외 중 어느 것도 트리거되지되고있는 이유는 아마도 오류 조건이 아닌
def DetermineNames(self): 
    sql = """select NAME from EMP_TAB where fd_fle_id = %s"""%(self.fileid) 
    try: 
     self.cursor.execute(sql) 
     result = self.cursor.fetchall() 
     for row in result: 
       print('row',row) 
    except cx_Oracle.Error as e: 
     print("Error:Unable to determine the RAW_OBJ_NAME: Object Name:%s, Function Name:%s Error:%s")%(self.__class__.__name__,sys._getframe().f_code.co_name, 
     str(e).strip())       
    except cx_Oracle.DatabaseError as e: 
     print("Error:Unable to determine the RAW_OBJ_NAME: Object Name:%s, Function Name:%s Error:%s")%(self.__class__.__name__,sys._getframe().f_code.co_name, 
     str(e).strip()) 
    except cx_Oracle.Warning as e: 
     print("Error:Unable to determine the RAW_OBJ_NAME: Object Name:%s, Function Name:%s Error:%s")%(self.__class__.__name__,sys._getframe().f_code.co_name, 
     str(e).strip())      
    return self.rawname  

답변

2

. 대신이 같은 것을보십시오 :

if not self.cursor.rowcount: 
    print 'No rows returned' 
+0

감사합니다 ... 각 SQL 문을 실행 한 후 오류 코드를 확인 할 수있는 방법은 객체가 아니라 실제 코드가 나는 인쇄 - cx_Oracle._Error.code..It 때? ... – user1050619

1

사용 cx_Oracle._Error.code 될 수 있으며 값은 자사의 NO DATA FOUND1403 인 경우.

.... 
except cx_Oracle.DatabaseError as e: 
    error, = e.args 
    if error.code == 1403: 
     print "No rows returned. Error Code:", error.code 
.... 
+0

나를 보여줍니다. – user1050619

+0

업데이트 된 답변 확인 – Annjawn

+0

NO DATA FOUND는 오류로 처리되지 않습니다. – user1050619