VARIABLE TYPES IN PL/SQL PROGRAMMING:
a) While passing the values to arguments at Runtime, the PL/SQL variables can be treated as the types.\
1) Bind Variables
2) PL/SQL Variables
1) Bind Variables:
i) In PL/SQL to reference Bind variables, it must be prefix with a colon(:).
ii) In SQL*PLUS the Bind variables has to be displayed using the PRINT command.
Ex:
Sql> VARIABLE G_SALARY NUMBER;
Sql> DECLARE
V_Sal NUMBER(7,2);
BEGIN
SELECT Sal INTO V_Sal FROM Emp where Empno=7369;
:G_Salary :=V-Sal;
END;
SQL> PRINT G_Salary;
SQL> SET ECHO OFF;
SQL> SET VERIFY OFF;
SQL> SET SERVEROUTPUT ON;
SQL> ACCEPT B_NUMBER1 PROMPT 'Please Enter the first number:';
SQL> ACCEPT B_NUMBER2 PROMPT 'Please Enter the secong number:';
SQL> DECLARE
V_Number1 NUMBER(9,2):=&B_Number1;
V_Number2 Number(9,2):=&B_Number2;
BEGIN
:Bind_Variable:=(V_Number1/V_Number2)+V_Number2;
END;
SQL> PRINT Bind_Variable;
DISCUSS: \Introduction\Vmethods\Bvari\Example1.sql
\Introduction\Vmethods\Bvari\Example2.sql
SQL> SET ECHO OFF
SQL> SET VERIFY OFF
SQL> VARIABLE B_Total NUMBER
SQL> ACCEPT B_Salary PROMOT 'Please Enter the Salary amount:'
SQL> ACCEPT B_Bonus PROMOT 'Please Enter the Bonus Percentage:'
SQL> DECLARE
V_Salary NUMBER(9,2):=&B_Salary;
V_Bonus NUMBER(9,2):=&B_Bonus;
BEGIN
:B_Total :=NVL(V_Salary,0)*(1+NVL(V_Bonus,0)/100
END;
SQL> PRINT B_Total;
2) PL/SQL Variables:
i) These are substitution variables that are directly declared within the program.
ii) These variables can be associated to the variables declared in ACCEPT command.
iii) The PL/SQL variables can be projected using the DBMS_OTUPUT.PUT_LINE method within PL/SQL program.
SQL> SET ECHO OFF;
SQL> SET VERIFY OFF;
SQL> SET SERVEROUTPUT ON;
SQL> ACCEPT P_NUMBER1 PROMPT 'Please Enter the first number:';
SQL> ACCEPT P_NUMBER2 PROMPT 'Please Enter the secong number:';
SQL> DECLARE
V_Number1 NUMBER(9,2):=&P_Number1;
V_Number2 Number(9,2):=&P_Number2;
V_RESULT(9,2);
BEGIN
V_RESULT:=(V_Number1/V_Number2)+V_Number2;
DBMS_OUTPUT.PUT_LINE(V_Result);
END;
DISCUSS: \Introduction\Vmethods\Pvari\Example1.sql
\Introduction\Vmethods\Pvari\Example2.sql
SQL> SET ECHO OFF
SQL> SET VERIFY OFF
SQL> SET SERVEROUTPUT ON;
SQL> ACCEPT P_Salary PROMOT 'Please Enter the Salary amount:'
SQL> ACCEPT P_Bonus PROMOT 'Please Enter the Bonus Percentage:'
SQL> DECLARE
V_Salary NUMBER(9,2):=&P_Salary;
V_Bonus NUMBER(9,2):=&P_Bonus;
V_RESULT NUMBER(9,2);
BEGIN
DBMS_OUTPUT.PUT_LINE('The salary is the Bonus is Rs'||TO_CHAR(NVL(V_Salary,0)*(1+NVL(V_Bonus,0)/100)));
END;
[7:59 PM
|
0
comments
]



0 comments
Post a Comment
Do comment to make this blog better