急!!!高分求救!!!

dudawu 2003-08-14 08:33:47
在存储过程里,事务处理和错误处理怎样做!我是初学者,请各位大虾帮忙!!!
...全文
16 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
beckhambobo 2003-08-14
  • 打赏
  • 举报
回复
create procedure pro
as
begin
insert into a values(...);
commit;
exception
when others then
rollback;
end;
/
beckhambobo 2003-08-14
  • 打赏
  • 举报
回复
create procedure pro
as
begin
insert into a values(...);
commit;
exception
when others then
rollback;
end;
/
Michaelyfj 2003-08-14
  • 打赏
  • 举报
回复
要用异常控制,如:
exception when others then //异常处理
以上是捕获所有异常

至于事务处理,如果没有异常,则直接commit,如果有异常,则rollback
sijian2001 2003-08-14
  • 打赏
  • 举报
回复
一个例子
------------------------------------------------------------
CREATE OR REPLACE FUNCTION ClassInfo(
/* Returns 'Full' if the class is completely full,
'Some Room' if the class is over 80% full,
'More Room' if the class is over 60% full,
'Lots of Room' if the class is less than 60% full, and
'Empty' if there are no students registered. */
p_Department classes.department%TYPE,
p_Course classes.course%TYPE)
RETURN VARCHAR2 IS

v_CurrentStudents NUMBER;
v_MaxStudents NUMBER;
v_PercentFull NUMBER;
BEGIN
-- Get the current and maximum students for the requested
-- course.
SELECT current_students, max_students
INTO v_CurrentStudents, v_MaxStudents
FROM classes
WHERE department = p_Department
AND course = p_Course;

-- Calculate the current percentage.
v_PercentFull := v_CurrentStudents / v_MaxStudents * 100;

IF v_PercentFull = 100 THEN
RETURN 'Full';
ELSIF v_PercentFull > 80 THEN
RETURN 'Some Room';
ELSIF v_PercentFull > 60 THEN
RETURN 'More Room';
ELSIF v_PercentFull > 0 THEN
RETURN 'Lots of Room';
ELSE
RETURN 'Empty';
END IF;
END ClassInfo;
/
------------------------------------------------------------
dudawu 2003-08-14
  • 打赏
  • 举报
回复
要用return 返回一 个值怎么办?谢谢!!!

17,088

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