[英]PL/SQL Update Trigger (Beginner)
I have two tables. 我有两张桌子。 Table 1 includes a brief movie summary, Table 2 contains the entire movie bio.
表1包含了简短的电影摘要,表2包含了完整的电影简介。
I'd like to create an on update trigger that occurs when I update table 1. Essentially I want the first 30 characters to be updated in the table 1 movie summary, while the entire movie bio is updated in Table 2. 我想创建一个在更新表1时发生的更新触发。本质上,我希望表1电影摘要中的前30个字符被更新,而整个电影简介在表2中被更新。
Any ideas to how I would begin this task? 关于我将如何开始此任务的任何想法?
It's been a while since I worked with PL/SQL but I would try something like this: 自从我使用PL / SQL已经有一段时间了,但是我会尝试这样的事情:
Create Or Replace Trigger update_movie_bio
Before Update On Table1
For Each Row
Begin
UPDATE Table2
SET movie_bio = :new.movie_bio
WHERE movie_id = :new.movie_id
End;
So then you would update Table 1 with the first 30 characters and then this would automatically fire and update Table 2. 因此,您将使用前30个字符更新表1,然后它将自动触发并更新表2。
To update Table 1 the query would look like this: 要更新表1,查询将如下所示:
UPDATE Table1
SET movie_summary = SUBSTR("movie_summary", 0, 30)
WHERE movie_id = movie_id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.