The Oracle stored procedure consists of three parts: Process Declaration, execution process, and stored procedure exception.
- Oracle stored procedures can contain parameter stored procedures and parameter stored procedures.
- I. No parameter program process syntax
- 1Create Or Replace ProcedureNoParPro
- 2As;
- 3Begin
- 4;
- 5 exception // The stored procedure is abnormal.
- 6;
- 7End;
- 8
- Ii. Example of stored procedure with Parameters
- 1Create Or Replace ProcedureQueryempname (sfindno emp. empno % type)As
- 2 sName emp. ename % type;
- 3 sjob emp. job % type;
- 4Begin
- 5 ....
- 7 exception
- ....
- 14End;
- 15
- Iii. Parameter stored procedures and value assignment methods
- 1Create Or Replace ProcedureRunbyparmeters (isalInEmp. sal % type,
- SnameOut Varchar, SjobIn Out Varchar)
- 2AsIcount number;
- 3Begin
- 4Select Count(*)IntoIcountFromEmpWhereSal> isalAndJob = sjob;
- 5 if icount = 1Then
- 6 ....
- 9Else
- 10 ....
- 12EndIf;
- 13 exception
- 14WhenToo_many_rowsThen
- 15 DBMS_OUTPUT.PUT_LINE ('Return value more than 1 Line');
- 16WhenOthersThen
- 17 DBMS_OUTPUT.PUT_LINE ('An error occurred during the RUNBYPARMETERS process! ');
- 18End;
- 19
- 4. Calling stored procedures in Oracle
- Method 1
- 1Declare
- 2 realsal emp. sal % type;
- 3 realnameVarchar(40 );
- 4 realjobVarchar(40 );
- 5Begin// The Stored Procedure Call starts.
- 6. realsal: = 1100;
- 7 realname: ='';
- 8 realjob: ='Cler';
- 9 runbyparmeters (realsal, realname, realjob); -- must be in order
- 10 DBMS_OUTPUT.PUT_LINE (REALNAME |''| REALJOB );
- 11END; // Process call ends
- 12
- Method 2
- 1Declare
- 2 realsal emp. sal % type;
- 3 realnameVarchar(40 );
- 4 realjobVarchar(40 );
- 5Begin// Process call starts
- 6. realsal: = 1100;
- 7 realname: ='';
- 8 realjob: ='Cler';
- 9 runbyparmeters (sname => realname, isal => realsal, sjob => realjob); -- the variable sequence of the specified value is variable.
- 10 DBMS_OUTPUT.PUT_LINE (REALNAME |''| REALJOB );
- 11END; // Process call ends
- 12