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.