最近项目上线,python连接数据库部分出现很多问题,总结一下
错误一:python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX
cx_Oracle.connenct()的参数中设置参数encoding = 'utf8',问题完美解决
错误二:oracle DatabaseError:DPI-1054:connection cannot be closed when open statement or LOBs exist
原因是这个字段是JSON格式
json.load(xxx.read()) 读取之后转换成字典,就可以根据key来获取value
错误三:ORA-01036: illegal variable name/number
cursor.prepare("INSERT INTO python_modules(module_name, file_path) VALUES (:1, :2)")
原因是VALUES括号的冒号缺少导致
错误四:ORA-00933: SQL 命令未正确结束 / ORA-00933: SQL command not properly ended
查了其他的博客大多是因为sql语句后有分号导致的,我是因为想把程序开始执行的时间写入到数据的starttime字 段,将拼接的SQL语句打印出来 UPDATE tablea SET starttime = 2018-10-21 17:31:51 where ID = '34rh3gj2grjdj'
那问题就清楚了,时间应该是字符串,拼接的时候应该加上引号。
错误五:ORA-01502:index or partition of such index is in unusable
折腾了我一天的问题,这个可能是数据库在迁移过程中造成index unusable,rebuild一下index即可解决
错误六:“ ORA-00001: unique constraint”
主键冲突