Oracle 10g 中的触发器
我有一个关系,其中帐户、客户是两个与 cl_ac 关系相关的表。帐户具有 ac_id,客户端具有 c_id 作为主键,这两个相同的键在 cl_ac 表中作为外键。我在帐户(ac_id)和客户端(c_id)中有一个主键触发器,因此在这两个表中我只需要插入剩余的值,并且主键会为每个记录增加自身。现在我想要一个触发器,当我在帐户和客户端中插入值时,它会自动在“cl_ac”表中插入值。
或者另一个选项而不是触发器,不违反外键约束。
我尝试了很多选项,但无法在 cl_ac 表中一次插入 2 个值(c_id 和 ac_id)。请有人帮助我。如果我可以插入图像以便更好地理解,那就更好了,我希望,我已经用可以理解的语言提出了我的问题。
谢谢。
I've an relationship in which Account, Client are two tables are related with cl_ac relationship. Account has ac_id and client has c_id as primary keys and these same two keys are in cl_ac table as foreign keys. I have a trigger for primary keys in account (ac_id) and client (c_id) so that in both table i need to insert only remaining values and primary keys increment itself for each record. Now i want a trigger that inserts values in "cl_ac" table automatically when i insert values in account and client.
or else another option rather trigger that do not violate the foreign key constraint.
I tried many option but was unable to insert 2 values (c_id and ac_id) at a time in cl_ac table. Please somebody help me. It would have been better if i could insert an image for better understanding, i hope, i've put my question in words that is understandable .
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许您需要使用 RETURNING 来获取要插入的两个值,而不是触发器?
perhaps you need to use
RETURNING
to get both of the values you want to insert, rather than a trigger ?触发器如何知道哪个帐户与哪个客户关联?
您最好从创建帐户/客户记录的代码中插入关系记录。那是您获得必要信息的地方。
How would the trigger know which account to associate with which client?
You are better off inserting the relationship record from the code that creates the account/client records. That's where you have the necessary information.
您可能想将其包装在一个过程中,有点像下面的伪代码
You might want to wrap the thing in a procedure, sort of like the pseduo code below