简易版的DDL的执行SQL函数:它应该是可以在DB2 z内的检查约束/ OS
create function rm00dv1.no_concurrent_schedules()
returns integer
LANGUAGE SQL
READS SQL DATA
NO EXTERNAL ACTION
NOT DETERMINISTIC
BEGIN
declare num_overlaps integer;
select count(*)
into num_overlaps
from
rm00dv1.schedules a
where
a.id != 0
and
exists (
select 1
from rm00dv1.schedules b
where
b.id = 0 -- matches the key of a given record
and rm00dv1.isConcurrent(b.schdl_eff_dt, b.schdl_trm_dt, a.schdl_eff_dt, a.schdl_trm_dt) != 0
);
return num_overlaps;
end;
表:
create table rm00dv1.schedules (
id int not null,
schdl_eff_dt date not null,
schdl_trm_dt date not null,
info_chg_ts timestamp(6) not null with default
)
in RM00DV1.TSRMDV01 ;
alter table rm00dv1.schedules add constraint no_schedule_overlap
check ((schdl_trm_dt < '01/01/2015')
or
rm00dv1.no_concurrent_schedules() <= 0);
我得到了SQL00551N - no execution privilege
和很奇怪,因为我可以在select语句中执行该函数。
任何想法来解决这个问题? 谢谢。
织补。我阅读了该文档,但错过了这个子弹。谢谢。仅供参考,当我存入内置函数min(1,0)时,出现错误消息,检查约束无效。因此,无论WLM的权限如何,这种方法都无法工作。 –
仅供参考,由于插入或更新操作的有效性取决于表中的值,并且无法访问表,因此触发器本身不起作用。我遇到了这个问题,http://www.ibm.com/support/knowledgecenter/SSEPEK_11.0.0/codes/src/tpc/n746.html –
@ChrisGolledge请问您是如何解决问题的? – David