你可以在触发器里设置时间比较,例如,下面的例子说明中午12点以后才触发。
SQL> create table test1
2 (
3 a number(10)
4 )
5 ;
Table created.
SQL>
SQL> create table test2
2 (
3 a number(10)
4 )
5 ;
Table created.
SQL> create or replace trigger test1_insert
2 after insert on test1
3 for each row
4 declare
5 -- local variables here
6 begin
7
8 If to_number(to_char(sysdate , 'hh24')) > 12 Then
9 insert into test2 values (:new.a);
10 end if ;
11
12 end test1_insert;
13 /
Trigger created.
SQL> select to_number(to_char(sysdate , 'hh24')) from dual ;
TO_NUMBER(TO_CHAR(SYSDATE,'HH24'))
----------------------------------
14
SQL> insert into test1 values (1) ;
1 row created.
SQL> commit;
Commit complete.
SQL> select * from test2 ;
A
----------
1
SQL> select to_number(to_char(sysdate , 'hh24')) from dual ;
TO_NUMBER(TO_CHAR(SYSDATE,'HH24'))
----------------------------------
4
SQL> insert into test1 values (2) ;
1 row created.
SQL> select * from test2 ;
A
----------
1
你可以在触发器里设置时间比较,例如,下面的例子说明中午12点以后才触发。
SQL>
create
table
test1
2
(
3
a
number(10)
4
)
5
;
Table
created.
SQL>
SQL>
create
table
test2
2
(
3
a
number(10)
4
)
5
;
Table
created.
SQL>
create
or
replace
trigger
test1_insert
2
after
insert
on
test1
3
for
each
row
4
declare
5
--
local
variables
here
6
begin
7
8
If
to_number(to_char(sysdate
,
'hh24'))
>
12
Then
9
insert
into
test2
values
(:new.a);
10
end
if
;
11
12
end
test1_insert;
13
/
Trigger
created.
SQL>
select
to_number(to_char(sysdate
,
'hh24'))
from
dual
;
TO_NUMBER(TO_CHAR(SYSDATE,'HH24'))
----------------------------------
14
SQL>
insert
into
test1
values
(1)
;
1
row
created.
SQL>
commit;
Commit
complete.
SQL>
select
*
from
test2
;
A
----------
1
SQL>
select
to_number(to_char(sysdate
,
'hh24'))
from
dual
;
TO_NUMBER(TO_CHAR(SYSDATE,'HH24'))
----------------------------------
4
SQL>
insert
into
test1
values
(2)
;
1
row
created.
SQL>
select
*
from
test2
;
A
----------
1