我编写了Python代码但是我收到了这个错误:
错误ORA-00917:缺少逗号
但是没有丢失的逗号;怎么了?
sTableName = "IRM_PREP_EPS_NRTRDEFLAT"
# build the SQL insert statement
sql_str = "INSERT INTO " + sTableName + " (ID,EPSDV_ERROR_FILE,EPSDV_ERROR_FILE_CREATION,EPSDV_RECORD_NUMBER,EPSDV_ERROR_CODE,EPSDV_ERROR_MESSAGE,"
sql_str = sql_str + "EPSDV_CURRENT_AREA,EPSDV_PREVIOUS_AREA,EPSDV_EQUIPMENT,EPSDV_PORTAL,EPSDV_PLAN,EPSDV_OPERATION,EPSDV_EXTERNAL_FILENAME,"
sql_str = sql_str + "EPSDV_LAST_MODIFIED_BY,EPSDV_LAST_MODIFIED_DATE,RECORD_TYPE,SPECIFICATION_VERSION_NUMBER,RELEASE_VERSION_NUMBER,SENDER,"
sql_str = sql_str + "RECIPIENT,SEQUENCE_NUMBER,FILE_AVAILABLE_TIMESTAMP,UTC_TIMEOFFSET_FAT,IMSI,IMEI,CALL_EVENT_START_TIMESTAMP,UTC_TIMEOFFSET_CET,"
sql_str = sql_str + "CALL_EVENT_DURATION,CAUSE_FOR_TERMINATION,TELE_SERVICE_CODE,BEARER_SERVICE_CODE,SUPPLEMENTARY_SERVICE_CODE,DIALLED_DIGITS,"
sql_str = sql_str + "CONNECTED_NUMBER,THIRD_PARTY_NUMBER,CALLING_NUMBER,RECENTITY_ID,CALL_REFERENCE,ACCESS_POINT_NAME_NI,ACCESS_POINT_NAME_OI,"
sql_str = sql_str + "DATA_VOLUME_INCOMING,DATA_VOLUME_OUTGOING,SGSN_ADDRESS,GGSN_ADDRESS,CHARGING_ID,CHARGE_AMOUNT,SERVING_NETWORK,MSISDN,"
sql_str = sql_str + "LOCATION_AREA,CELL_ID,FILLER) VALUES ("
sql_str = sql_str + ID + ',' + EPSDV_ERROR_FILE + ',' + EPSDV_ERROR_FILE_CREATION + ',' + EPSDV_RECORD_NUMBER + ',' + EPSDV_ERROR_CODE + ',' + EPSDV_ERROR_MESSAGE
sql_str = sql_str + ',' + EPSDV_CURRENT_AREA + ',' + EPSDV_PREVIOUS_AREA + ',' + EPSDV_EQUIPMENT + ',' + EPSDV_PORTAL + ',' + EPSDV_PLAN + ','
sql_str = sql_str + EPSDV_OPERATION + ',' + EPSDV_EXTERNAL_FILENAME + ',' + EPSDV_LAST_MODIFIED_BY + ',' + EPSDV_LAST_MODIFIED_DATE + ','
sql_str = sql_str + RECORD_TYPE + ',' + SPECIFICATION_VERSION_NUMBER + ',' + RELEASE_VERSION_NUMBER + ',' + SENDER + ',' + RECIPIENT + ','
sql_str = sql_str + SEQUENCE_NUMBER + ',' + FILE_AVAILABLE_TIMESTAMP + ',' + UTC_TIMEOFFSET_FAT + ',' + IMSI + ',' + IMEI + ','
sql_str = sql_str + CALL_EVENT_START_TIMESTAMP + ',' + UTC_TIMEOFFSET_CET + ',' + CALL_EVENT_DURATION + ',' + CAUSE_FOR_TERMINATION + ','
sql_str = sql_str + TELE_SERVICE_CODE + ',' + BEARER_SERVICE_CODE + ',' + SUPPLEMENTARY_SERVICE_CODE + ',' + DIALLED_DIGITS + ',' + CONNECTED_NUMBER
sql_str = sql_str + ',' + THIRD_PARTY_NUMBER + ',' + CALLING_NUMBER + ',' + RECENTITY_ID + ',' + CALL_REFERENCE + ',' + ACCESS_POINT_NAME_NI
sql_str = sql_str + ',' + ACCESS_POINT_NAME_OI + ',' + DATA_VOLUME_INCOMING + ',' + DATA_VOLUME_OUTGOING + ',' + SGSN_ADDRESS + ','
sql_str = sql_str + GGSN_ADDRESS + ',' + CHARGING_ID + ',' + CHARGE_AMOUNT + ',' + SERVING_NETWORK + ',' + MSISDN + ',' + LOCATION_AREA + ','
sql_str = sql_str + CELL_ID + ',' + FILLER + ')'
答案 0 :(得分:0)
我不知道您的错误位置,可能是由多种原因引起的,例如,如果您的字符串未包含在'
引号中。将变量传递给sql是一种非常错误的方法。
在绑定变量使用方面(oracle SQL最佳实践的基石)可能更强大和正确的是将您的语句编写为(不测试它):
sTableName = 'IRM_PREP_EPS_NRTRDEFLAT'
fields_str = ("ID,EPSDV_ERROR_FILE,EPSDV_ERROR_FILE_CREATION,EPSDV_RECORD_NUMBER,"
"EPSDV_ERROR_CODE,EPSDV_ERROR_MESSAGE,EPSDV_CURRENT_AREA,"
"EPSDV_PREVIOUS_AREA,EPSDV_EQUIPMENT,EPSDV_PORTAL,EPSDV_PLAN,"
"EPSDV_OPERATION,EPSDV_EXTERNAL_FILENAME,EPSDV_LAST_MODIFIED_BY,"
"EPSDV_LAST_MODIFIED_DATE,RECORD_TYPE,SPECIFICATION_VERSION_NUMBER,"
"RELEASE_VERSION_NUMBER,SENDER,RECIPIENT,SEQUENCE_NUMBER,"
"FILE_AVAILABLE_TIMESTAMP,UTC_TIMEOFFSET_FAT,IMSI,IMEI,"
"CALL_EVENT_START_TIMESTAMP,UTC_TIMEOFFSET_CET,CALL_EVENT_DURATION,"
"CAUSE_FOR_TERMINATION,TELE_SERVICE_CODE,BEARER_SERVICE_CODE,"
"SUPPLEMENTARY_SERVICE_CODE,DIALLED_DIGITS,CONNECTED_NUMBER,"
"THIRD_PARTY_NUMBER,CALLING_NUMBER,RECENTITY_ID,CALL_REFERENCE,"
"ACCESS_POINT_NAME_NI,ACCESS_POINT_NAME_OI,DATA_VOLUME_INCOMING,"
"DATA_VOLUME_OUTGOING,SGSN_ADDRESS,GGSN_ADDRESS,CHARGING_ID,"
"CHARGE_AMOUNT,SERVING_NETWORK,MSISDN,LOCATION_AREA,CELL_ID,FILLER")
fields = fields_str.split(',')
vars = ','.join(map(':{}'.format, fields)))
sql = 'INSERT INTO {} ({}) VALUES({})'.format(sTableName,
fields_str, vars)
values = {f: locals()[f] for f in fields}
cur.execute(sql, values)