楼主: msnch

关于建立表触发器问题?

[复制链接]
论坛徽章:
10
授权会员
日期:2005-10-30 17:05:332010年世界杯参赛球队:科特迪瓦
日期:2010-04-15 12:20:472010年世界杯参赛球队:智利
日期:2010-04-13 17:15:21生肖徽章2007版:蛇
日期:2009-09-24 13:54:11生肖徽章2007版:龙
日期:2009-09-22 13:56:012009日食纪念
日期:2009-07-22 09:30:00生肖徽章2007版:龙
日期:2009-02-10 13:45:15生肖徽章2007版:狗
日期:2009-02-03 13:53:34会员2006贡献徽章
日期:2006-04-17 13:46:34ITPUB十周年纪念徽章
日期:2011-11-01 16:20:28
11#
发表于 2005-3-7 09:58 | 只看该作者
触发器没有通过编译,你把编译出错提示贴出来看看。

SQL*Plus中用show errors。

使用道具 举报

回复
论坛徽章:
1
会员2006贡献徽章
日期:2006-04-17 13:46:34
12#
 楼主| 发表于 2005-3-7 11:43 | 只看该作者
最初由 wyq21973 发布
[B]

INSTEAD OF触发器只有在对VIEW进行更新时才会触发。 [/B]


  我对此VIEW的一个表进行更新,难道不会点火吗?

使用道具 举报

回复
论坛徽章:
1
会员2006贡献徽章
日期:2006-04-17 13:46:34
13#
 楼主| 发表于 2005-3-7 11:45 | 只看该作者

Re: wyq21973 ,你好,执行报错!

最初由 anzi_oracle 发布
[B]wyq21973 :你好!
    我按你提供的代码:

CREATE TRIGGER ZYGS.A_TRG BEFORE INSERT OR UPDATE OR DELETE
ON ZYGS.A
FOR EACH ROW
begin
if inserting then
insert into b values (:new.id);
end if;
if updating then
update b set id = :new.id where id = ld.id;
end if;
if deleting then
delete from b where id = ld.id;
end if;
end;

建立触发器后,执行insert into a values (1) 后,oracle报错:
ORA-04098:  触发器'A-TRG'无效且未通过重新验证。
请教如何解决?谢谢 [/B]


是不是你把:old 变成ld?????

使用道具 举报

回复
论坛徽章:
10
授权会员
日期:2005-10-30 17:05:332010年世界杯参赛球队:科特迪瓦
日期:2010-04-15 12:20:472010年世界杯参赛球队:智利
日期:2010-04-13 17:15:21生肖徽章2007版:蛇
日期:2009-09-24 13:54:11生肖徽章2007版:龙
日期:2009-09-22 13:56:012009日食纪念
日期:2009-07-22 09:30:00生肖徽章2007版:龙
日期:2009-02-10 13:45:15生肖徽章2007版:狗
日期:2009-02-03 13:53:34会员2006贡献徽章
日期:2006-04-17 13:46:34ITPUB十周年纪念徽章
日期:2011-11-01 16:20:28
14#
发表于 2005-3-7 11:52 | 只看该作者

Re: Re: wyq21973 ,你好,执行报错!

最初由 msnch 发布
[B]

是不是你把:old 变成ld????? [/B]


这是系统的一个问题,正常你写一个:o会变成一个图标。
你这里是用:替了:。

使用道具 举报

回复
论坛徽章:
10
授权会员
日期:2005-10-30 17:05:332010年世界杯参赛球队:科特迪瓦
日期:2010-04-15 12:20:472010年世界杯参赛球队:智利
日期:2010-04-13 17:15:21生肖徽章2007版:蛇
日期:2009-09-24 13:54:11生肖徽章2007版:龙
日期:2009-09-22 13:56:012009日食纪念
日期:2009-07-22 09:30:00生肖徽章2007版:龙
日期:2009-02-10 13:45:15生肖徽章2007版:狗
日期:2009-02-03 13:53:34会员2006贡献徽章
日期:2006-04-17 13:46:34ITPUB十周年纪念徽章
日期:2011-11-01 16:20:28
15#
发表于 2005-3-7 12:15 | 只看该作者
最初由 msnch 发布
[B]

  我对此VIEW的一个表进行更新,难道不会点火吗? [/B]


关于这个问题文档中只找到下面的说明:

INSTEAD OF triggers provide a transparent way of modifying views that cannot be modified directly through DML statements (INSERT, UPDATE, and DELETE). These triggers are called INSTEAD OF triggers because, unlike other types of triggers, Oracle fires the trigger instead of executing the triggering statement.

You can write normal INSERT, UPDATE, and DELETE statements against the view and the INSTEAD OF trigger is fired to update the underlying tables appropriately. INSTEAD OF triggers are activated for each row of the view that gets modified.

INSTEAD OF 触发器应该只适用于用户没有表的授权的时候给他创建一个视图同时创建INSTEAD OF触发器。

使用道具 举报

回复
论坛徽章:
168
马上加薪
日期:2014-02-19 11:55:142012新春纪念徽章
日期:2012-02-13 15:10:582012新春纪念徽章
日期:2012-01-04 11:49:54蜘蛛蛋
日期:2011-12-05 16:08:56ITPUB十周年纪念徽章
日期:2011-11-01 16:19:41设计板块每日发贴之星
日期:2011-07-22 01:01:02ITPUB官方微博粉丝徽章
日期:2011-06-30 12:30:16管理团队成员
日期:2011-05-07 01:45:082011新春纪念徽章
日期:2011-01-25 15:42:562011新春纪念徽章
日期:2011-01-25 15:42:33
16#
发表于 2005-3-7 13:10 | 只看该作者
Notes on Updatable Views

