Oracle plsql 題目

1.編寫一個(gè)PL/SQL程序塊 接收一個(gè)雇員名,顯示該雇員的所有內(nèi)容,(用%rowtype實(shí)現(xiàn)),當(dāng)沒有這個(gè)雇員時(shí),拋異常來顯示錯(cuò)誤提示;當(dāng)雇員同名有多個(gè)時(shí),拋異常來顯示錯(cuò)誤提示,如果沒有異常,則顯示該雇員的工資和獎(jiǎng)金,沒有獎(jiǎng)金的用0替代。(用%type實(shí)現(xiàn)); 測(cè)試(Vargas,Zlotkey,Gietz,Hello)這幾個(gè)名字 表用employees ,雇員名指的是last_name字段。
DECLARE
      V_emp_REC employees%ROWTYPE;
      com_pct employees.commission_pct%type;
      my_exception Exception;
BEGIN
      SELECT * INTO V_emp_REC  FROM employees emp
      WHERE emp.last_name=&lastname;
      dbms_output.put_line('員工姓名'||V_emp_REC.last_name||';員工Email'||V_emp_REC.email||';員工話'||V_emp_REC.phone_number||';入職日期'||V_emp_REC.hire_date||';員工工資'||V_emp_REC.salary||';員工獎(jiǎng)金'||V_emp_REC.commission_pct);
      if V_emp_REC.commission_pct is null then
             com_pct :=0;
      else
             com_pct :=V_emp_REC.commission_pct;
      end if;
      raise my_exception;
      exception
            when too_many_rows then
                  dbms_output.put_line('員工同名');
            when no_data_found then
                 dbms_output.put_line('沒有該員工');
            when others then
                 dbms_output.put_line('員工工資'||V_emp_REC.salary||';員工獎(jiǎng)金'||com_pct);
END;
2.編寫一個(gè)游標(biāo),一次性上漲全部雇員的工資。根據(jù)它所在的部門漲工資,規(guī)則: 10部門上漲10% 20部門上漲20% 30部門上漲30% 其它部門上漲40%。
DECLARE

BEGIN
          for addsal in (select department_id from employees group by department_id) loop
          if addsal.department_id='10' then
               update employees t set t.salary=t.salary*1.1  ;
         elsif  addsal.department_id='20' then
               update employees t set t.salary=t.salary*1.2;
         elsif  addsal.department_id='30' then
               update employees t set t.salary=t.salary*1.3;
         else
               update employees t set t.salary=t.salary*1.4;
         end if;
         end loop;
COMMIT;
END;
3.編寫一個(gè)REF游標(biāo), 提示用戶輸入要查看哪個(gè)表中的記錄。如果用戶輸入‘E’,則顯示emp表中的employee_id、last_name、job_id和salary列的值;如果用戶輸入‘D’,則顯示departments表中的department_id、department_name和location_id列的值
declare
           type cur_tab is ref cursor;
           mycursor cur_tab;
           v_table varchar2(30):='&請(qǐng)輸入要查看的表名';
           v_emp employees%rowtype;
           v_dept departments%rowtype;
begin
          v_table:=upper(v_table);
          if v_table='E' then
               open mycursor for select * from employees ;
               loop
               fetch mycursor into v_emp;
               exit when mycursor%notfound;
                dbms_output.put_line('員工編號(hào):'||v_emp.employee_id||'員工姓名:'||v_emp.last_name||'員工jobid:'||v_emp.job_id||'員工工資:'||v_emp.salary);
               end loop;
          elsif v_table='D' then
                 open mycursor for select * from departments ;
                 loop
                 fetch mycursor into v_dept;
                 exit when mycursor%notfound;
                 dbms_output.put_line('部門編號(hào):'||v_dept.department_id||'部門名:'||v_dept.department_name||'部門locationid:'||v_dept.location_id);
                 end loop;
          end if;
end;
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1、Check規(guī)則 Check (Agebetween15and30 )把年齡限制在15~30歲之間 2、新SQL...
    姜海濤閱讀 1,004評(píng)論 0 4
  • 1. Java基礎(chǔ)部分 基礎(chǔ)部分的順序:基本語法,類相關(guān)的語法,內(nèi)部類的語法,繼承相關(guān)的語法,異常的語法,線程的語...
    子非魚_t_閱讀 34,706評(píng)論 18 399
  • 一. Java基礎(chǔ)部分.................................................
    wy_sure閱讀 4,012評(píng)論 0 11
  • 1.1 基本結(jié)構(gòu) PL/SQL程序由三個(gè)塊組成,即聲明部分、執(zhí)行部分、異常處理部分。 1.2 命名規(guī)則 1.3 記...
    慢清塵閱讀 4,070評(píng)論 3 14
  • 簡(jiǎn)悅直播教練恬源閱讀 436評(píng)論 0 2

友情鏈接更多精彩內(nèi)容