【问题标题】:Create Trigger to Print Error创建触发器以打印错误
【发布时间】:2015-03-02 12:58:08
【问题描述】:

我正在尝试创建一个触发器,当再次将同一课程分配给同一位老师时打印警告。

但是有问题,如果条件为真则触发器正常工作,但如果条件为假则触发器不工作并通过运行输出错误,这是什么问题?

这是我的触发器:

创建或替换 TRIGGER CHECK_ASSIGN

在TEACHERS_COURSES 上插入或更新teacher_id、course_id 之前

每一行

声明

x 教师课程 %rowtype;

前例外;

开始

select teacher_id, course_id into x from teacher_courses, courses, TEACHERS

where courses.C_id = TEACHERS_COURSES.Course_id

and TEACHERS.T_ID = TEACHERS_COURSES.TEACHER_ID

和 teacher_courses.teacher_ID = :new.teacher_id

和 teacher_courses.course_ID = :new.course_id;

如果 x.teacher_id = :new.teacher_id 和 x.course_id = :new.course_id 那么

raise ex;

其他

  dbms_output.put_line('Inserting Success');

如果结束;

异常

前任然后

raise_application_error(-20001, 'ERROR: You are assign same course to the same teacher.');

结束;

我有三张桌子,它们是:

COURSES: 
     course_id (PK) 
     course_name

TEACHERS: 
     teacher_id (PK) 
     teacher_name.

TEACHERS_COURSES 
      teacher with his courses

【问题讨论】:

    标签: oracle plsql triggers oracle11g


    【解决方案1】:

    dmbs_output 在触发器中使用时无法工作,因为运行触发器的进程无法写入终端,因为在数据库中运行查询或代码的实际进程没有附加终端。

    改用 UTL_FILE 包写入文件,或引发错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-11
      • 2013-07-16
      • 2014-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-09
      相关资源
      最近更新 更多