Well I have a field in my table that is called status, I need to have my bank update this field automatically if the visitor does not leave the company after 18:00.
Does anyone know how I start? I'm using Oracle
Well I have a field in my table that is called status, I need to have my bank update this field automatically if the visitor does not leave the company after 18:00.
Does anyone know how I start? I'm using Oracle
Procedure is the solution to your problem.
Develop your Store Procedure:
Syntax error:
CREATE [OR REPLACE] PROCEDURE procedure_nome
[ (parameter [,parameter]) ]
IS
[declaration_section]
BEGIN
executable_section
[EXCEPTION
exception_section]
END [procedure_nome];
Example of how it would apply to the problem:
CREATE OR REPLACE Procedure AtualizaStatusVisitante
BEGIN
UPDATE visitante SET vistiante_status = 'Ausente' WHERE vistiante_status = 'Pendente';
COMMIT;
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20001, 'Ocorreu um erro');
END;
In this example, it performs an UPDATE when the visitor is with STATUS = Pendente
With the procedure created time to apply a schedule, for this will be used JOBs that allows to create this type of activity.
begin
sys.dbms_job.submit(job => :job,
what => 'begin PRC_sua_rotina; end;',
next_date => to_date('26-01-2018 20:41:52', 'dd-mm-yyyy hh24:mi:ss'),
interval => 'TRUNC(sysdate+1) + 1/24*4');
commit;
end;
Only change NEXT DATE to the date you want to run the FIRST time. Then, this date will be automatically updated to the date of that "interval", that is, the next day + 4 hours.
Sources: