内容发布更新时间 : 2025/6/20 19:19:02星期一 下面是文章的全部内容请认真阅读。
end;
3))FOR语句格式:
for 计数器 in 低值..高值 loop 执行语句; end loop; eg:
--从1加到100 declare
v_I int := 1; v_Sum int := 0; begin
for v_I in 1..100 loop v_Sum := v_Sum + v_I; end loop;
dbms_output.put_line(v_Sum); exception
when others then
dbms_output.put_line('error!'); end;
4))case语句格式: 1)))语法一:
CASE search_expression
WHEN expression1 THEN result1 WHEN expression2 THEN result2 ...
WHEN expressionN THEN resultN ELSE default_result END eg:
select scott.emp.empno, scott.emp.ename, case scott.emp.empno when 7369 then 'aa' when 7499 then 'bb' when 7521 then 'cc' when 7566 then 'dd' when 7654 then 'ee' else 'ff'
end A --新字段名称 from scott.emp
41
2)))语法二: CASE
WHEN condition1 THEN result1 WHEN condition2 THEN result2 ...
WHEN conditionN THEN resultN ELSE default_result END eg:
select scott.emp.empno, scott.emp.ename, case
when scott.emp.empno=7369 then 'aa' when scott.emp.empno=7499 then 'bb' when scott.emp.empno=7521 then 'cc' when scott.emp.empno=7566 then 'dd' when scott.emp.empno=7654 then 'ee' else 'ff'
end A --新字段名称 from scott.emp
2.关键字%TYPE和%ROWTYPE的含义和作用是什么? 解:
(1)%type:
如果声明的变量是直接映射到数据库的某一列上,那么就可以使用%type关键字将变量锚定到这个列上。
比如:declare v_ename scott.emp.ename%type; 当数据类型发生变化时,此方法显得非常灵活。
如果更改了列的长度,那么锚定到该列上的所有变量都会自动更改其长度;
假设我们将v_ename定义为varchar2(10),那么当emp表中的ename列发生变化时, 我们得手动将v_enam更改为emp.ename相同的数据长度; 当我们使用锚定类型后,变量就会自动进行调整。 (2)%rowtype:
%rowtype与%type相似;不过它将变量锚定到表的所有列,而不是锚定到某一列;
3.如何处理用户自定义的异常? 解:
使用RAISE_APPLICATION_ERROR 函数,该函数是将应用程序专有的