I am trying to create an Oracle table using Python 3.5. I have the column names and data type stored in a dictionary, and I want to create an SQL statement (stored in sql_stmt
) to execute it from Python. My dictionary looks like this:
adict1 = {'col1': 'Number', 'col2': 'Date', 'col3': 'Date'}
I am trying to create an SQL statement which looks like this:
create table dummy(col1 Number, col2 Date, col3 Date)
So, I was trying to create the SQL statement by looping through the dictionary keys:
sql_stmt = "create table"
for key in adict1 :
sql_stmt = sql_stmt + ("dummy('%s' , '%s')" ,(key,adict1[key]))
But it throws the error:
Traceback (most recent call last):
File "<pyshell#413>", line 2, in <module>
sql_stmt = sql_stmt + ("dumm5('%s' , '%s')" ,(key,adict1[key]))
TypeError: must be str, not tuple
What have I done wrong?