An updatable view is one you can use to insert, update, or delete base table rows. You can create a view to be inherently updatable, or you can create an INSTEAD OF trigger on any view to make it updatable.

To learn whether and in what ways the columns of an inherently updatable view can be modified, query the USER_UPDATABLE_COLUMNS data dictionary view. The information displayed by this view is meaningful only for inherently updatable views. For a view to be inherently updatable, the following conditions must be met:

Each column in the view must map to a column of a single table. For example, if a view column maps to the output of a TABLE clause (an unnested collection), then the view is not inherently updatable.


The view must not contain any of the following constructs:

A set operator
a DISTINCT operator
An aggregate or analytic function
A GROUP BY, ORDER BY, MODEL, CONNECT BY, or START WITH clause
A collection expression in a SELECT list
A subquery in a SELECT list
A subquery designated WITH READ ONLY
Joins, with some exceptions, as documented in Oracle Database Administrator's Guide


In addition, if an inherently updatable view contains pseudocolumns or expressions, then you cannot update base table rows with an UPDATE statement that refers to any of these pseudocolumns or expressions.


If you want a join view to be updatable, then all of the following conditions must be true:

1.  The DML statement must affect only one table underlying the join.

2.  For an INSERT statement, the view must not be created WITH CHECK OPTION, and all columns into which values are inserted must come from a key-preserved table. A key-preserved table is one for which every primary key or unique key value in the base table is also unique in the join view.

3.  For an UPDATE statement, all columns updated must be extracted from a key-preserved table. If the view was created WITH CHECK OPTION, then join columns and columns taken from tables that are referenced more than once in the view must be shielded from UPDATE.


For a DELETE statement, if the join results in more than one key-preserved table, then Oracle Database deletes from the first table named in the FROM clause, whether or not the view was created WITH CHECK OPTION.


参考:http://www.psoug.org/reference/instead_of_trigger.html

使用道具 举报

回复
论坛徽章:
1
授权会员
日期:2006-02-05 17:25:21
17#
发表于 2005-3-9 08:41 | 只看该作者

你好, wyq21973 ,还是有问题???

CREATE TRIGGER ZYGS.A_TRG BEFORE INSERT OR UPDATE OR DELETE
ON ZYGS.A
FOR EACH ROW
begin
if inserting then
insert into b values (:new.id);
end if;
if updating then
update b set id = :new.id where id =old.id;
end if;
if deleting then
delete from b where id =old.id;
end if;
end;   
   
    建立触发器后,执行insert into a values (1) 后,oracle报错:
ORA-04098: 触发器'A-TRG'无效且未通过重新验证。
请教如何解决?谢谢

使用道具 举报

回复
论坛徽章:
131
2006年度最佳技术回答
日期:2007-01-24 12:58:48福特
日期:2013-10-24 13:57:422014年新春福章
日期:2014-02-18 16:41:11马上有车
日期:2014-02-18 16:41:11马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上加薪
日期:2014-02-19 11:55:142013年新春福章
日期:2013-02-25 14:51:24
18#
发表于 2005-3-9 09:21 | 只看该作者
show errors TRIGGER ZYGS.A_TRG
先,不让谁都帮不了你。

使用道具 举报

回复
论坛徽章:
10
授权会员
日期:2005-10-30 17:05:332010年世界杯参赛球队:科特迪瓦
日期:2010-04-15 12:20:472010年世界杯参赛球队:智利
日期:2010-04-13 17:15:21生肖徽章2007版:蛇
日期:2009-09-24 13:54:11生肖徽章2007版:龙
日期:2009-09-22 13:56:012009日食纪念
日期:2009-07-22 09:30:00生肖徽章2007版:龙
日期:2009-02-10 13:45:15生肖徽章2007版:狗
日期:2009-02-03 13:53:34会员2006贡献徽章
日期:2006-04-17 13:46:34ITPUB十周年纪念徽章
日期:2011-11-01 16:20:28
19#
发表于 2005-3-9 10:42 | 只看该作者

Re: 你好, wyq21973 ,还是有问题???

最初由 anzi_oracle 发布
[B]CREATE TRIGGER ZYGS.A_TRG BEFORE INSERT OR UPDATE OR DELETE
ON ZYGS.A
FOR EACH ROW
begin
if inserting then
insert into b values (:new.id);
end if;
if updating then
update b set id = :new.id where id =old.id;
end if;
if deleting then
delete from b where id =old.id;
end if;
end;   
   
    建立触发器后,执行insert into a values (1) 后,oracle报错:
ORA-04098: 触发器'A-TRG'无效且未通过重新验证。
请教如何解决?谢谢 [/B]


old前面再加上一个:符号。
上论坛讨论相关主题前多看看书中相关的基础知识。

使用道具 举报

回复
论坛徽章:
1
授权会员
日期:2006-02-05 17:25:21
20#
发表于 2005-3-10 11:06 | 只看该作者

wyq21973,你的批评是我前进的动力!!!


    old前面再加上一个:符号。
    上论坛讨论相关主题前多看看书中相关的基础知识。

wyq21973,你好,你的批评是我前进的动力!!!

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表