實(shí)驗(yàn)3:三輪亂弄版(共9頁(yè))_第1頁(yè)
實(shí)驗(yàn)3:三輪亂弄版(共9頁(yè))_第2頁(yè)
實(shí)驗(yàn)3:三輪亂弄版(共9頁(yè))_第3頁(yè)
實(shí)驗(yàn)3:三輪亂弄版(共9頁(yè))_第4頁(yè)
實(shí)驗(yàn)3:三輪亂弄版(共9頁(yè))_第5頁(yè)
已閱讀5頁(yè),還剩5頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、精選優(yōu)質(zhì)文檔-傾情為你奉上Oracle數(shù)據(jù)庫(kù)管理與開發(fā)I實(shí)驗(yàn)報(bào)告 系 所: 專 業(yè): 學(xué)生姓名: 學(xué)生學(xué)號(hào): 提交日期: 大連東軟信息學(xué)院Dalian Neusoft University of Information專心-專注-專業(yè)實(shí)驗(yàn)名稱: 利用PLSQL進(jìn)行系統(tǒng)功能模塊的開發(fā)實(shí)驗(yàn)日期:實(shí)驗(yàn)?zāi)康模赫莆誔L/SQL程序設(shè)計(jì)實(shí)驗(yàn)要求:按要求利用PL/SQL進(jìn)行功能模塊開發(fā)實(shí)驗(yàn)步驟描述:1. 編寫一個(gè)PL/SQL塊,輸出所有員工的員工姓名、員工號(hào)、工資和部門號(hào)。declare cursor c_emp is select * from employees; begin for v_emp in

2、c_emp loop dbms_output.put_line(v_emp.first_name|'' |v_emp.employee_id|' '|v_emp.department_id|' '|v_emp.salary); end loop; end;2. 編寫一個(gè)PL/SQL塊,輸出所有比本部門平均工資高的員工信息。declare v_avg employees.salary%type;begin for v_emp in (select * from employees) loop select avg(salary) into v_av

3、g from employees where department_id = v_emp.department_id; if v_emp.salary >= v_avg then dbms_output.put_line(v_emp.employee_id|' '| v_emp.first_name|''| v_emp.salary |''| v_emp.department_id); end if; end loop;end;3. 寫一個(gè)PL/SQL塊,輸出所有員工及其部門領(lǐng)導(dǎo)的姓名、員工號(hào)及部門號(hào)。declarecursor c_emp

4、 is select * from employees;v_emp1 c_emp%rowtype;v_emp2 c_emp%rowtype;begin open c_emp; loop fetch c_emp into v_emp1; exit when c_emp% notfound; if v_emp1.manager_id is not null then select * into v_emp2 from employees where employee_id = v_emp1.manager_id; dbms_output.put_line(''|v_emp1.fir

5、st_name|''| v_emp1.employee_id |''| v_emp1.department_id); dbms_output.put_line(''|v_emp2.first_name|''|v_emp2.employee_id|''| v_emp2.department_id); else dbms_output.put_line(''|v_emp1.first_name|''| v_emp1.employee_id |''| v_emp1.depa

6、rtment_id); end if ; end loop; close c_emp;end; 4. 查詢姓為“Smith”的員工信息,并輸出其員工號(hào)、姓名、工資、部門號(hào)。如果該員工不存在,則插入一條新記錄,員工號(hào)為2014,員工姓為“Smith”,工資為7500元,EMAIL為,入職日期為“2000年10月5日”,職位編號(hào)為AD_VP,部門號(hào)為50。如果存在多個(gè)名為“Smith”的員工,則輸出所有名為“Smith”的員工號(hào)、姓名、工資、入職日期、部門號(hào)、EMAIL。declarev_emp employees%rowtype;beginselect * into v_emp from emp

