PriyalChaudhari
PriyalChaudhari

Reputation: 383

Loading CSV file contents to oracle using cx_Oracle and getting Select keyword error

I am trying to load a csv file into an Oracle table and I am getting this error:

DatabaseError: ORA-00928: missing SELECT keyword

Below is the code I am using:

def Create_list():
reader = csv.reader(open("Query_result_combined.csv","r"))
lines=[]
for line in reader:
    lines.append(line)
print(lines[:1])
print(lines[:2])
return lines

def Insert_data():
db_user = "XXXXXXX"  # replace this with correct user name
db_password = "********"  # Set the environment variable DB_PASSWORD
db_connection_name = "***********"# repalce this with correct database name
#db_driver = "oracle.jdbc.OracleDriver","C:/Oracle/32bitclient/product/11.2.0/client_1/jdbc/lib/ojdbc6.jar"
print("Connecting Now!!")
con = cx_Oracle.connect(db_user,db_password,db_connection_name)
print("Connected to Oracle!!")
lines=Create_list()
#print lines
cur=con.cursor()
print("Inserting data")
cur.executemany("INSERT INTO BRIODB.A608232_QUERY_RESULT ('InteractionId','QueryId','Score','StartOffsetInMs','EndOffsetInMs','SpeakerRole','QueryIdentity','SpeakerId') VALUES(:1,:2,:3,:4,:5,:6,:7,:8)",lines)
con.commit ()
cur.close()
print("completed")

If I print lines[:1] and lines[:2] this is the output I get:

[['InteractionId', 'QueryId', 'Score', 'StartOffsetInMs', 'EndOffsetInMs', 
'SpeakerRole', 'QueryIdentity', 'SpeakerId']]
[['InteractionId', 'QueryId', 'Score', 'StartOffsetInMs', 'EndOffsetInMs', 
'SpeakerRole', 'QueryIdentity', 'SpeakerId'], ['34118470', '27', '45.63345', 
'89900', '90980', 'U', 'e54fd492-8877-4534-997b-9dbe9a8fbd74', '']]
Inserting data

I couldn't resolve the problem.

Upvotes: 0

Views: 585

Answers (1)

Jeff Holt
Jeff Holt

Reputation: 3190

If the table has uppercase column names, then remove the ' surrounding the column names in the insert statement's column list. If the case of the column names in the insert statement matches those found in the table, then replace ' with ". The latter is how you reference a column with special characters or when a column name is mixed case.

Upvotes: 1

Related Questions