Click here to Skip to main content
15,038,643 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
Jörgen Andersson 10-Feb-21 3:55am
   
When you set a variable you need to use :=
Earlier versions of Oracle's PL/SQL language were based on the Ada language syntax and structure.
Hugo Nilsson 10-Feb-21 5:26am
   
I tried that and it still dont work
Gerry Schmitz 9-Feb-21 13:33pm
   
One typically doesn't store "derived" values in a database; one calculates them at run / report time. Imagine a transaction error (without a rollback): all your "numbers" are now out of sync.
Hugo Nilsson 10-Feb-21 6:16am
   
I hear you sir but this is a school task so we are just training :)
Gerry Schmitz 10-Feb-21 10:21am
   
One can learn to do it right in the first place. Or not ... and blame it on "schooling".
Hugo Nilsson 10-Feb-21 11:49am
   
I really thought this forum was serious. Turns out it wasn't. You haven't been trying to help you've just been rude

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

  Print Answers RSS
Top Experts
Last 24hrsThis month



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