sofiDev img

Mobashshir Hasan

Difference B/W Parameter & Variable in PL/SQL

πŸ”Ή Difference Between Parameter and Variable in Oracle (PL/SQL)


βœ… 1 Variable

A variable is used to store data inside a PL/SQL block, procedure, or function for internal use.

It helps in calculations, temporary storage, and logic.

Example:

DECLARE
   v_salary NUMBER;  -- variable
BEGIN
   v_salary := 10000;
   DBMS_OUTPUT.PUT_LINE(v_salary);
END;

βœ” v_salary is a variable βœ” It is used only inside this block βœ” It stores value temporarily


βœ… 2 Parameter

A parameter is also a variable, but it is used to pass values between programs (like between caller and procedure/function).

πŸ‘‰ It is declared in the procedure/function header.

Example:

CREATE OR REPLACE PROCEDURE show_salary(p_salary NUMBER)
IS
BEGIN
   DBMS_OUTPUT.PUT_LINE(p_salary);
END;

βœ” p_salary is a parameter βœ” It receives value from outside


πŸ”₯ Main Differences

| Point    | Variable               | Parameter                                        |
| -------- | ---------------------- | ------------------------------------------------ |
| Purpose  | Store value internally | Pass value between caller and procedure/function |
| Declared | In DECLARE section     | In procedure/function bracket                    |
| Scope    | Limited to block       | Accessible inside procedure/function             |
| Types    | Normal variable        | IN, OUT, IN OUT                                  |
| Used for | Calculations & logic   | Input/Output communication                       |

🎯 Simple Interview Answer (Say Like This)

A variable is used to store data inside a PL/SQL block for internal processing. A parameter is used to pass data into or out of a procedure or function.


πŸ”‘ One Important Line

All parameters are variables, but all variables are not parameters.