pl/sql中有BEFORE SELECT触发器吗?
您好,我正在使用连接到 Oracle 数据库的 sqldeveloper。
我的情况是,我的数据库中有一个客户表,其中有一个名为 start_date
的日期字段,该字段保存用户注册当天的日期,还有一个名为 is_member
的“布尔”字段。每个会员资格仅持续一年,因此如果 SYSDATE > 则
。is_member
为 false。开始日期 + 1 年
我想在用户调用 select 语句之前检查用户是否仍然是成员(如果不是,则更改 is_member
)。这可能吗?
如果没有,有没有人知道如何保持 is_member
字段最新?您可以做一个每天调用一次的触发器来查看会员资格是否已过期吗?
提前致谢! =]
Hi I am using sqldeveloper conected to an oracle database.
My senario is I have a customer table in my database with a date field called start_date
which holds the date of the day the user signed up and a "boolean" field called is_member
. Each membership only lasts one year so is_member
is false if SYSDATE > start_date + 1year
.
I would like to do a check to see if a user is still a member (and change is_member
if not) before the user calls a select statement. Is this possible?
If not has anyone got any ideas on how else to keep the is_member
field up to date? Can you do a trigger that is called once a day to see if the membership has expiered?
Thanks in advace! =]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不要使用表列来存储相关数据,而应使用视图:
is_member
视图列将始终包含最新数据。Don't use a table column to store dependent data, use a view:
The
is_member
view column will always contain up-to-date data.PL/SQL 中不存在 BEFORE SELECT 触发器之类的东西。
听起来
is_member
根本不应该是表中的列,而应该是在视图中计算的内容。 像您的代码这样的东西将简单地查询视图而不是查询基表。
There is no such thing as a
BEFORE SELECT
trigger in PL/SQL.It sounds like
is_member
should not be a column in a table at all but should be something that is computed in a view. Something likeYour code would then simply query the view rather than querying the base table.
这是应用程序执行检查的工作,而不是触发器。 Triiger 不会在 SELECT 上触发。
至于保持该领域的最新状态,有两种可能性。首先设置一项夜间工作,以停用所有会员资格已过期的会员。或者更改您的结构以存储membershipenddate而不是isactive,并在应用程序中使用它来检查成员是否处于活动状态。
This is a job for the application to do the checking not a trigger. Triiger do not fire on SELECT.
As far as keeping the field up-to-date, there are two possibilities. First set up a nightly job to inactivate any members whose meberships have expired. Or change your struture to store membershipenddate rather than isactive and use that in the application check to see if the member is active.
您可以将策略添加到表和架构中,然后添加所需的代码。
http://docs.oracle.com/cd/B28359_01 /network.111/b28531/vpd.htm#CIHCAACD
You can add a Policy to your table and schema and Add the code that you want.
http://docs.oracle.com/cd/B28359_01/network.111/b28531/vpd.htm#CIHCAACD
您可以定义每天运行的作业并更新 is_member 字段。
You can define a job which is run everyday and update the is_member field.