What is a Stored Procedure?
A stored procedure or in simple a proc is a named PL/SQL block which performs one or more specific task. This is similar to a procedure in other programming languages.
A procedure has a header and a body. The header consists of the name of the procedure and the parameters or variables passed to the procedure. The body consists or declaration section, execution section and exception section similar to a general PL/SQL Block.
A procedure is similar to an anonymous PL/SQL Block but it is named for repeated usage.
We can pass parameters to procedures in three ways.
3) IN OUT-parameters
A procedure may or may not return any value.
General Syntax to create a procedure is:
IS - marks the beginning of the body of the procedure and is similar to DECLARE in anonymous PL/SQL Blocks.
The code between IS and BEGIN forms the Declaration section.
The syntax within the brackets [ ] indicate they are optional.
By using CREATE OR REPLACE together the procedure is created if no other procedure with the same name exists or the existing procedure is replaced with the current code.
The below example creates a procedure shuma which gives the sum of two numbers
How to execute a Stored Procedure?
There are two ways to execute a procedure.
1) From the SQL prompt.
2) Within another procedure – simply use the procedure name.
Krijoni nje proedure qe gjen shumen e dy numrave.
Procedura merr 2 argumenta hyres dhe nje argument Dales.
Si e perdorim proceduren?
Te ndertojme nje procedure e cila merr si argment dy numra dhe gjen shumen, diferencen dhe prodhimin e tyre
Ta perdorim proceduren