Você está na página 1de 5

Problem 10: ----------------create or replace procedure getEmployeeDetails(emp_id IN number) as cursor emp_cur is select first_name,salary,hire_date from employees where salary

>15000 and hire_date > '01-FEB-1988'; emp_name employees.first_name%type; emp_salary employees.salary%type; emp_hiredate employees.hire_date%type; begin open emp_cur; loop fetch emp_cur into emp_name, emp_salary, emp_hiredate; exit when emp_cur%notfound; dbms_output.put_line(emp_name ' earns ' emp_salary ' and joined the organizat ion on ' emp_hiredate); end loop; close emp_cur; end getEmployeeDetails; ------------------------------------------------------------------Problem 10 repeated with parameterized cursor ------------------------------------------------create or replace procedure getEmployeeDetails(emp_id IN number) as cursor emp_cur(emp_id number) is select first_name,salary,hire_date from employees where employee_id = emp_id; emp_name employees.first_name%type; emp_salary employees.salary%type; emp_hiredate employees.hire_date%type; begin open emp_cur(emp_id); fetch emp_cur into emp_name, emp_salary, emp_hiredate; if emp_salary > 15000 and emp_hiredate > '21-JUN-1980' then dbms_output.put_line(emp_name ' earns ' emp_salary ' and joined the organizat ion on ' emp_hiredate); else dbms_output.put_line('Salary is below 15000 and date is 21-JUN-1999'); end if; close emp_cur; end getEmployeeDetails; ------------------------------------------------------------------------------------Problem 11 ----------------

create or replace procedure getEmployeeDepartment(emp_id IN number) as cursor emp_cur(emp_id number) is select first_name, department_id from employees where employee_id > emp_id; emp_name employees.first_name%type; emp_dept employees.department_id%type; begin open emp_cur(emp_id); loop fetch emp_cur into emp_name, emp_dept; exit when emp_cur%notfound; dbms_output.put_line('Employee Name :' ); end loop; close emp_cur; end getEmployeeDepartment; -----------------------------------------------------------------------------------Problem:12 ----------------create or replace procedure getEmployeeByDate(date_in IN date) as cursor date_cur(date_in date) is select employee_id,first_name,salary,hire_date from employees where hire_date > date_in; emp_id employees.employee_id%type; emp_name employees.first_name%type; emp_salary employees.salary%type; emp_hiredate employees.hire_date%type; begin open date_cur(date_in); loop fetch date_cur into emp_id, emp_name, emp_salary, emp_hiredate; exit when date_cur%notfound; dbms_output.put_line(emp_id emp_name emp_hiredate); end loop; close date_cur; end getEmployeeByDate; -----------------------------------------------------------------------------------Problem 6: ------------set serveroutput on; declare cursor c1 is

emp_name ' Department ID : ' emp_dept

select d.department_name, count(*) "No of Employees" from employees e,department s d where e.department_id=d.department_id(+) group by d.department_name; emp_dept departments.department_name%TYPE; num_emp number; begin open c1; loop fetch c1 into emp_dept, num_emp; exit when c1%notfound; dbms_output.put_line('In Dept ' emp_dept ' ' num_emp ' people works'); end loop; close c1; end; / show errors;

-------------------------------------------------------------------------------------Problem 9: -------------create or replace procedure updateEmployee(emp_num number,dept_num number, perce nt_incr number) as new_salary employees.salary%type := null; old_salary employees.salary%type := null; begin select salary into old_salary from employees where employee_id = emp_num; salary_in := salary_in + ((percent_incr/100)*salary_in); update employees set department_id = dept_num, salary = salary_in where employee_id =emp_num; if sql%rowcount = 0 then dbms_output.put_line('No table is updated with empid ' emp_num); else dbms_output.put_line('Table is updated with empid ' emp_num); end if; end updateEmployee; -------------------------------------------------------------------------------------Problem 1:(Error for the boolean declaration there is no dbms output) -----------set serveroutput on; declare salary number(7,2) := 2000.00;

boNum boolean := false; begin salary := 8000.00; dbms_output.put_line(salary); dbms_output.put_line(boNum); end; / show error; -------------wrong number or types of arguments in call to 'PUT_LINE' ------------------------------------------------------------------------Problem 2: ---------set serveroutput on; declare v_email char(17) := 'v_firstname' to_char('v_empno'); salary number(7,2) := 2000.00; boNum boolean := false; begin salary := 8000.00; dbms_output.put_line(salary); dbms_output.put_line(bonum); end; / show error; -----------------------------------numeric or value error: character string buffer too small ------------------------------------------------------------------------

Você também pode gostar