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

Chapter 4 PLSQL

1. A PL/SQL block inserts numbers 1-10 except 6 and 8 into a table called messages and commits the changes. It then selects the results from the messages table. 2. A PL/SQL block declares variables to store an employee ID, salary, and bonus from the employees table. It calculates the bonus as 10%, 15%, or 20% of salary depending on salary amount and outputs the employee details. 3. A table called Emp is created from the Employees table and adds a default column called STARS with the value '*'.

Uploaded by

Ahmed Said
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Chapter 4 PLSQL

1. A PL/SQL block inserts numbers 1-10 except 6 and 8 into a table called messages and commits the changes. It then selects the results from the messages table. 2. A PL/SQL block declares variables to store an employee ID, salary, and bonus from the employees table. It calculates the bonus as 10%, 15%, or 20% of salary depending on salary amount and outputs the employee details. 3. A table called Emp is created from the Employees table and adds a default column called STARS with the value '*'.

Uploaded by

Ahmed Said
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Chapter 4 PL/SQL

1.create table messages (results number);


a) begin
for i in 1..10 loop
if i not in (6,8) then
insert into messages (results)
values (i);
end if;
end loop;
b) COMMIT;
end;
c)select results
from messages;
-----------------------------------------------------------------------------------2)declare emp_id employees.employee_id%TYPE;
emp_salary employees.salary% TYPE;
emp_bouns number(4,2);
begin
select employee_id, salary
into emp_id, emp_salary
from employees
where employee_id=&Enter_employee_id ;
dbms_output.put_line('Employee Number ' ||'Salary '|| 'Resulting Bouns');
a) if(emp_salary <5000) then
dbms_output.put_line(emp_id || ' ' || emp_salary ||' '|| 0.1*emp_salary);
b) elsif (emp_salary between 5000 and 10000 ) then
dbms_output.put_line(emp_id ||' '|| emp_salary ||' '|| 0.15*emp_salary);
c) elsif (emp_salary >10000 ) then
dbms_output.put_line(emp_id ||' '|| emp_salary ||' '|| 0.2*emp_salary);
d) elsif (emp_salary IS null ) then
dbms_output.put_line(emp_id ||' '|| emp_salary ||' '|| 0);
end if;
end;
------------------------------------------------------------------------------------

3)CREATE TABLE Emp


AS (SELECT * FROM Employees);
ALTER TABLE Emp
ADD STARS varchar2(50)
default '*';

-----------------------------------------------------------------------------------4)ALTER TABLE Employees ADD STARS VARCHAR2(10) DEFAULT '*';


DECLARE
emp_id employees.employee_id% TYPE;
emp_salary employees.salary% TYPE;
emp_star employees.stars% TYPE;
Number_div number;
Number_stars number;
BEGIN
SELECT employee_id,
salary,
stars
INTO emp_id,
emp_salary,
emp_star
FROM employees
WHERE employee_id=
&Enter_Employee_id;
number_div : = emp_salary/1000;
number_stars := trunc(Number_div, 0);
for i in 1..Number_stars loop
string x:= replicate('*', number_stars);
end loop;
emp_star :=x;
dbms_output.put_line('Employee ID '|| ' '|| 'Salary '||' '||'Stars');
dbms_output.put_line(emp_id|| '
'|| emp_salary||' '|| emp_star);
END;
------------------------------------------------------------------------------------

You might also like