简体   繁体   中英

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.

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:

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 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.


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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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