Some Basic PL/SQL programs
Print your name using PL SQL block.
Declare
message varchar2(20):='Your Name';
Begin
dbms_output.put('My name is : ');
dbms_output.put_line(message);
End;
/
Write a PL/SQL code block to find sum of three numbers.
Declare
a integer (10):=10;
b integer (10):=20;
c integer (10):=30;
d integer (10):=a+b+c;
Begin
dbms_output.put('value of a is = ');
dbms_output.put_line(a);
dbms_output.put('Value of B is = ');
dbms_output.put_line(b);
dbms_output.put('Value of c is = ');
dbms_output.put_line(c);
dbms_output.put('sum of a,b&c is = ');
dbms_output.put_line(d);
End;
/
Write a PL/SQL code block to find Simple Interest.
Declare
Principle integer (10):=10;
rate integer (10):=20;
time integer (10):=30;
simple_Int float (10):=(Principle*rate*time)/100;
Begin
dbms_output.put('value of principle is = ');
dbms_output.put_line(Principle);
dbms_output.put('Value of rate is = ');
dbms_output.put_line(rate);
dbms_output.put('Value of time is = ');
dbms_output.put_line(time);
dbms_output.put('Simple interest is = ');
dbms_output.put_line(Simple_Int);
End;
/
Write a PL/SQL program to display information of employees whose employee id is given
(Here i consider the table is Emp with attributes Emp_id,Emp_Name,job.salery).
declare
E_id Emp.Emp_id%TYPE:=7788;
E_name Emp.Emp_Name%TYPE;
jobs Emp.Job%TYPE;
Sals Emp.Sal%TYPE;
begin
select Emp_id,Emp_Name,Job,Sal
into E_id,E_name,jobs,sals from Emp
where Emp_id=E_id;
dbms_output.put_line('Employee id is : '||E_id);
dbms_output.put_line('Employee name is : '||E_name);
dbms_output.put_line('Employee job is : '|| jobs);
dbms_output.put_line('employee salery is : '||sals);
end;
/
Write a PLSQL program to print the square of a number input by the user
declare
function print_sqr(num1 number) return number
is
output number;
begin
output := num1 * num1;
return output;
end;
begin
dbms_output.put_line('The square is '|| print_sqr(&enter));
end;
No comments:
Post a Comment