如何使用 PL/SQL 中的过程在 table 中插入多个值?

How to insert multiple values in table using procedure in PL/SQL?

在 运行 上,我将以下代码作为输出:

OUTPUT:- ORA-00001: unique constraint (KART.SYS_C007206) violated

我想我是在数据库中一次插入一批值。也许这就是它不起作用的原因。

      <!--  declare
      Enter_the_size_of_array int;
      id int;
      name varchar(30);
      age int
      c int;


      procedure s(a in out int , b in out varchar2,c in out int) is 
                begin 
                insert into table1 values(a,b,c);
                end;

      begin
      c:=1;
      Enter_the_size_of_array:= :Enter_the_size_of_array;


      loop 
                id:= :id;
                name:= :name;
                age:= :age;
                s(id,name,age);
                c:=c+1;
      exit when (c=Enter_the_size_of_array);
      end loop;

      end;
      / -->

Kumar,看起来在循环的每次迭代中,ID(以及所有其他值)都保持不变。您很可能对一个或多个列有约束(例如 ID 上的主键),而您只是试图一遍又一遍地插入相同的值。

假设 ID 是唯一的关键字段。每次您为 ID 输入相同的值时。它抛出唯一键约束异常。