PLSQL BASICS
PLSQL BASICS
syntax is
begin
end;
syntax;
declare
// declare all variable
begin
assign value to that varibale
then display or print the masg use dbms_output.put_line(' print whatever msg u want to print ');
begin
dbms_output.put_line('happy');
dbms_output.put_line('new');
dbms_output.put_line('year');
dbms_output.put_line('2023');
end;
declare
x number(5);
begin
x := 10;
dbms_output.put_line('Roll no: ' || x);
end;
declare
first_num number(5);
second_num number(5);
nm varchar2(20);
begin
first_num := 1000;
second_num := 5000;
nm := 'Prajali';
dbms_output.put_line('1st num : ' || first_num);
dbms_output.put_line('2nd num: ' || second_num);
dbms_output.put_line('Nmae: ' || nm);
end;
declare
rollnum number(5);
sname varchar2(20);
marks number(5);
begin
rollnum :=46;
sname := 'tinu';
marks := 90;
dbms_output.put_line('Rno : ' || rollnum || ' studname: ' || sname || ' Total Marks : ' || marks);
end;
Date := 7-feb-2023
use hr
set serveroutput on
declare
numA number(5);
numB number(5);
numC number(8);
begin
numA := 500;
numB := 200;
numC := numA + numB;
dbms_output.put_line('total Addition :- ' || numC );
end;
// student result
declare
rolno number(5);
sname varchar2(20);
total_marks number(5);
avg_marks number(5);
percentage number(5);
hindi number(5);
eng number(5);
marathi number(5);
begin
rolno := 22;
sname := 'malti';
hindi := 80;
eng := 70;
marathi := 60;
total_marks := hindi + eng + marathi ;
avg_marks := (hindi+eng+marathi)/3;
percentage := (hindi+eng+marathi)*0.34;
dbms_output.put_line('Roll number of student :- ' || rolno);
dbms_output.put_line('Name of student :- ' || sname);
dbms_output.put_line('Total marks of student :- ' || total_marks);
dbms_output.put_line('Average marks of student :- ' || avg_marks);
dbms_output.put_line('percentage of student :- ' || percentage);
end;
//student percentage
declare
rolno number(5);
sname varchar2(20);
total_marks number(5);
avg_marks number(5);
percentage number(5);
hindi number(5);
eng number(5);
marathi number(5);
begin
rolno := 25;
sname := 'Maya';
hindi := 95;
eng := 85;
marathi := 75;
total_marks := hindi + eng + marathi ;
avg_marks := total_marks/3;
percentage := total_marks/300*100;
dbms_output.put_line('Roll number of student :- ' || rolno);
dbms_output.put_line('Name of student :- ' || sname);
dbms_output.put_line('Total marks of student :- ' || total_marks);
dbms_output.put_line('Average marks of student :- ' || avg_marks);
dbms_output.put_line('percentage of student :- ' || percentage);
end;
// employee salary
declare
employer varchar2(30);
empnum number(8);
empname varchar2(20);
bsal number(10);
gross_sal number(10);
net_sal number(10);
pf number(10);
da number(10);
hra number(10);
begin
employer:= 'SHCIL';
empnum:=4432;
empname:='pranjali';
bsal:=30000;
pf:=bsal*.12;
da:=bsal*.20;
hra:=bsal*.60;
gross_sal:=bsal+da+hra;
net_sal:=gross_sal-pf;
dbms_output.put_line('employer name :- ' || employer);
dbms_output.put_line('employee number:- ' || empnum);
dbms_output.put_line('employee name :- '|| empname);
dbms_output.put_line('employee PF :- '|| pf);
dbms_output.put_line('employee DA :- '|| da);
dbms_output.put_line('employee HRA :- '|| hra);
dbms_output.put_line('employee basic salary :-' || bsal);
dbms_output.put_line('employee gross salary :- '|| gross_sal);
dbms_output.put_line('employee net salary :- ' || net_sal);
end;
Date: 8-feb-20213
use hr
set serveroutput on
declare
x number(4);
begin
x:=&x;
dbms_output.put_line('x='||x);
end;
declare
rollnum number(5);
sname varchar2(20);
marks number(5);
begin
rollnum :=&rollnum;
sname := 'tinu';
marks :=&marks;
dbms_output.put_line('Rno : ' || rollnum || ' studname: ' || sname || ' Total Marks : ' || marks);
end;
//electricity bill
declare
mno number(10); cname varchar2(20); ltype varchar2(2); cr number(10); pr number(10); nu number(10); fbill
number(10);
begin
mno:=&mno; cname:='Hiwale'; ltype:='C'; cr:=&cr; pr:=≺ nu:=(cr-pr); fbill:=nu*4.5;
dbms_output.put_line('meter no - ' || mno);
dbms_output.put_line('consumer name - ' || cname);
dbms_output.put_line('line type - '|| ltype);
dbms_output.put_line('current reading - '|| cr);
dbms_output.put_line('previous reading - '|| pr);
dbms_output.put_line('number of unit - '|| nu);
dbms_output.put_line('final bill - '|| fbill);
end;
use hr
set serveroutput on
// if ...else...learning
//if comes with condition if its true then print the given msg other wise print reming one or we use else then
remaing msg which not satisfied condition
// else always comes with if
// syntax if condition
//end if;
declare
no number;
begin
no:=&no;
dbms_output.put_line('print number - ' || no);
if no>=18 then
dbms_output.put_line('Eligible');
else
dbms_output.put_line('Not Eligible');
end if;
dbms_output.put_line('Finish');
end;
declare
pname varchar2(20);
ppage number(10);
begin
pname:='pranjali';
ppage:=&ppage;
dbms_output.put_line('age of person - ' || ppage);
dbms_output.put_line('name of person - ' || pname);
if ppage>=21 then
dbms_output.put_line('Eligible for marriage ');
else
dbms_output.put_line('Not eligible for marriage ');
end if;
end;
// if .......else Wages
declare
wno number(10);wname varchar2(20);wh number(10);wages number(10);
begin
wno:=&wno;
wname:='John';
wh:=&wh;
dbms_output.put_line('Worker number ' || wno);
dbms_output.put_line('Worker name ' ||wname);
if wh<=8 then wages:=wh*50;
dbms_output.put_line('Wages for first 8 hours ' ||wages);
else
wages:=(8*50)+(wh-8)*90;
end if;
dbms_output.put_line('Wages for next all hours ' ||wages);
end;