Ошибка приходит отсюда:
cur.execute("INSERT INTO test(name,id) VALUES (%s,%d)", ('hello',30))
Попробуйте использовать :n
указатели:
cur.execute("INSERT INTO test(name, id) VALUES (:1, :2)", ('hello', 30))
update
Для вашего второго случая - еслиy
- это строка типа y = "100%"
, затем вы можете выполнить обновление следующим образом:
cur.execute("update temp set perc = :1", (y[:-1],))
Это вставит 100
как int
.
Обратите внимание, что кортеж размером 1 элементis (x,)
, not (x)
.
Код, который я использую
import cx_Oracle
con = cx_Oracle.connect('system/system@127.0.0.1:1521/xe')
# print(con.version)
#
# print("this connection is established")
cur = con.cursor()
f3 = open("common.txt", 'r+') #this text file have only 2 words lets say (10% increased)
string = f3.read() #will read common.txt
common_words = string.split()
x = common_words[0] #here x have 10%
y = common_words[1] #here y have increased
# Now I want 10 should be updated in the temp table **Not 10%**
cur.execute("update temp set perc=(:1)", (y[:-1],))
cur.execute("update temp set remarks=(:1)", (y))
con.commit
Примечание: я должен извлечь это 10 и выполнить дальнейшие вычисления
Таблица Temp:
Замечания Perc
10 увеличено