Click here to Skip to main content
15,568,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So my procedure should add a row to the table INSÄTTNING. Some keys are reference keys. When the row has been inserted it should take P_BELOPP and subtract it with SALDO which is in another table called KONTO. The new amount should be added into that column and replace the old amount. I get that SALDO must be declared error. Would it even work as i intend? Hope its pretty understandable :)

What I have tried:

SQL
create or replace procedure do_insättning(
p_radnr in insättning.radnr%type,
p_pnr in insättning.pnr%type,
p_knr in insättning.knr%type,
p_belopp in insättning.belopp%type,
p_datum in insättning.datum%type) 
as 
begin 
insert into insättning(radnr,pnr,knr) 
values(select radnr from kontoägare,select pnr from bankkund, select knr from konto);
insert into insättning(belopp,datum)
values(p_belopp,p_datum);
update konto 
set konto.saldo = konto.saldo - p_belopp
where kontoägare.radnr = p_radnr; 
dbms_output.put_line('Saldo: '||''||saldo);
end;
Posted
Comments
CHill60 9-Feb-21 7:46am    
You are treating saldo as a variable when in fact it is a column on your table. Try something like (nb untested)
...set konto.saldo = konto.saldo - p_beloppwhere 
kontoägare.radnr = p_radnr; 
declare saldo number;saldo = (select kont.saldo from konto where kontoägare.radnr = p_radnr); 
dbms_output.put_line('Saldo: '||''||saldo);
Hugo Nilsson 9-Feb-21 9:06am    
I tried it and tried to modify it aswell without any luck :(
CHill60 9-Feb-21 9:14am    
Same error message? Even after declaring it?
Hugo Nilsson 9-Feb-21 9:33am    
No another error:
Line/Col: 13/7 PLS-00103: Encountered the symbol "=" when expecting one of the following: constant exception <an identifier="">

and

Line/Col: 13/52 PLS-00103: Encountered the symbol ";" when expecting one of the following:

) , and or
CHill60 9-Feb-21 12:40pm    
And what is in line 13 in your new query because in the code you have shared it says update konto - no '=' or ';'
I do notice in the code in the comment I posted two lines have merged into one - the declare saldo number; is meant to be on one line and then the saldo = ... etc on the next.
I may have the syntax for declaring the variable slightly wrong - check the documentation for your version of Oracle

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900