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

PLSQL 2

The document contains examples of PL/SQL code blocks that perform various operations: 1. Updates an employee's address in the EMPLOYEE table where SSN matches and displays a confirmation message. 2. Counts the number of departments and employees in each department from the EMPLOYEE table and displays the results. 3. Deletes employees from the EMPLOYEE table who are over 60 years old based on their birthdate and displays the remaining employees. 4. Deletes employees from the EMPLOYEE table whose salary is less than $20,000 and displays a confirmation message. 5. Prompts the user to input three numbers, compares them, and displays the greatest number.

Uploaded by

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

PLSQL 2

The document contains examples of PL/SQL code blocks that perform various operations: 1. Updates an employee's address in the EMPLOYEE table where SSN matches and displays a confirmation message. 2. Counts the number of departments and employees in each department from the EMPLOYEE table and displays the results. 3. Deletes employees from the EMPLOYEE table who are over 60 years old based on their birthdate and displays the remaining employees. 4. Deletes employees from the EMPLOYEE table whose salary is less than $20,000 and displays a confirmation message. 5. Prompts the user to input three numbers, compares them, and displays the greatest number.

Uploaded by

mikku ninavi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

plsql_1

set serveroutput on;


ans.1
SQL> BEGIN
2 UPDATE EMPLOYEE SET ADDRESS='24 B NEW COLONY KOTA' WHERE SSN=&SSN;
3 DBMS_OUTPUT.PUT_LINE('RECORD GOT UPDATED');
4 END;
5 /
Enter value for ssn: 554433221
old 2: UPDATE EMPLOYEE SET ADDRESS='24 B NEW COLONY KOTA' WHERE SSN=&SSN;
new 2: UPDATE EMPLOYEE SET ADDRESS='24 B NEW COLONY KOTA' WHERE
SSN=554433221;

RECORD GOT UPDATED


SQL> SELECT FNAME,ADDRESS FROM EMPLOYEE;

FNAME ADDRESS
--------------- --------------------------------------------------
doug 24 B NEW COLONY KOTA

1 row selected.

---------------------------------------------------------------------------------------------------------------
------------------

ans 2.

SQL> declare
2 no_dep number(3);
3 i number(3);
4 no_emp number(3);
5 begin
6 select count( distinct depno) into no_dep from employee;
7 dbms_output.put_line('No. of dep= '||no_dep);
8 i:=1;
9 while(i<=no_dep) loop
10 select count(*) into no_emp from employee where depno=i;
11 dbms_output.put_line(' Dep '|| i || ' No. of emp= '||no_emp);
12 i:=i+1;
13 end loop;
14 end;
Page 1
plsql_1
15 /
No. of dep= 5
Dep 1 No. of emp= 1
Dep 2 No. of emp= 1
Dep 3 No. of emp= 2
Dep 4 No. of emp= 3
Dep 5 No. of emp= 3

PL/SQL procedure successfully completed.

_____________________________________________________________________________
_____________________________________

ans 3.

SQL> begin
2 delete from employee where (months_between(sysdate,bdate)/12)>60;
3 end;
4 /

PL/SQL procedure successfully completed.

SQL> select fname, bdate from employee;

FNAME BDATE
--------------- ---------
Doug 09-JUN-60
Joyce 07-FEB-78
Joyce 31-JUL-62
Alicia 19-JUL-58
Ahmed 29-MAR-59

_____________________________________________________________________________
_______________________________________

ans 5.

SQL> begin
2 delete from employee where salary<20000;
3 dbms_output.put_line('Records updated');
4 end;
5 /
Records updated
Page 2
plsql_1

PL/SQL procedure successfully completed.

EXE - 8
ANS .1
SQL> declare
2 a number;
3 b number;
4 c number;
5 begin
6 a:=&a;
7 b:=&b;
8 c:=&c;
9 if(a>b) and (a>c) then
10 dbms_output.put_line('the greatest is'||a);
11 elsif(b>a) and (b>c) then
12 dbms_output.put_line('the greatest is'||b);
13 else
14 dbms_output.put_line('the greatest is'||c);
15 endif;
16 end;
17 /
Enter value for a: 12
old 6: a:=&a;
new 6: a:=12;
Enter value for b: 56
old 7: b:=&b;
new 7: b:=56;
Enter value for c: 1
old 8: c:=&c;
new 8: c:=1;

the greatest is 56

Page 3

You might also like