• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 932
  • Last Modified:

Meaning of "null" sentence in Procedure

I dont know whats the point with using a "null" sentence after an insert in the next given procedure, we use this at uni, but i can't understand whats the point with it, and what would it happen if i don't use it. is it actually necessary?
create or replace
PROCEDURE RELLENARCOMPRAS AS
 
cursor cursorVentas is select c1.dni, c1.nombre, c1.apellido,count(*) cuantos from ventas  v1, clientes  c1 
WHERE v1.dni = c1.dni group by c1.dni, c1.nombre, c1.apellido; --relacionamos la tabal de ventas con la de clientes
 
BEGIN
for i in  cursorVentas loop
insert into compras(dni, nombre, apellido, numcochescomprados) values(i.dni,i.nombre,i.apellido,i.cuantos);
null;
end loop;
commit;
END RELLENARCOMPRAS;

Open in new window

0
axtur
Asked:
axtur
  • 2
  • 2
2 Solutions
 
sdstuberCommented:
null;

is a "do nothing" statement.  it doesn't hurt or help your procedure.  it literally does nothing.

it's probably a remnant from early development.

a lot of procedures are stubbed in like

procedure my_proc
is
begin
null;
end;

that way it compiles and gives your app code something to invoke then you can fill in the working code later.
0
 
axturAuthor Commented:
I know it does nothing, but in don't know whats the utility of this sentence, why is it used, and what if i simply dont use it?
0
 
MilleniumaireCommented:
It looks completely redundant to me and I can't see any need for it so you would be okay to remove it.

Sometimes a null statement is used to improve the logic of if then else statements.
0
 
sdstuberCommented:
it has no utility at all in your procedure

It's used only to fill in places where you must have code to act as a placeholder.
Since you already have code it has no utility at all in your example.

begin  
end;  -- is illegal

begin
null;
end; -- ok

if 1=1 then
end if;  -- is illegal

if 1=1 then
 null;
end if;  -- ok


if 1=0 then
else
endif;  -- is illegal


if 1=0 then
   null;
else
  null;
endif;  -- ok
0
 
MilleniumaireCommented:
It is often used to act as a "do nothing" in "complex" (or at least, difficult to understand) if statements.  For example:

if prod_flag != 'Y' or prod_code != 'CX34' then
  process_product(prod_code);
end if;

People tend to struggle to understand boolean logic when it contains not equals and or's and this can lead to mistakes.  The above code could be simplified using:

if prod_flag = 'Y' and prod_code = 'CX34' then
  null;
else
  process_product(prod_code);
end if;
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now