简体   繁体   English

执行过程时参数数量或类型错误

[英]Wrong number or types of arguments when executing a procedure

Hope someone can help me, I've been getting this error but I'm not sure what I'm doing wrong.希望有人可以帮助我,我一直收到此错误,但我不确定我做错了什么。 I created this procedure that inserts the following information into a 'deposit' table for a bank: sequence number, personal number, account number, amount of deposit, and date).我创建了这个过程,将以下信息插入到银行的“存款”表中:序列号、个人编号、帐号、存款金额和日期)。 The procedure is also supposed to print out the total balance after the new deposit.该程序还应该在新存款后打印出总余额。

create or replace procedure do_insättning (
p_radnr kontoägare.radnr NUMBER(9),
p_pnr  bankkund.pnr VARCHAR(11), 
p_knr  konto.knr NUMBER(8), 
p_belopp  insättning.belopp NUMBER(10,2),
p_datum insättning.datum DATE,
p_saldo konto.saldo NUMBER(10,2))
is
begin
insert into kontoägare(radnr)
values(p_radnr);
insert into bankkund (pnr)
values(p_pnr);
insert into konto(knr)
values(p_knr);
insert into insättning(belopp)
values(p_belopp);
insert into insättning(datum)
values(sysdate);
insert into konto(saldo)
values(p_saldo);
commit;

dbms_output.put_line('Saldot är nu = ' || p_belopp + p_saldo);
end;
/

When I execute it this way, I get a wrong number of arguments error:当我以这种方式执行它时,我收到错误数量的参数错误:

EXECUTE do_insättning (radnr_seq.NEXTVAL, '540126-1111', 123, 200, sysdate);

I created this procedure that inserts the following information into a 'deposit' table for a bank我创建了这个程序,将以下信息插入到银行的“存款”表中

No, it does not insert the data into one table;不,它不会将数据插入到一张表中; it inserts it into four different tables ( kontoägare , bankkund , konto and insättning ) and creates 2 rows in each of the konto and insättning tables.它将它插入到四个不同的表( kontoägarebankkundkontoinsättning )中,并在kontoinsättning表中的每一个中创建 2 行。

Your query is effectively:您的查询有效:

create procedure do_insättning (
  p_radnr  kontoägare.radnr%TYPE,
  p_pnr    bankkund.pnr%TYPE, 
  p_knr    konto.knr%TYPE, 
  p_belopp insättning.belopp%TYPE,
  p_saldo  konto.saldo%TYPE
)
is
begin
  insert into kontoägare(radnr) values (p_radnr);
  insert into bankkund (pnr) values(p_pnr);
  insert into konto(knr, saldo) values(p_knr, NULL);
  insert into konto(knr, saldo) values(NULL, p_saldo);
  insert into insättning(belopp, datum) values(p_belopp, NULL);
  insert into insättning(belopp, datum) values(NULL, SYSDATE);
  COMMIT;
  dbms_output.put_line('Saldot är nu = ' || p_belopp + p_saldo);
end;
/

If you want to insert a single row into a single table (called deposits ) then you want just a single INSERT statement:如果您想在单个表中插入一行(称为deposits ),那么您只需要一个INSERT语句:

create procedure do_insättning (
  p_radnr  kontoägare.radnr%TYPE,
  p_pnr    bankkund.pnr%TYPE, 
  p_knr    konto.knr%TYPE, 
  p_belopp insättning.belopp%TYPE,
  p_saldo  konto.saldo%TYPE
)
is
begin
  insert into deposits(
    radnr,   pnr,   knr,   saldo,   belopp,   datum
  ) values (
    p_radnr, p_pnr, p_knr, p_saldo, p_belopp, SYSDATE
  );

  dbms_output.put_line('Saldot är nu = ' || p_belopp + p_saldo);
end;
/

Then you can call it using:然后你可以使用以下方法调用它:

EXECUTE do_insättning(
  p_radnr  => radnr_seq.NEXTVAL,
  p_pnr    => '540126-1111',
  p_knr    => 123,
  p_belopp => 200,
  p_saldo  => 42
);
COMMIT;

Note: don't put COMMIT statements in procedures ;注意: 不要在过程中放置COMMIT语句 COMMIT in the transaction that calls the procedure as that lets you chain multiple procedures together in a single transaction and apply a ROLLBACK statement to them all as a group.在调用过程的事务中COMMIT允许您将多个过程链接到一个事务中,并将ROLLBACK语句作为一个组应用于它们。


When I execute it this way, I get a wrong number of arguments error:当我以这种方式执行它时,我收到错误数量的参数错误:

 EXECUTE do_insättning (radnr_seq.NEXTVAL, '540126-1111', 123, 200, sysdate);

That is because your procedure takes 6 arguments and you have only provided 5.那是因为您的过程需要 6 个参数,而您只提供了 5 个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM