StoredprocedureinOracleplsql

                                               Learn Stored procedure concept in Oracle plsql

Here in this blog just we are going to see stored procedure concept in Oracle plsql.
We will include further topics in Oracle plsql training in separate blogs.

1. Stored procedure is also called as PL/SQL block
2. Stored procedure receive input in the form of parameters and performs some task and it may or may not returns a value.
3. Procedures are created to perform one or more DML operations over database.
    (Ex: To create one or more DML operation (Insert or Delete or update) over database, we are creating  
     Stored procedure)

SYNTAX for Stored procedure:

CREATE OR REPLACE PROCEDURE <NAME> (parameters if any)  
IS
          <variables>;
BEGIN
          statements;
END;

Parameters are of 3 types. Parameters is used to pass the values.

IN (Default)   -> procedure receives value from calling program.
OUT              -> Procedure send values to calling program
IN OUT         -> Calling program sends the input to procedure then procedure sends the output to calling 
                          program

CREATE OR REPLACE PROCEDURE
          RAISE_SALARY(EMPID IN NUMBER, AMT IN NUMBER, SAMPLE OUT NUMBER)
IS
BEGIN
          UPDATE EMP SET SALARY=SALARY+1000
                       WHERE EMPNO = 7844;                  (Employee is getting salary INR 2000)
          COMMIT;
          SELECT SALARY INTO SAMPLE FROM EMP WHERE EMPNO=EMPID;
END;

VARIABLE K NUMBER  - - - > Here we are declaring the variable as K.

Run the query:

EXECUTE RAISE_SALARY(7844, 1000, :K);   - - > 2000+1000 = 3000

To see the value, use the below print command

print :k

k - > 3000
                                                         Suggestions are always welcome !!!

Comments

Popular posts from this blog

Decode function in Oracle pl/sql

SUBSTR function in Oracle pl/sql