Reputation: 10943
I am creating Stored Procedure in Oracle and one of them is created permanently and another one is temporarily created and vanished after serving its purpose.How it is working please give your guidance when to use and how it is created.
---- This is not created in DB, just temporarily created and vanished
DECLARE name varchar2(10);
PROCEDURE printVal (name varchar2) IS
BEGIN
dbms_output.put_line ('name:' || name);
END;
BEGIN
name := 'Joe';
printVal(name);
END;
/
---- This is created in DB and permanently available
create PROCEDURE printVal (name varchar2) IS
BEGIN
dbms_output.put_line ('name:' || name);
END;
Upvotes: 2
Views: 2289
Reputation: 2338
To understand, Dividing your sql in two parts.
Stored Procedure:
Anonymous Block:
---------- Stored Procedure Start--------
DECLARE name varchar2(10);
PROCEDURE printVal (name varchar2) IS
BEGIN
dbms_output.put_line ('name:' || name);
END;
--------- Stored Procedure End-----------
----------anonymous block Start----------
BEGIN
name := 'Joe';
printVal(name);
END;
/
----------anonymous block end ------------
Upvotes: 4
Reputation: 52356
Well, clearly there is different syntax -- the first one is an anonymous block, and the second creates a stored procedure. The expected behaviour is exactly what you observe, and covered by Oracle PL/SQL documentation. https://docs.oracle.com/cloud/latest/db112/LNPLS/overview.htm#LNPLS141
Upvotes: 3