oracle错误:没有足够的值

时间:2012-10-19 08:57:11

标签: sql oracle

我有一张表donor_master:

create table donor_master  
(  
donor_id number(10) primary key not null,  
dob date not null,  
age number(3) not null,  
gender char(1) not null,  
blood_group char(3),  
contact_no number(10),  
address varchar(50) not null,  
city varchar(10) not null,  
pin number(10) not null,  
state varchar(10) not null,  
branch_registration_id number(5) references branch_master(branch_id)  
);  

当我尝试在程序insert_donor_master中插入表时,我在编译时得到“没有足够的值”错误。

这是程序:

create or replace procedure insert_donor_master(  
vdob donor_master.dob%type,  
vage donor_master.age%type,  
vgender donor_master.gender%type,  
vblood_group donor_master.blood_group%type,  
vcontact_no donor_master.contact_no%type,  
vaddress donor_master.address%type,  
vcity donor_master.city%type,  
vpin donor_master.pin%type,  
vstate donor_master.state%type,  
vbranch_registration_id donor_master.branch_registration_id%type  
)  
is  

begin  

    insert into donor_master values (sq_donor_master.nextval, vdob, vage, vgender, vblood_group, vcontact_no, vaddress, vcity, vpin, vstate, vbranch_registration_id);  
    commit;  

end;

有什么问题?

感谢。

1 个答案:

答案 0 :(得分:3)

当我们指定INSERT语句时,Oracle会抛出ORA-00947,该语句没有表中每列的值。

现在,您发布的CREATE TABLE语句显示了一个包含11列的表。您发布的存储过程代码在VALUES(...)子句中显示带有11个值的insert语句。

所以,解释是:

  1. 您遇到配置管理问题,并且您运行的是存储过程的错误版本或表的错误版本
  2. 您遇到配置管理问题,表的实际结构与您的想法不符(与您的CREATE TABLE脚本不匹配)
  3. 你没有真正得到ORA-00947错误
  4. 请注意,如果您不想填充每一行,可以在VALUES子句之前指定相关列的投影。例如,如果您只想填充必填列,则可以对此进行编码:

    insert into  donor_master 
        (donor_id, dob, age, gender, address, city, pin, state )
       values (sq_donor_master.nextval, vdob, vage, vgender, vaddress, vcity, vpin, vstate) 
    

    重要的是值的数量与列数相匹配。

    INSERT语句的完整语法在文档中。 enter link description here了解更多信息。

相关问题