我想用下面的代碼插入CLOB。使用cx_Oracle插入CLOB
cursor = connection.cursor()
cursor.setinputsizes(HERP = cx_Oracle.CLOB)
cursor.execute("INSERT INTO myTable (FOO, BAR) VALUES (:FOO, :BAR)", FOO=val1, BAR=val2)
cursor.execute("INSERT INTO myTable2 (HERP) VALUES (:HERP)", HERP=val3)
#len(HERP) 39097
當我運行腳本,而不cursor.setinputsizes(HERP = cx_Oracle.CLOB)
失敗與ValueError: string data too large
第二個查詢,當我cursor.setinputsizes(HERP = cx_Oracle.CLOB)
運行該腳本失敗與DatabaseError: ORA-01036: illegal variable name/number
第一個查詢。我試圖插入的CLOB包含一個代碼片段(即它有很多分號,逗號和括號),"string".decode("ascii")
返回u'string'
,所以unicode不是問題...對不對?我不知道這些事情是否有問題。數據庫中的字段是當前的CLOB,但是我用NCLOB嘗試過,行爲沒有改變。
我也嘗試過該字段作爲BLOB,然後在我插入的值上使用.encode("hex")
,再次使用相同的行爲。
我也試過HERP = cursor.var(cx_Oracle.CLOB)
而不是cursor.setinputsizes(HERP = cx_Oracle.CLOB)
,同樣的問題。
我一直在討論cx-oracle-users列表,但沒有運氣呢。
它適用於如果我使用這一行cursor.execute("INSERT INTO myTable2 (HERP) VALUES (:HERP)", HERP="".join(set(val3)).encode("hex"))
,所以我不認爲這是數據的內容(這是BLOB)的問題。
如何使用cx_Oracle
將CLOB插入到Oracle數據庫中?