ORACLE Apex验证

时间:2019-05-22 21:56:58

标签: oracle apex

我有一张桌子,我有三列,开始时间,结束时间和日期, 在ORACLE Apex中,我有一个包含两个项目P00_START_HOUR和P00_END_HOUR的表单页面,我需要创建一个验证,以防止在表的start_hour和end_hour之间插入相同的日期。 例如,如果在表中我已经有
| start_hour || end_hour |
| 12:00 PM ||下午08:00 |
我无法插入这两个小时之间的值 像这样
P00_START_HOUR = 08:00 AM
P00_END_HOUR = 01:00 PM
我不知道该怎么做。

1 个答案:

答案 0 :(得分:0)

我为此示例创建了一个用户表

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;
/

页面加载后,我正在计算上次创建的用户

enter image description here

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;

enter image description here

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

enter image description here

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;

结果是

enter image description here

Download the app