SQL/Oracle 10g - 触发器/从表中获取值的问题
我目前正在编写的触发器遇到问题。我想做一个简单的触发器,其中在状态字段设置为“已发送”的情况下更新表 STATEMENT 后,它将在表 NOTICE 中创建一个新行,其中包含 id、日期、用户等字段,最后一个字段是消息,它采用某些字段值来创建“通知”。
如果有帮助的话,我的语句表包含以下字段:
- id
- 列表项
- 标题
- 其他不需要知道
因此,随着要插入的通知的最后一个字段,我想创建一条消息,也许会说“语句,( id) - (标题),于(日期)发布,已发送。”
我目前拥有:
create trigger send_notice
after update on STATEMENT
for each row
when (new.status = 'Sent')
begin
insert into NOTICE values (notice_seq.nextval, SYSDATE, '10001', 'the notice
im having trouble constructing');
end send_notice;
我已经在数据库中测试了这个触发器,一切似乎都工作正常。我想知道的另一件事是格式或是否缺少任何内容可能有助于此触发?另外,我想创建一个通知,它从 STATMENT 中获取字段值吗?
任何帮助表示赞赏
I'm currently having an issue with a trigger I'm writing. I want to do a simple trigger in which after an update to table STATEMENT with the status field set to 'Sent', it would create a new row in the table NOTICE with fields such as id, date, user and the last field being a message which takes certain field values to create a "notice".
If it will help, my STATEMENT table contains the following fields:
- id
- List item
- Title
- Others not needed to know
So, with the last field of the NOTICE to be inserted, I want to create like a message, perhaps saying "The statement, (id) - (title), issued on (date) has been sent."
I currently have at the moment:
create trigger send_notice
after update on STATEMENT
for each row
when (new.status = 'Sent')
begin
insert into NOTICE values (notice_seq.nextval, SYSDATE, '10001', 'the notice
im having trouble constructing');
end send_notice;
I have tested this trigger in a database and everything seems to work fine. Another thing I was just wondering is if the formatting or if there is anything missing that might help with this trigger? And also, I would I go about creating that notice, which takes field values from STATEMENT?
Any help is appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 :new. 在触发器中引用新的 STATEMENT 列值,并将它们连接到您的文本中:
有时连接大量文本和值可能会造成混乱,您可能会发现使用这种“模板”方法更容易:
You can refer to new STATEMENT column values in the trigger using :new., and concatenate them into your text:
Sometimes concatenating a lot of text and values can get confusing, and you may find it easier to use this "template" approach: