在触发器主体内创建视图

编程入门 行业动态 更新时间:2024-10-25 18:30:20
本文介绍了在触发器主体内创建视图-Oracle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否可以在Oracle中的触发器内创建或替换视图?

Is possible to create or replace a view inside a trigger in Oracle?

该视图是通过联接2个表创建的,其中一个是由触发器更新的表

The view is created by joining 2 tables and one of them is the one updated by the trigger

推荐答案

只需提供所有选项(但是在触发器中创建视图的想法可能很奇怪...),您可以可以创建触发器中的视图.是的,将跟随隐式COMMIT,但是如果我们使触发器在自主事务中工作,那么动态DDL将不会失败.以卢克·伍德沃德(Luke Woodward)为例:

Just to provide all options (however weird the idea of creating a view inside a trigger might be...) you can create a view in a trigger. Yes, an implicit COMMIT will follow, but if we make the trigger work in autonomous transaction, then the dynamic DDL will not fail. Using Luke Woodward's example:

CREATE TABLE test (a integer); INSERT INTO test (a) VALUES (5); CREATE OR REPLACE TRIGGER test_trig AFTER UPDATE ON test FOR EACH ROW DECLARE -- making the trigger work outside of the main transaction PRAGMA autonomous_transaction; BEGIN EXECUTE IMMEDIATE 'CREATE OR REPLACE VIEW test_view AS SELECT * FROM test'; END; / UPDATE test SET a = 6; SELECT * FROM test_view;

A ---------- 6

在SQLFiddle中检查

更多推荐

在触发器主体内创建视图

本文发布于:2023-10-21 17:31:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1514890.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:触发器   视图   主体

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!