sql - 甲骨文错误 : not enough values

标签 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;

问题是什么?

谢谢。

最佳答案

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

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

所以,解释如下:

  • 您遇到了配置管理问题,并且您正在运行错误版本的存储过程或错误版本的表
  • 你有一个配置管理问题,表的实际结构不是你想象的那样(与你的 CREATE TABLE 脚本不匹配)
  • 你并没有真正收到 ORA-00947 错误

  • 请注意,如果您不想填充每一行,您可以在 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了解更多。

    关于sql - 甲骨文错误 : not enough values,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12970724/

    相关文章:

    c# - Dapper 出现 postgresql 错误(序列包含多个元素)

    c# - DataTable 问题列的 ADO.Net DataType

    sql - 获取Oracle表的列名、数据类型、大小和注释

    linux - Oracle 11.2 在随机时间对简单 SQL 有 2 秒的延迟

    SQL Server Create Table 给出错误,对象 '' 已经存在,但它不存在

    C# SQL 命令参数不起作用

    oracle - 组合 Group BY 和每个结果的多个计数

    oracle - 如何使用 Oracle DBMS_LDAP 执行大型(大于 Sizelimit)LDAP 查询

    mysql - 不显示拥有多个实例的用户的平均值

    sql - 如何在 TYPE OBJECT 的 VARRAY 中正确插入?