我有张桌子:
create table employee (
employee_id NUMBER NOT NULL,
name VARCHAR2(255) NOT NULL,
notes VARCHAR2(4000),
created_by varchar2(255) not null,
created_at date default sysdate not null,
updated_by varchar2(255) not null,
updated_at date default sysdate not null,
PRIMARY KEY(vendor_id)
);
因此,当我插入时:
insert into employee(employee_id, name,notes) values(1,'xyz','test');
它自动填充create_by、created_at、updated_at和updated_by。
成功插入行。
然而,如果我尝试在python中使用cx_Oracle模块插入,
cursor.execute("INSERT INTO employee VALUES (:employee_id,:name,:notes)",
{
'employee_id' : max_value,
'name' : each_vendor,
'notes' : 'test'
}
)
它会抛出错误,说值不够。
为什么我会有这个错误?我该怎么解决呢?
发布于 2015-12-23 13:02:39
答案非常简单,与python无关。您的2个insert
语句非常不同。
在第一节中,您显式地命名了要为:(employee_id, name,notes)
提供值的列。但是,在Python使用的insert
语句中,没有按名称指定3列。因此,insert
语句要求您为表中的所有列提供值。
修复:显式命名这3列:
cursor.execute("INSERT INTO employee (employee_id, name, notes) VALUES (:employee_id,:name,:notes)",
{
'employee_id' : max_value,
'name' : each_vendor,
'notes' : 'test'
}
)
https://stackoverflow.com/questions/34394092
复制相似问题