完整的過程結(jié)構(gòu)如下: create or replace PRocedure 過程名 as 聲明語句段; begin 執(zhí)行語句段; exception 異常處理語句段; end;
2. 過程的特點(diǎn)
過程是有名稱的程序塊,as要害詞代替了無名塊的declare。
3. 創(chuàng)建過程實(shí)例
在【SQLPlus Worksheet】中執(zhí)行下列PL/SQL程序,該程序?qū)?chuàng)建名為tempprocedure的過程,create是創(chuàng)建過程的標(biāo)識符,replace表示若同名過程存在將覆蓋原過程。該過程定義了一個變量,其類型和testtable數(shù)據(jù)表中的currentdate字段類型相同,都是日期型,將數(shù)據(jù)表中的recordnumber字段為88的currentdate字段內(nèi)容送入變量中,然后輸出結(jié)果。 ――――――――――――――――――――――――――――――――――――― set serveroutput on create or replace procedure tempuser.tempprocedure as tempdate tempuser.testtable.currentdate%type; begin select currentdate into tempdate from testtable where recordnumber=88; dbms_output.put_line(to_char(tempdate)); end; ――――――――――――――――――――――――――――――――――――― 【配套程序位置】:第9章/ createprocedure.sql。
在【SQLPlus Worksheet】中執(zhí)行下列PL/SQL程序,執(zhí)行結(jié)果如圖9.45所示。 ――――――――――――――――――――――――――――――――――――― set serveroutput on begin tempprocedure; end; ―――――――――――――――――――――――――――――――――――――
以system用戶名、sysdba身份登錄【SQLPlus Worksheet】,執(zhí)行下列PL/SQL程序,執(zhí)行結(jié)果如圖9.46所示。 ――――――――――――――――――――――――――――――――――――― Set serveroutput on create or replace procedure scott.tempprocedure( tempdeptno in scott.dept.deptno%type, tempdname out scott.dept.dname%type, temploc in out scott.dept.loc%type)as loc1 scott.dept.loc%type; dname1 scott.dept.dname%type; begin select loc into loc1 from scott.dept where deptno=tempdeptno; select dname into dname1 from scott.dept where deptno=tempdeptno; temploc:='地址:'loc1; tempdname:='姓名'dname1; end; ――――――――――――――――――――――――――――――――――――― 【配套程序位置】:第9章/ createscottprocedure.sql。