2.Using $ Operator in PL/SQL

PL/SQL

Using & in plsql : & is used to read values at run time

Example 1:
Write a program to read any 2 numbers and find their sum

declare
a number :=&a;
b number :=&b;
c number;
begin
c:=a+b;
dbms_output.put_line (c);
end;
/

Output

SQL> @ filename.sql
Enter value for a: 10
Enter value for b: 20
30

PL/SQL procedure successfully completed.

SQL> /
Enter value for a: 50
Enter value for b: 40
90


Example2:
Write a program to read an empno, empname and sal, doj then calculate
anual sal, and bonus as 10% on anual sal. Show all values

DECLARE
lc_ename varchar2(10):=’&ename’;
ln_eno number:=&eno;
ln_sal number:=&sal;
ln_asal number;
ln_tax number;
ln_bonus number;
BEGIN
ln_asal := ln_sal*12;

ln_bonus := ln_asal * 10/100;
ln_tax  := (ln_asal+ln_bonus) *5/100;

dbms_output.put_line ('Employee name '||lc_ename);
dbms_output.put_line ('Employee no   '||ln_eno);
dbms_output.put_line ('Salary is     '||ln_sal);
dbms_output.put_line ('Anual Salary  '||ln_asal);
dbms_output.put_line ('Bonus         '||ln_bonus);
dbms_output.put_line ('Tax           '||ln_tax);

END;
/


Task: Read mno (meter no),smr (starting meter reading),emr (ending meter reading), type (domestic/nondomestic)
then calculate no of units and amount

Task: Read the acno, name of the customer, deposit, withdraw then show the final balance