Reputation: 19
https://i.sstatic.net/M4oUC.jpg - Picture
I'm trying to calculate the current product stock. I have product_reception table in which I can calculate my stock. And sales (vanzari) table.
Upvotes: 0
Views: 34
Reputation: 143088
Posting code as an image is usually a bad idea.
Anyway: quite a few objections:
cod_pds in number
but par_cod_pds in number
is
and begin
. Don't use var
(key)word. It is a good idea to name them so that the name reflects the fact that these are local variables, such as l_stoc_pds number
exec
within a PL/SQL procedure, especially not to run a select
statement. exec
is used in SQL*Plus to run a PL/SQL procedure, such as exec calculstoclazi
select into
a variable preceded by a colon, but simply name the variableselect
statements are exactly the same; I have no idea what you meant to do by doing that. Besides, you preceded cod_pds
with stoc_pds
which is a variable name (so that's totally wrong); if a column name is to be preceded by something, that's table name (or its alias)Therefore, code that might look like something valid is this; obviously, the result will be 0 (zero). As I told you, those two selects
are exactly the same.
create or replace procedure calculstoclazi
(par_cod_pds in number,
par_rezultat out number
)
is
l_stocs_pds number;
l_total_vanzare number;
begin
select sum(cantitate)
into l_stoc_pds
from receptie_marfa
where cod_pds = par_cod_pds;
select sum(cantitate)
into l_total_vanzare
from receptie_marfa
where cod_pds = par_cod_pds;
par_rezultat := l_stoc_pds - l_total_vanzare;
end;
Upvotes: 2