| how to create the trigger ? [message #575845] |
Mon, 28 January 2013 06:34  |
 |
saeed_06
Messages: 10 Registered: January 2013 Location: pakistan
|
Junior Member |
|
|
|
how to create the trigger that count the last 7 day about from sale table if the last 7 day amount is greater then 10000 then update the commission 2% other wise do nothing
|
|
|
|
|
|
|
|
|
|
| Re: how to create the trigger ? [message #576078 is a reply to message #576076] |
Thu, 31 January 2013 06:38   |
 |
sss111ind
Messages: 268 Registered: April 2012 Location: India
|
Senior Member |

|
|
CREATE OR REPLACE
PROCEDURE process_commission
IS
l_salsum NUMBER;
BEGIN
SELECT SUM(sal)
INTO l_salsum
FROM emp
WHERE hiredate>=TRUNC(SYSDATE)
AND hiredate <TRUNC(SYSDATE-7);
IF l_salsum >10000 THEN
UPDATE emp SET sal=sal+sal*0.02;
END IF;
END;
BEGIN
DBMS_SCHEDULER.create_job (
job_name => 'process_commission_job',
JOB_TYPE => 'PLSQL_BLOCK',
job_action => 'BEGIN process_commission; END;',
start_date => SYSTIMESTAMP,
repeat_interval => 'freq=daily; byhour=5; byminute=00; bysecond=0;',
end_date => NULL,
enabled => TRUE,
comments => 'Job defined to update the commission.');
END;
/
[Updated on: Thu, 31 January 2013 06:40] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: how to create the trigger ? [message #576100 is a reply to message #576082] |
Thu, 31 January 2013 07:57   |
joy_division
Messages: 4267 Registered: February 2005 Location: East Coast USA
|
Senior Member |
|
|
sss111ind wrote on Thu, 31 January 2013 07:58
WHERE hiredate>=TRUNC(SYSDATE)
AND hiredate <TRUNC(SYSDATE-7);
[/code]
This can never happen. How can it be greater than today but less than 7 days ago?
|
|
|
|
|
|
|
|
|
|