0% found this document useful (0 votes)
4 views

PLSQL BASICS

The document provides a comprehensive overview of PL/SQL programming, including syntax for variable declaration, assignment, and output using dbms_output.put_line. It contains multiple examples demonstrating the use of PL/SQL for various applications such as student results, employee salary calculations, and conditional statements. Additionally, it showcases how to handle user input and perform calculations for bills and discounts.

Uploaded by

Pranjali
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

PLSQL BASICS

The document provides a comprehensive overview of PL/SQL programming, including syntax for variable declaration, assignment, and output using dbms_output.put_line. It contains multiple examples demonstrating the use of PL/SQL for various applications such as student results, employee salary calculations, and conditional statements. Additionally, it showcases how to handle user input and perform calculations for bills and discounts.

Uploaded by

Pranjali
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

DATE:- 06-Feb-2023 PL SQL PRGRAMMING

syntax is

begin

end;

in this programming variables declare separetly in declare section

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

// value taken from user use &

declare
x number(4);
begin
x:=&x;
dbms_output.put_line('x='||x);
end;

// employee salary structure


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:=&empnum;
empname:='Pranjali';
bsal:=&bsal;
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;

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;

// item purchasing bill


declare
ino number(10); iname varchar2(10); poi number(10);qoi number(10);tbill number(10);da number(10);fbill
number(10);
begin
ino:=&ino; iname:='Pranali'; poi:=&poi; qoi:=&qoi; tbill:=poi*qoi; da:=tbill*0.1; fbill:=tbill-da;
dbms_output.put_line('Item no = ' || ino);
dbms_output.put_line('Name of item = ' || iname);
dbms_output.put_line('price of item = ' || poi);
dbms_output.put_line('quantity of item = ' || qoi);
dbms_output.put_line('total bill of item = ' || tbill);
dbms_output.put_line('Discount amount of item = ' || da);
dbms_output.put_line('final bill of item after 10% discount = ' || fbill);
end;
Date: 9-feb-2023

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 salesamt and commision


declare
sno number(5); sname varchar2(20); samt number(10);comm number(10);
begin
sno:=&sno; sname:='geeta'; samt:=&samt;
dbms_output.put_line('Name of sales person ' || sname);
dbms_output.put_line('Number of sales person ' || sno);
dbms_output.put_line('sales amount ' || samt);
if samt>=1000 then comm:=samt*0.10;
dbms_output.put_line('commision amount ' || comm);
else
comm:=samt*0.05;
dbms_output.put_line('commision amount ' || comm);
end if;
end;
// if ....else item purchasing
declare
ino number(5); iname varchar2(20); iprice number(20); iqty number(10); tbill number(20); dbill number(20); nbill
number(20);discount number(20);
begin
ino:=&ino;
iname:='Watch';
iprice:=&iprice; iqty:=&iqty;
dbms_output.put_line('Number of item '|| ino);
dbms_output.put_line('Price of item '|| iprice);
dbms_output.put_line('quantity of item '|| iqty);
dbms_output.put_line('Name of item '|| iname);
tbill:=iprice*iqty;
dbms_output.put_line('Total bill of item '|| tbill);
if tbill>=5000 then dbill:=tbill*0.10;
dbms_output.put_line('Discount'|| dbill);
else
dbill:=tbill*0.08;
dbms_output.put_line('Discount'|| dbill);
end if;
nbill:=tbill-dbill;
dbms_output.put_line('Net bill'|| nbill);
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;

//if........else electricity bill


declare
mno number(3);cname varchar2(10); cr number(10); pr number(10); nou number(10); charges number(10);
begin
mno:=105;
cname:='Lizy';
dbms_output.put_line('Meter no. - '|| mno);
dbms_output.put_line('consumer name - '|| cname);
cr:=&cr; pr:=&pr;
nou:=(cr-pr);
dbms_output.put_line('Number of units - '|| nou);
if nou<=100 then charges:=nou*3.5;
dbms_output.put_line('charges for fisrt 100 units - '|| charges);
else
charges:=(100*3.5)+(nou-100)*7.5;
end if;
dbms_output.put_line('charges for next all units - '|| charges);
end;

You might also like