|
|||
BEGIN. 16) Решение:ЕламанСтр 1 из 2Следующая ⇒
55) DECLARE sFirstName varchar2(20): = '& Имя_сотрудника'; sLastName varchar2(25): = '& Фамилия_сотрудника'; sEmail varchar2(25): = '& Адрес_электронной_почты'; sPhoneNumber varchar2(20): = '& Номер_телефона'; sJobId varchar2(10): = '& Должность_сотрудника'; BEGIN insert into hr. employees values(employees_seq. nextval, sFirstName, sLastName, sEmail, sPhoneNumber, sysdate, sJobId, (SELECT AVG(SALARY) from hr. employees where job_id=sJobId), null, null, null); commit; END;
54) DECLARE sFirstName varchar2(20): = '& Имя_сотрудника'; sLastName varchar2(25): = '& Фамилия_сотрудника'; sEmail varchar2(25): = '& Адрес_электронной_почты'; sPhoneNumber varchar2(20): = '& Номер_телефона'; sJobId varchar2(10): = '& Должность_сотрудника'; BEGIN insert into hr. employees values(employees_seq. nextval, sFirstName, sLastName, sEmail, sPhoneNumber, sysdate, sJobId, (SELECT MAX(SALARY) from hr. employees where job_id=sJobId), null, null, null); commit; END;
53) SET SERVEROUTPUT ON; DECLARE nEmpID hr. EMPLOYEES. Employee_id%TYPE: = & Номер_сотрудника; nOldSalary hr. employees. salary%Type; nNewSalary hr. Employees. SALARY%Type; sFirstName hr. EMPLOYEES. first_name%Type; sLastName hr. employees. Last_Name%Type; dHireDate hr. employees. HIRE_DATE%type; nYears number(4, 0); BEGIN SELECT salary into nOldSalary from hr. employees where employee_id = nEmpId; SELECT first_name into sFirstName from hr. employees where employee_id = nEmpId; SELECT last_name into sLastName from hr. employees where employee_id = nEmpId; SELECT hire_date into dHireDate from hr. employees where employee_id = nEmpId; nYears: = MONTHS_BETWEEN(SYSDATE, dHireDate)/12; IF nYears > = 15 then nNewSalary: = nOldSalary*1. 15; ELSIF nYears > = 10 Then nNewSalary: = nOldSalary*1. 10; ELSE nNewSalary: = nOldSalary*1. 05; END IF; UPDATE hr. employees SET SALARY = nNewSalary WHERE employee_id = nEmpID; commit; DBMS_OUTPUT. PUT_LINE('Номер сотрудника: ' || nEmpID || ' Имя и фамилия: ' || sFirstName || ' ' || sLastName || ' Проработано лет: ' || nYears); DBMS_OUTPUT. PUT_LINE('Старая зарплата: ' || nOldSalary || ' Новая зарплата: ' || nNewSalary); END;
52) DECLARE nOldSalary hr. employees. salary%Type; nNewSalary hr. Employees. SALARY%Type; sFirstName hr. EMPLOYEES. first_name%Type; sLastName hr. employees. Last_Name%Type; dHireDate hr. employees. HIRE_DATE%type; nYears number(4, 0); BEGIN FOR ITEM IN (SELECT Employee_id FROM hr. EMPLOYEES) LOOP SELECT salary into nOldSalary from hr. employees where employee_id = item. Employee_id; SELECT first_name into sFirstName from hr. employees where employee_id = item. Employee_id; SELECT last_name into sLastName from hr. employees where employee_id = item. Employee_id; SELECT hire_date into dHireDate from hr. employees where employee_id = item. Employee_id; nYears: = MONTHS_BETWEEN(SYSDATE, dHireDate)/12; CASE WHEN nYears > = 15 THEN nNewSalary: = nOldSalary*1. 15; WHEN nYears > = 10 THEN nNewSalary: = nOldSalary*1. 10; ELSE nNewSalary: = nOldSalary*1. 05; END CASE; UPDATE hr. employees SET SALARY = nNewSalary WHERE employee_id = item. Employee_id; DBMS_OUTPUT. PUT_LINE('Номер сотрудника: ' || item. Employee_id || ' Имя и фамилия: ' || sFirstName || ' ' || sLastName || ' Проработано лет: ' || nYears); DBMS_OUTPUT. PUT_LINE('Старая зарплата: ' || nOldSalary || ' Новая зарплата: ' || nNewSalary); END LOOP; END;
51) create sequence seq increment by 5 start with 100 maxvalue 565;
declare sjob_title varchar2(20): ='& nazvanie'; smin_salary int: ='& min'; smax_salary int: ='& max'; begin insert into jobs values(seq. nextval, sjob_title,
smin_salary, smax_salary); commit; end; / 50) declare salary employees. salary%TYPE; begin update employees set salary =(select (salary*0. 3 +salary)from employees where hire_date> 22. 03. 2010 and commission_pct< 10; ) where hire_date> 22. 03. 2010 and commission_pct< 10; end;
49)SET SERVEROUTPUT ON; BEGIN FOR item in (SELECT * FROM hr. employees) LOOP DBMS_OUTPUT. PUT_LINE(item. employee_id || ' ' || item. first_name || ' ' || item. last_name); END LOOP; END;
48) SET SERVEROUTPUT ON; declare nAvg number(8, 2); begin select avg(salary) into nAvg FROM hr. employees; DBMS_OUTPUT. PUT_LINE (nAvg); end;
47) DECLARE sFirstName varchar2(20): = '& Имя_сотрудника'; sLastName varchar2(25): = '& Фамилия_сотрудника'; sEmail varchar2(25): = '& Адрес_электронной_почты'; sPhoneNumber varchar2(20): = '& Номер_телефона'; sJobId varchar2(10): = '& Должность_сотрудника'; BEGIN insert into hr. employees values(employees_seq. nextval, sFirstName, sLastName, sEmail, sPhoneNumber, sysdate, sJobId, (SELECT MIN(SALARY) from hr. employees where job_id=sJobId), null, null, null); commit; END;
46) DECLARE sFirstName employees. first_name%TYPE; sLastName employees. Last_Name%TYPE; sEmail employees. email%TYPE; sPhoneNumber employees. phone_number%TYPE; sJobId employees. job_id%TYPE; BEGIN sFirstName: = '& Имя_сотрудника'; sLastName: = '& Фамилия_сотрудника'; sEmail: = '& Адрес_электронной_почты'; sPhoneNumber: = '& Номер_телефона'; sJobId: = '& Должность_сотрудника'; insert into hr. employees values(employees_seq. nextval, sFirstName, sLastName, sEmail, sPhoneNumber, sysdate, sJobId, (SELECT MIN(SALARY) from hr. employees where job_id=sJobId), null, null, null); commit; END;
45) DECLARE sFirstName varchar2(20): = '& Имя_сотрудника'; sLastName varchar2(25): = '& Фамилия_сотрудника'; sEmail varchar2(25): = '& Адрес_электронной_почты'; sPhoneNumber varchar2(20): = '& Номер_телефона'; sJobId varchar2(10): = '& Должность_сотрудника'; BEGIN insert into hr. employees values(employees_seq. nextval, sFirstName, sLastName, sEmail, sPhoneNumber, sysdate, sJobId, (SELECT MIN(SALARY) from hr. employees where job_id=sJobId), null, null, null); commit; END; 44) sFirstName varchar2(20): = '& Имя_сотрудника'; sLastName varchar2(25): = '& Фамилия_сотрудника'; sEmail varchar2(25): = '& Адрес_электронной_почты'; sPhoneNumber varchar2(20): = '& Номер_телефона'; sJobId varchar2(10): = '& Должность_сотрудника'; BEGIN insert into hr. employees values(employees_seq. nextval, sFirstName, sLastName, sEmail, sPhoneNumber, sysdate, sJobId, (SELECT avg(SALARY) from hr. employees where job_id=sJobId), null, null, null); commit;
43) sFirstName varchar2(20): = '& Имя_сотрудника'; sLastName varchar2(25): = '& Фамилия_сотрудника'; sEmail varchar2(25): = '& Адрес_электронной_почты'; sPhoneNumber varchar2(20): = '& Номер_телефона'; sJobId varchar2(10): = '& Должность_сотрудника'; BEGIN insert into hr. employees values(employees_seq. nextval, sFirstName, sLastName, sEmail, sPhoneNumber, sysdate, sJobId, (SELECT max(SALARY) from hr. employees where job_id=sJobId), null, null, null); commit;
42) SET SERVEROUTPUT ON; DECLARE nEmpId number(6, 0): = & Номер_сотрудника; nOldSalary number(8, 2); nNewSalary number(8, 2): = & Новая_зарплата; rEmp hr. employees%ROWTYPE; BEGIN SELECT * INTO rEmp FROM hr. EMPLOYEES WHERE employee_id = nEmpId; nOldSalary: = rEmp. Salary; rEmp. Salary: = nNewSalary; UPDATE hr. Employees SET ROW = rEmp WHERE employee_id = rEmp. employee_id; COMMIT; dbms_output. PUT_LINE('Номер сотрудника: ' || rEmp. Employee_id || ' Имя и фамилия: ' || rEmp. first_name || ' ' || rEmp. Last_name); dbms_output. PUT_LINE('Старая зарплата: ' || nOldSalary || ' Новая зарплата: ' || rEmp. Salary); END;
41) SET SERVEROUTPUT ON; DECLARE nEmpID hr. EMPLOYEES. Employee_id%TYPE: = & Номер_сотрудника; nOldSalary hr. employees. salary%Type; nNewSalary hr. Employees. SALARY%Type; sFirstName hr. EMPLOYEES. first_name%Type; sLastName hr. employees. Last_Name%Type; dHireDate hr. employees. HIRE_DATE%type; nYears number(4, 0); BEGIN SELECT salary into nOldSalary from hr. employees where employee_id = nEmpId; SELECT first_name into sFirstName from hr. employees where employee_id = nEmpId; SELECT last_name into sLastName from hr. employees where employee_id = nEmpId; SELECT hire_date into dHireDate from hr. employees where employee_id = nEmpId; nYears: = MONTHS_BETWEEN(SYSDATE, dHireDate)/12; IF nYears > = 15 then nNewSalary: = nOldSalary*1. 15; ELSIF nYears > = 10 Then nNewSalary: = nOldSalary*1. 10; ELSE nNewSalary: = nOldSalary*1. 05; END IF; UPDATE hr. employees SET SALARY = nNewSalary WHERE employee_id = nEmpID; commit; DBMS_OUTPUT. PUT_LINE('Номер сотрудника: ' || nEmpID || ' Имя и фамилия: ' || sFirstName || ' ' || sLastName || ' Проработано лет: ' || nYears); DBMS_OUTPUT. PUT_LINE('Старая зарплата: ' || nOldSalary || ' Новая зарплата: ' || nNewSalary); END;
40) DECLARE nOldSalary hr. employees. salary%Type; nNewSalary hr. Employees. SALARY%Type; sFirstName hr. EMPLOYEES. first_name%Type; sLastName hr. employees. Last_Name%Type; dHireDate hr. employees. HIRE_DATE%type; nYears number(4, 0); BEGIN FOR ITEM IN (SELECT Employee_id FROM hr. EMPLOYEES) LOOP SELECT salary into nOldSalary from hr. employees where employee_id = item. Employee_id; SELECT first_name into sFirstName from hr. employees where employee_id = item. Employee_id; SELECT last_name into sLastName from hr. employees where employee_id = item. Employee_id; SELECT hire_date into dHireDate from hr. employees where employee_id = item. Employee_id; nYears: = MONTHS_BETWEEN(SYSDATE, dHireDate)/12; CASE WHEN nYears > = 15 THEN nNewSalary: = nOldSalary*1. 15; WHEN nYears > = 10 THEN nNewSalary: = nOldSalary*1. 10; ELSE nNewSalary: = nOldSalary*1. 05; END CASE; UPDATE hr. employees SET SALARY = nNewSalary WHERE employee_id = item. Employee_id; DBMS_OUTPUT. PUT_LINE('Номер сотрудника: ' || item. Employee_id || ' Имя и фамилия: ' || sFirstName || ' ' || sLastName || ' Проработано лет: ' || nYears); DBMS_OUTPUT. PUT_LINE('Старая зарплата: ' || nOldSalary || ' Новая зарплата: ' || nNewSalary); END LOOP; END;
36) create sequence seq increment by 5 start with 100 maxvalue 565;
declare sjob_title varchar2(20): ='& nazvanie'; smin_salary int: ='& min'; smax_salary int: ='& max'; begin insert into jobs values(seq. nextval, sjob_title,
smin_salary, smax_salary); commit; end; / 38) declare salary employees. salary%TYPE; begin update employees set salary = (select (salary*0. 5 +salary) from employees where hire_date> 15. 01. 2010 and commission_pct< 10; ) where hire_date> 15. 01. 2010 and commission_pct< 10; end;
37) SET SERVEROUTPUT ON; BEGIN FOR item in (SELECT * FROM hr. employees) LOOP DBMS_OUTPUT. PUT_LINE(item. employee_id || ' ' || item. first_name || ' ' || item. last_name); END LOOP; END;
36) SET SERVEROUTPUT ON; declare nAvg number(8, 2); begin select avg(salary) into nAvg FROM hr. employees; DBMS_OUTPUT. PUT_LINE (nAvg); end;
35) DECLARE sFirstName employees. first_name%TYPE; sLastName employees. Last_Name%TYPE; sEmail employees. email%TYPE; sPhoneNumber employees. phone_number%TYPE; sJobId employees. job_id%TYPE; BEGIN sFirstName: = '& Имя_сотрудника'; sLastName: = '& Фамилия_сотрудника'; sEmail: = '& Адрес_электронной_почты'; sPhoneNumber: = '& Номер_телефона'; sJobId: = '& Должность_сотрудника'; DBMS_OUTPUT. PUT_LINE('insert into hr. employees values(' || 'Номер сотрудника' || ', ' || sFirstName || ', ' || sLastName || ', ' || sEmail || ', ' || sPhoneNumber || ', ' || sysdate || ', ' || sJobId || ', ' || '(SELECT MIN(SALARY) from hr. employees where job_id=' || sJobId || '), null, null, null); '); insert into hr. employees values(employees_seq. nextval, sFirstName, sLastName, sEmail, sPhoneNumber, sysdate, sJobId, (SELECT MIN(SALARY) from hr. employees where job_id=sJobId), null, null, null); commit; FOR item IN (SELECT * FROM hr. employees WHERE employees. first_name = sFirstName and employees. Last_name =sLastName ) LOOP DBMS_OUTPUT. PUT_LINE(item. first_name || ' ' || item. last_name || ' ' || item. Email || ' ' || item. Phone_number || ' ' || item. hire_date || ' ' || item. job_id || ' ' || item. salary ); END LOOP; END;
34) DECLARE sFirstName employees. first_name%TYPE; sLastName employees. Last_Name%TYPE; sEmail employees. email%TYPE; sPhoneNumber employees. phone_number%TYPE; sJobId employees. job_id%TYPE; BEGIN sFirstName: = '& Имя_сотрудника'; sLastName: = '& Фамилия_сотрудника'; sEmail: = '& Адрес_электронной_почты'; sPhoneNumber: = '& Номер_телефона'; sJobId: = '& Должность_сотрудника'; insert into hr. employees values(employees_seq. nextval, sFirstName, sLastName, sEmail, sPhoneNumber, sysdate, sJobId, (SELECT MIN(SALARY) from hr. employees where job_id=sJobId), null, null, null); commit; END;
33) DECLARE sFirstName varchar2(20): = '& Имя_сотрудника'; sLastName varchar2(25): = '& Фамилия_сотрудника'; sEmail varchar2(25): = '& Адрес_электронной_почты'; sPhoneNumber varchar2(20): = '& Номер_телефона'; sJobId varchar2(10): = '& Должность_сотрудника'; BEGIN insert into hr. employees values(employees_seq. nextval, sFirstName, sLastName, sEmail, sPhoneNumber, sysdate, sJobId, (SELECT MIN(SALARY) from hr. employees where job_id=sJobId), null, null, null); commit; END;
32) DECLARE sFirstName varchar2(20): = '& Имя_сотрудника'; sLastName varchar2(25): = '& Фамилия_сотрудника'; sEmail varchar2(25): = '& Адрес_электронной_почты'; sPhoneNumber varchar2(20): = '& Номер_телефона'; sJobId varchar2(10): = '& Должность_сотрудника'; BEGIN insert into hr. employees values(employees_seq. nextval, sFirstName, sLastName, sEmail, sPhoneNumber, sysdate, sJobId, (SELECT avg(SALARY) from hr. employees where job_id=sJobId), null, null, null);
31) DECLARE sFirstName varchar2(20): = '& Имя_сотрудника'; sLastName varchar2(25): = '& Фамилия_сотрудника'; sEmail varchar2(25): = '& Адрес_электронной_почты'; sPhoneNumber varchar2(20): = '& Номер_телефона'; sJobId varchar2(10): = '& Должность_сотрудника'; BEGIN insert into hr. employees values(employees_seq. nextval, sFirstName, sLastName, sEmail, sPhoneNumber, sysdate, sJobId, (SELECT max(SALARY) from hr. employees where job_id=sJobId), null, null, null);
26) Select job_title as “ Названия работ”, last_name “фамилия”, department_name as ”Название департамента”, city as “Город” From jobs as j, employees e, locations l, department d Where e. job_id = j. job_id and e. department_id=d. department_id and d. location_id = l. location_id;
30) create sequence mySeq increment by 2 start with 20 MAXVALUE 250; insert into hr. locations (location_id) values(mySeq. nextval);
24) create sequence mySequence1 increment by 10 start with 100 MAXVALUE 10000; insert into hr. employees values(mySequence1. nextval, '& Имя_сотрудника', '& Фамилия_сотрудника', '& Адрес_электронной_почты', '& Номер_телефона', sysdate, '& Должность_сотрудника', null, null, null, null); 23) Примечание: Допускается, чтобы вначале запрашивалась информация о новой заработной плате, а затем — о номере столбца. Решение: Код соответствующей команды может быть таким: UPDATE hr. EMPLOYEES SET salary=& Новая_заработная_плата WHERE employee_id = & Номер_сотрудника 25) Решение: Команда на выполнение вставки может выглядеть так: insert into hr. employees values(900, 'Ivan', 'Ivanov', Upper(substr('Ivan', 1, 1) || 'Ivanov'), '555-55-55', sysdate, 'SH_CLERK', null, null, null, null) Команда для запроса информации о введенной Вами записи может выглядеть так: select * from HR. EMPLOYEES where employee_id = 900
21) Решение: Код соответствующей команды может быть таким: DELETE FROM hr. employees WHERE employee_id=& Номер_сотрудника
24) Решение: Код соответствующего запроса может быть таким: SELECT first_name As " Имя", last_name As " Фамилия", job_id As " Должность", salary as " Оклад" from hr. employees where (job_id, salary) in (select job_id, min_salary from jobs)
21) Решение: Код соответствующего запроса может быть таким: SELECT first_name As " Имя", last_name As " Фамилия" from hr. employees where employee_id = any (select manager_id from hr. employees) 21) Решение: Код соответствующего запроса может быть таким: SELECT first_name As " Имя", last_name As " Фамилия", salary As " Оклад" from hr. employees where salary > (select avg(salary) from hr. employees, hr. departments where hr. employees. department_id = hr. departments. department_id AND hr. departments. department_name = 'Sales')
19) Решение: Код соответствующего запроса может выглядеть так: select departments. department_name AS " Отдел", employees. job_id AS " Должность", max(employees. salary) As " Максимальная зарплата", min(employees. salary) As " Минимальная зарплата", To_Char(avg(employees. salary), '99999999. 99') As " Средняя зарплата" fromhr. employees, hr. departments where hr. employees. DEPARTMENT_ID = hr. departments. DEPARTMENT_ID group by hr. departments. department_name, hr. employees. job_id having avg(employees. salary) > = 7000 order by hr. departments. department_name, hr. employees. job_id
16) Решение: Еламан Employees, locations жә не departments кестелерінен: · бө лім атауы туралы (departments кестесінен deparment_name бағ аны) · орналасқ ан қ аласы туралы (locations кестесі) ақ паратты сұ раныс арқ ылы шыгару. Сонымен бірге, employees кестесінде бө лімнің қ ызметкерлері жоқ бө лімдер туралы мә ліметті шығ ару. Сұ раныс нә тижесі бө лім бойынша сұ рыпталып, келесі бағ андар арқ ылы шығ арылуы тиіс «Отдел», «Город»
select d. department_name as Otdel, l. city as Gorod from locations l, departments d, employees e where d. manager_id=null order by d. department_id /
|
|||
|