oracle 错误:没有足够的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12970724/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:11:17  来源:igfitidea点击:

oracle error: not enough values

sqloracle

提问by Neal

i have a table donor_master:

我有一个表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)  
);  

when i try to insert into the table in a procedure insert_donor_master, i get "not enough values" error on compilation.

当我尝试在过程 insert_donor_master 中插入表时,在编译时出现“值不足”错误。

this is the procedure:

这是程序:

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;

What is the problem?

问题是什么?

Thanks.

谢谢。

采纳答案by APC

Oracle hurls ORA-00947 when we specify an INSERT statement which doesn't have a value for every column in the table.

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

Now, the CREATE TABLE statement you posted shows a table with eleven columns. And the stored procedure code you posted shows an insert statement with eleven values in the VALUES (...) clause.

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

So, the explanations are:

所以,解释如下:

  1. you have a configuration management issue, and you're running the wrong version of the stored procedure or the wrong version of the table
  2. you have a configuration management issue, and the actual structure of the table isn't what you think it is (doesn't match your CREATE TABLE script)
  3. you aren't really getting an ORA-00947 error
  1. 您有配置管理问题,并且您运行的是错误版本的存储过程或错误版本的表
  2. 你有一个配置管理问题,表的实际结构不是你认为的那样(与你的 CREATE TABLE 脚本不匹配)
  3. 你并没有真正收到 ORA-00947 错误

Note that if you don't want to populate every row you can specify a projection of the relevant columns before the VALUES clause. For instance, if you just wanted to populate the mandatory columns you would code this:

请注意,如果您不想填充每一行,您可以在 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) 

All that matters is that the number of values matches the number of columns.

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

The complete syntax for INSERT statements is in the documentation. enter link description hereFind out more.

INSERT 语句的完整语法在文档中。 在此处输入链接描述了解更多。