2017-05-09 8 views
3

비슷한 질문을하기 전에 질문했지만 아직 해결 방법을 찾을 수 없었습니다. 내 코드 :cx_Oracle : 오류 933입니다. ORA-00933 : "SQL 명령이 제대로 종료되지 않았습니다.": SQL 명령 오류?

try: 
     connection = cx_Oracle.connect(ORACLE_CONNECT) 
     logger.info("Connection to Oracle success.") 
     print ("Oracle DB version: " + connection.version) 
     print ("Oracle client encoding: " + connection.encoding) 
     print ("Python version: " + platform.python_version()) 
    except cx_Oracle.DatabaseError as e: 
     error, = e.args 
     if error.code == 1017: 
      print ("Username/password invalid.") 
      logger.debug("Username/password invalid: %s", error.code) 
     else: 
      logger.debug("Database connection error: %s", e) 
      print ("Database connection error: %s".format(e)) 
     raise 

    cursor = connection.cursor() 
    smsreport_text_new = tuple(smsreport_text) 
    find_command = self.identify_unique_msgid(smsreport_list) 
    cursor.execute(find_command) 

def identify_unique_msgid(self, smsreport_list): 
    msgid_i_to_be_crosschecked = smsreport_list.get('msgid_i') 
    msgid_ii_to_be_crosschecked = smsreport_list.get('msgid_ii') 
    find_command = 'SELECT * FROM myTable WHERE msgid_i = {0}'.format(msgid_i_to_be_crosschecked) 
    print (find_command) 

    return find_command 

find_command은 다음과 같습니다

SELECT * FROM myTable WHERE msgid_i = 2R67C865FB6ZHG5A9 

나는 함께하고 SQL 쿼리의 끝에 세미콜론없이 시도했지만 계속 실패했습니다. 내가 다른 쿼리 (아래 참조) 및이 테이블에 데이터를 씁니다 때문에 연결 작동하는지 알 수 있습니다. 이 오류 메시지는 특정 값을 포함하는 행을 찾으려고 할 때 발생합니다.

insert into xura_push (date_sms, result_sms, msgid, msgparts, msgid_i, msgid_ii) values (TO_DATE(:1, 'dd-mon-yyyy hh24:mi:ss'), :2, :3, :4, :5, :6) 

어디로 잘못 가고 있습니까?

건배, pymat. 위의 설명에서 언급 한 바와 같이

+1

를 사용하여 매개 변수를 설정합니다. 더 실제적으로 문자열 상수에 대해서는 작은 따옴표가 필요합니다. –

+0

@GordonLinoff 당신은 find_command가 위의 삽입 명령과 유사해야한다는 것을 의미합니까? – pymat

+0

이것을 사용할 수 있습니다. SELECT * FROM myTable WHERE msgid_i = \ '{0} \' "'많이 신경 쓸 필요는 없지만 매개 변수화 된 쿼리를 사용해야합니다. –

답변

1

은 다음과 같이 매개 변수를 사용하는 대신 문자열에 값을 직접 퍼팅의

def identify_unique_msgid(self, smsreport_list): 
    msgid_i_to_be_crosschecked = smsreport_list.get('msgid_i') 
    msgid_ii_to_be_crosschecked = smsreport_list.get('msgid_ii') 
    find_command = 'SELECT * FROM myTable WHERE msgid_i = :msgid' 
    return find_command, dict(msgid = msgid_i_to_be_crosschecked) 

cursor = connection.cursor() 
smsreport_text_new = tuple(smsreport_text) 
find_command, args = self.identify_unique_msgid(smsreport_list) 
cursor.execute(find_command, args) 
+0

내가 찾고있는 것이 었습니다. – pymat

+0

반갑습니다. 대답을 받아 들일 수 있다고 표시 할 수 있습니까? 감사! –