【正文】
D ClassList。 p_IDs(p_NumStudents) := v_StudentID。 EXIT WHEN c_RegisteredStudents%NOTFOUND。 例四 —— 包體 OPEN c_RegisteredStudents。 Local cursor to fetch the registered students. CURSOR c_RegisteredStudents IS SELECT student_id FROM registered_students WHERE department = p_Department AND course = p_Course。 END RemoveStudent。 END IF。 Removes the specified student from the specified class. PROCEDURE RemoveStudent( p_StudentID IN %TYPE, p_Department IN %TYPE, p_Course IN %TYPE) IS BEGIN DELETE FROM registered_students WHERE student_id = p_StudentID and 例四 —— 包體 department = p_Department AND course = p_Course。 例四 —— 包體 COMMIT。 END ClassPackage。 Table type used to hold student info. TYPE t_StudentIDTable IS TABLE OF %TYPE INDEX BY BINARY_INTEGER。 Removes the specified student from the specified class. PROCEDURE RemoveStudent( p_StudentID IN %TYPE, p_Department IN %TYPE, 包規(guī)范 p_Course IN %TYPE)。 為 PL/SQL程序提供了全局對象。 子程序 —— 相關(guān)數(shù)據(jù)字典 ?USER_OBJECTS 所有對象,包含子程序 ?USER_SOURCE 存儲過程,函數(shù),觸發(fā)器,包的源碼 ?USER_ERRORS 編譯過程中的錯誤信息 包( package) ?包是一個可以將相關(guān)對象存儲在一起的PL/SQL結(jié)構(gòu)。 p(a1, a2)。 —— 形參限制 p (v1 out %type) 子程序 —— 參數(shù)標(biāo)識 1. 位置標(biāo)識 p(v1, v2, v3) p(a1, a2, a3) 2. 帶名標(biāo)識 p(v1 = a1, v3 = a3, v2 = a3)。 a3 char(6)。 錯誤 2. 實(shí)參限制 p(v1 out varchar2, v2 out number, v3 out char) a1 varchar2(10)。 函數(shù) —— 創(chuàng)建語法 Create or replace function function_name [ (argument [in|out|in out] type, …)] Return type [is|as] begin [Exception] end [function_name]。 RETURN TRUE。 存儲過程 —— 創(chuàng)建語法 Create or replace procedure procedure_name [ (argument [in|out|in out] type, …)] [is|as] 說明部分 Begin 執(zhí)行部分 [Exception] 例外處理部分 end [procedure_name]。 必須說明 存儲過程 Create or replace procedure raise_salary (emp_id integer,increase real) is begin update emp set sal=sal+increase where eno=emp_id 。 SQL show error TRIGGER T1出現(xiàn)錯誤: LINE/COL ERROR 2/2 PL/SQL: SQL Statement ignored 2/25 PLS00201: 標(biāo)識符 39。 end。 End。 end 。 時出錯 觸發(fā)器 —— 類型 ?語句級觸發(fā)器 ?行級觸發(fā)器( for each row) ?:old ?:new ?Insteadof觸發(fā)器 觸發(fā)器 —— 觸發(fā)順序 ?Before 語句級 ?Before 行級 ?DML ?After 行級 ?After 語句級 觸發(fā)器 —— 限制 ?不能有事務(wù)控制語句 ?調(diào)用的過程和函數(shù)也不能有事務(wù)控制語句 ?不能聲明 long, long raw列 ?語句級觸發(fā)器不能使用 :old, :new ?行級觸發(fā)器存取變化表與限制表 Create trigger emp_t before update of sal on emp for each row when ( is not null) begin if (: = :) then raise_application_error(… )。 錯誤信息: 錯誤位于第 1行: ORA20220: today is holiday ORA06512: 在 , line 3 ORA04088: 在執(zhí)行觸發(fā)子 39。 end 。) 。 觸發(fā)器 ?存儲在數(shù)據(jù)庫里的帶名的 PL/SQL塊,當(dāng)表被修改時,如果滿足條件,自動執(zhí)行 ?主要用處 ?維護(hù)復(fù)雜的完整性約束 ?審計(jì)修改 ?表被修改時,給其他需運(yùn)行的程序發(fā)信號 觸發(fā)器 —— 創(chuàng)建語法 Create or Replace trigger emp_check before/after insert or update or delete [for each row] on emp [when …] begin … end 。 raise。 Begin raise a。 立刻傳播到包含塊 Exception段發(fā)生例外 Excepion when a then raise b。 end 。 end if 。 PL/SQL塊的嵌套及例外轉(zhuǎn)移 D01部門沒有職工屬正常情況 … begin select eno into v_eno from emp where dno=`d01` 。 insert into tout values(err_code,err_msg) 。 例外信息捕獲 Exception when others then err_msg:=substr(sqlerrm,1,50)。 PL/SQL表 —— 屬性 (I)。 student_array(I):=rec 。 I binary_integer :=0 。 end loop 。 begin for rec in (select ename from emp) loop I:=I+1 。 ename_array ename_type 。 time_rec time_type 。 end loop 。 end if 。 elsif = l_d then