declare
v_num number := 0;
begin
v_num := 4/v_num;
dbms_output.put_line(v_num);
end;
/
declare
v_num number := 0;
begin
v_num := 4/v_num;
dbms_output.put_line(v_num);
exception
when others then
dbms_output.put_line('error!');
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) := 7369;
v_empnos(2) := 7839;
v_empnos(-1) := 7369;
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 := 50;
v_temp.dname := 'aaa';
v_temp.loc := 'beijing'
dbms_output.put_line(v_temp.deptno||'--'||v_temp.dname|| '--' ||v_temp.loc);
end;
/
declare
v_ename emp.ename%type;
v_sal emp.sal%type;
begin
select ename,sal into v_ename, v_sal from emp where empno=7369;
dbms_output.put_line(v_ename ||'--' ||v_sal);
end;
/
declare
v_deptno dept2.deptno%type;
v_dname dept2.dname%type;
v_count number;
begin
update dept2 set dname='hanlipeng' where deptno=10;
commit;
select dname into v_dname from dept2 where deptno=10;
dbms_output.put_line(v_dname);
end;
/
declare
v_deptno emp2.deptno%type := 10;
v_count number;
begin
--update emp2 set sal=sal/2 where deptno=v_deptno;
--select deptno into v_deptno from emp2 where empno=7369;
select count(*) into v_count from emp2;
dbms_output.put_line(sql%rowcount || '条记录被影响');
commit;
end;
/