触发以使用PL/SQL显示消息 [英] Trigger to display message using PL/SQL

查看:149
本文介绍了触发以使用PL/SQL显示消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当将新记录插入到Employee表中时,我想创建一个触发器以显示消息"NEW EMPLOYEE DESERILS INSERTED",并且具有此代码-

I want to create a trigger to display the message "NEW EMPLOYEE DETAILS INSERTED", whenever a new record is inserted into Employee table, and have this code for it-

set serveroutput on;
create or replace trigger display_message 
after insert or update on employee
for each row
when(new.emp_id>0)
begin
dbms_output.put_line('new employee details inserted');
end; 

但是,这没有给我任何输出.请帮忙,谢谢!

But this isn't giving me any output. Please help, thanks in advance!

推荐答案

仅当 EMP_ID 不大于 0 时,该方法才起作用.是吗?就我而言,它有效:

It won't work only if EMP_ID isn't larger than 0. Is it? In my case, it works:

样品表:

SQL> CREATE TABLE employee
  2  (
  3     emp_id   NUMBER
  4  );

Table created.

触发:

SQL> CREATE OR REPLACE TRIGGER display_message
  2     AFTER INSERT OR UPDATE
  3     ON employee
  4     FOR EACH ROW
  5     WHEN (new.emp_id > 0)
  6  BEGIN
  7     DBMS_OUTPUT.put_line ('new employee details inserted');
  8  END;
  9  /

Trigger created.

测试:

SQL> SET SERVEROUTPUT ON;
SQL> INSERT INTO employee (emp_id)
  2       VALUES (100);
new employee details inserted                 --> the message is here!

1 row created.

SQL>

这篇关于触发以使用PL/SQL显示消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