我有一个表,我有三个列,start_hour,end_hour和date,在ORACLE Apex中,我有一个包含两个项的表单页面,P00_START_HOUR和P00_END_HOUR,我需要创建一个验证,以防止从表中插入start_hour和end_hour之间的同一日期。例如,如果在表中我已经有
start_hour || end_hour
12:00 08 || 08:00 08
我不能插入一个值,谁在这两个小时之间
P00_START_HOUR = 08:00AM
P00_END_HOUR =01:00 01
我不知道该怎么做。
发布于 2019-05-30 13:39:10
我为这个示例创建了一个用户表
create table users (
id number generated by default on null as identity
constraint users_id_pk primary key,
name varchar2(50),
the_user varchar2(20),
email varchar2(30),
created date not null,
created_by varchar2(255) not null,
updated date not null,
updated_by varchar2(255) not null
);
-- triggers
create or replace trigger users_biu
before insert or update
on users
for each row
begin
if inserting then
:new.created := sysdate;
:new.created_by := nvl(sys_context('APEX$SESSION','APP_USER'),user);
end if;
:new.updated := sysdate;
:new.updated_by := nvl(sys_context('APEX$SESSION','APP_USER'),user);
end users_biu;
/当页面被加载时,我正在计算最后创建的用户

declare
l_user varchar2(30);
begin
select the_user into l_user
from users
order by id desc
FETCH FIRST 1 ROWS ONLY;
return l_user;
end;

创建一个验证,我比1个小时,但你可以使用你自己的规则

declare
l_created_hour varchar2(50);
l_next_hour varchar2(50);
begin
select to_char(CREATED,'DD-MM-YYYY hh:mi:ss'),
to_char(CREATED + 1/24,'DD-MM-YYYY hh:mi:ss')
into l_created_hour, l_next_hour
from USERS
where the_user = :P3_LAST_USER;
if l_next_hour >= l_created_hour then
return false;
else
return true;
end if;
end;结果是

Download the app
https://stackoverflow.com/questions/56265533
复制相似问题