7、loyees where last_name='Simth'dbms_output.put_line(v_emp.first_name|' '|v_emp.last_name|' '|v_emp.employee_id|' '|v_emp.salary|' '|v_emp.department_id);exceptionwhen no_data_found theninsert into employees(employee_id,last_name,salary,EMAIL,hire_date,job_id,de

8、partment_id)values(2014,'Simth',7500,'smith',to_date('2000-10-05','yyyy-mm-dd'),'AD_VP',50);when too_many_rows thenfor v_emp in (select *from employees where last_name='Simth') loopdbms_output.put_line(v_emp.first_name|' '|v_emp.last_name|'

9、 '|v_emp.employee_id|' '|v_emp.salary|' '|v_emp.hire_date|' '|v_emp.email|' '|v_emp.department_id);end loop;end; 5. 編寫一個(gè)PL/SQL塊,根據(jù)員工職位不同更新員工的工資。職位為AD_PRES、AD_VP、AD_ASST的員工工資增加1000元,職位為FI_MGR、FI_ACCOUNT的員工工資增加800元,職位為AC_MGR 、AC_ACCOUNT的員工工資增加700元,職位為SA_MAN、SA_REP的員

10、工工資增加600元,職位為PU_MAN、PU_CLERK的員工工資增加500元,職位為ST_MAN、ST_CLERK、SH_CLERK的員工工資增加400元,職位為IT_PROG、MK_MAN、MK_REP的員工工資增加300元,其它職位的員工工資增加200元。declarev_sal employees.salary%type;begin for v_emp in ( select * from employees) loop if v_emp.job_id= 'AD_PRES'or v_emp.job_id='AD_VP'or v_emp.job_id= &

11、#39;AD_ASST' then v_sal:=1000; else if v_emp.job_id= ' FI_MGR' or v_emp.job_id= 'FI_ACCOUNT' then v_sal:=800; else if v_emp.job_id= 'AC_MGR' or v_emp.job_id='AC_ACCOUNT' then v_sal:=700; else if v_emp.job_id= 'SA_MAN' or v_emp.job_id= 'SA_REP'then

12、v_sal:=600; else if v_emp.job_id= 'PU_MAN'or v_emp.job_id= 'PU_CLERK'then v_sal:=500; else if v_emp.job_id='ST_MAN'or v_emp.job_id= 'ST_CLERK'or v_emp.job_id='SH_CLERK'then v_sal:=400; else if v_emp.job_id= 'IT_PROG'or v_emp.job_id= 'MK_MAN'or

13、v_emp.job_id='MK_REP' then v_sal:=300; else v_sal:=200; end if; update employees set salary = v_emp.salary + v_sal where employee_id = v_emp.employee_id;end loop;end;6. 編寫一個(gè)PL/SQL塊,修改員工號(hào)為201的員工工資為8000元,保證修改后的工資在職位允許的工資范圍之內(nèi),否則取消操作,并說(shuō)明原因。declare v_salmin employees.salary%type;v_salmax employee

14、s.salary%type;e_lightlinit exception;begin v_salmin:=&x; v_salmax:=&y; update employees set salary = 8000 where employee_id = 201; if v_salmax<8000 then raise e_lightlinit; elsif v_salmax>8000 then raise e_lightlinit; end if; exception when e_lightlinit then dbms_output.put_line('工

15、資超限制!'); rollback; when others then dbms_output.put_line('未知錯(cuò)誤!'); end;7. 創(chuàng)建一個(gè)存儲(chǔ)過(guò)程,以員工號(hào)為參數(shù),輸出該員工的工資。-不知道對(duì)不對(duì)create or replace procedure pro_sal(v_employees_name in employees.employee_id%type)asv_sal number;v_deptno number;begin select department_id into v_deptno from employees where emplo

16、yee_id=p_empno; select salary into v_sal from employees where departments_id=v_deptno; dbms_output.put_line(v_sal); exception when no_data_found then dbms.output.put_line('員工不存在'); end;-自己寫的8. 創(chuàng)建一個(gè)存儲(chǔ)過(guò)程,以員工號(hào)為參數(shù),修改該員工的工資。若該員工屬于10號(hào)部門,則工資增加140元;若屬于20號(hào)部門,則工資增加200元;若屬于30號(hào)部門,則工資增加250元;若屬于其他部門,則工資增長(zhǎng)

17、300元。 create or replace procedure pro_sal_change(v_employees_name in employees.employee_id%type)asv_sal number;v_deptno number;begin FOR v_emp IN c_emp LOOP CASE v_emp.department_id WHEN 10 THEN v_increment:=140; WHEN 20 THEN v_increment:=200; WHEN 30 THEN v_increment:=250; ELSE v_increment:=300; EN

18、D CASE; UPDATE employees SET salary=salary+v_increment WHERE CURRENT OF c_emp; END LOOP; exception when no_data_found then dbms.output.put_line('員工不存在'); end;9. 創(chuàng)建一個(gè)函數(shù),以員工號(hào)為參數(shù),返回該員工的工資。 CREATE OR REPLACE FUNCTION func_emp_salary( p_empno employees.employee_id%type)RETURN employees.salary%typ

19、eAS v_sal employees.salary%type;BEGIN SELECT salary INTO v_sal FROM employees WHERE employee_id=p_empno; RETURN v_sal;EXCEPTION WHEN NO_DATA_FOUND THEN RAISE_APPLICATION_ERROR(-20000,'There is not such an employee!');END func_emp_salary;10. 創(chuàng)建一個(gè)函數(shù),以部門號(hào)為參數(shù),返回該部門的平均工資; create or replace functi

20、on dro_avg_salary(v_deptno emp.deptno%type) return emp.sal%type is vr_sal emp.sal%type;begin select avg(sal) into vr_sal from emp where deptno = v_deptno; return vr_sal;end;11. 創(chuàng)建一個(gè)函數(shù),以員工號(hào)為參數(shù),返回該員工所在部門的平均工資。 CREATE OR REPLACE FUNCTION func_emp_dept_avgsal(p_empno employees.employee_id%type)RETURN em

21、ployees.salary%typeAS v_deptno employees.department_id%type; v_avgsal employees.salary%type;BEGIN SELECT department_id INTO v_deptno FROM employees WHERE employee_id=p_empno; SELECT avg(salary) INTO v_avgsal FROM employees WHERE department_id=v_deptno; RETURN v_avgsal;EXCEPTION WHEN NO_DATA_FOUND THEN RAISE_APPLICATION_ERROR(-20000,'There is not such an employee!');END func_emp_dept_avgsal;12. 在employees表上創(chuàng)

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論