Saturday, September 19, 2020

RDBMS PLSQL Program 16 get data from user, select and update table

 set serveroutput on

declare

VEno Emp.Eno%TYPE;

VESalary Emp.ESalary%TYPE;

begin

VEno := '&VEno';

select ESalary into VESalary from Emp

where Eno = VEno;

if VESalary > 50000 then 

VESalary := VESalary - 3000;

update emp set ESalary = VESalary 

where Eno = VEno;

end if;

end;

commit;

/

RDBMS PLSQL Program 15 get data from user, select and update table

 set serveroutput on

declare

VEno Emp.Eno%TYPE;

VESalary Emp.ESalary%TYPE;

begin

VEno := '&VEno';

select ESalary into VESalary from Emp

where Eno = VEno;

if VESalary > 10000 then 

VESalary := VESalary+2000;

update emp set ESalary = VESalary 

where Eno = VEno;

end if;

end;

commit;

/

RDBMS PLSQL Program 14 get data from user, select, update and delete from table

 set serveroutput on

declare

VEno Emp.Eno%TYPE;

VESalary Emp.ESalary%TYPE;

begin

VEno := '&VEno';

select ESalary into VESalary from Emp

where Eno = VEno;

VESalary := VESalary + 5000;

update Emp set ESalary = VESalary

where Eno = VEno;

if VESalary < 80000 then 

delete from emp

where Eno = VEno;  

end if;

end;

commit;

/

RDBMS PLSQL Program 13 get data from user and delete from table

 set serveroutput on

declare

VEno char(6);

begin

VEno := '&VEno';

delete from EMP

where Eno = VEno;

end;

commit;

/

RDBMS PLSQL Program 12 get data from user and update table

 set serveroutput on

declare

VEno char(6);

VNewSalary number(10,2);

begin

VEno := '&VEno';

VNewSalary := &VNewSalary;

update Emp Set ESalary = VNewSalary

where Eno = VEno;

end;

commit;

/


RDBMS PLSQL Program 11 get data from user and insert into table

 set serveroutput on

declare

VEno char(6);

VEname varchar(30);

VESalary number(10,2);

VEDate date;

VEDno char(3);

begin

VEno := '&VEno';

VEname := '&VEname';

VESalary := &VSalary;

VEDate := '&VEDate';

VEDno := '&vEDno';

insert into Emp values(VEno,VEname,VESalary,VEDate,VEDno);

end;

commit;

/


RDBMS SQL Query to Create table and Insert Into the table

 Create Table EMP

(

Eno char(6) Primary Key,

Ename varchar(30),

Esalary number(10,2),

EDoj Date,

EDno char(3)

)

/

insert into Emp values

(

'E00001','ABC',10000,'02-Aug-2017','D01'

);


insert into Emp values

(

'E00002','XYZ',50000,'02-Jan-2016','D02'

);

insert into Emp values

(

'E00003','MNO',40000,'01-Sep-2017','D03'

);


insert into Emp values

(

'E00004','PQR',50000,'24-Feb-2020','D03'

);

insert into Emp values

(

'E00005','ABC',10000,'30-Aug-2020','D01'

);

/

Friday, September 18, 2020

RDBMS PLSQL Program 10 Case Statement

 SET SERVEROUTPUT ON 

DECLARE

v_grade CHAR(1) := UPPER('&p_grade'); 

v_appraisal VARCHAR2(20);

BEGIN

v_appraisal := CASE v_grade WHEN 'A' THEN 'Excellent' WHEN 'B' THEN 'Very Good' WHEN 'C' THEN 'Good' ELSE 'No such grade'

END;

DBMS_OUTPUT.PUT_LINE ('Grade: '|| v_grade || ' Appraisal ' || v_appraisal);

END;

/

RDBMS PLSQL Program 8 For loop (Forward Direction)

 set serveroutput on

declare

i number(10,2);

begin

for  i in 1..10

loop 

dbms_output.put_line(i);

end loop;

end;

/

RDBMS PLSQL Program 9 For loop (Reverse Direction)

 set serveroutput on

declare

i number(10,2);

begin

for  i in reverse 1..10

loop 

dbms_output.put_line(i);

end loop;

end;

/