日期:2014-05-16 浏览次数:20350 次
---PL/SQL 一个简单的存储过程 分为四块1.声明declare 2.begin 3.exception 4.end
set?serveroutput?on; ?
?declare?
v_num?number?:=0; ?
begin?
v_num?:=2/v_num; ?
dbms_output.put_line(v_num); ?
exception ?
when?others?then?
dbms_output.put_line('error'); ?
end;?
?
---%type 变量声明的好处。
declare?
v_empno2?emp.empno%type; ?
begin?
dbms_output.put_line('test'); ?
end;?
?
---Table 变量类型
declare?
type?type_table_emp_empno?is?table?of?emp.empno%type?index?by?binary_integer; ?
v_empnos?type_table_emp_empno; ?
begin?
v_empnos(0)?:=?2999; ?
v_empnos(1)?:=?2434; ?
v_empnos(-1)?:=?8989; ?
dbms_output.put_line(v_empnos(-1)); ?
end;?
---Record 变量类型
declare?
type?type_record_dept?is?record ?
( ?
deptno?dept.deptno%type, ?
dname??dept.dname%type, ?
loc?dept.loc%type ?
); ?
v_temp?type_record_dept; ?
begin?
v_temp.deptno?:=?20; ?
v_temp.dname?:=?'tianyuexing'; ?
v_temp.loc?:=?'qhd'; ?
dbms_output.put_line(v_temp.dname?||?'?'