Sei sulla pagina 1di 2

A procedure is a collection of SQL and procedural statements that perform a specific task and are

assigned a unique name within the schema and stored in the database.


There are two kinds of procedures:
Anonymous: These procedures do not have a name assigned to them. It is complied each time when the
user submits its source code to the database server.
Stored : Unlike anonymous, stored procedures have a unique name assigned to them and are stored in
the compiled form in the database.
NOTE: Only Stored procedures can accept parameters and does not use the DECLARE BLOCK.


Procedure SyntaxSYNTAX:
CREATE [/REPLACE] PROCEDURE procedure_name [(parameter datatype),...]
[LANGUAGE { ADA|C|.|SQL}
ASStatement 1;
..
Procedure body.
SQL/PLSQL statements
.
.
END;
To execute the procedure:
EXEC procedure_name;









Procedure Example
CREATE OR REPLACE PROCEDURE InfoTable_proc
AS
counter number;
c_name varchar2(15);
BEGIN
DBMS_OUTPUT.PUT_LINE('in order');
counter :=10;
loop
select name into c_name FROM ConTable where ID=counter;
DBMS_OUTPUT.PUT_LINE(c);
EXIT WHEN counter<1;
END LOOP;
end;

Potrebbero piacerti anche