I've come across several posts that almost have the same problem as I do, but I haven't found an answer that fits my situation.
I have a stored procedure, that when run manually through SQL Developer, the procedure runs and finishes successfully, I see data updated which suggests that the commits are working.
I have a job that is scheduled to run daily, and it does.
I can run the job manually, i.e. an anonymous block in SQL Developer that
executes it.
I can "right-click" --> "Run Job"
Each of these methods work, and they report a Status of "SUCCEEDED" in the run log. However, the execution time is always 00:00:00; and no data is updated in the database.
This is the anonymous block that SQL Developer created when I created the job.
DBMS_SCHEDULER.CREATE_JOB (
job_name => '"OWNER"."GSS"',
job_type => 'STORED_PROCEDURE',
job_action => 'OWNER.PKG_GSS.GENERATE_GSS_DATA',
number_of_arguments => 2,
start_date => TO_TIMESTAMP_TZ('2018-05-09 11:47:15.000000000 AMERICA/NEW_YORK','YYYY-MM-DD HH24:MI:SS.FF TZR'),
repeat_interval => 'FREQ=DAILY;BYDAY=MON,TUE,WED,THU,FRI;BYHOUR=6',
end_date => NULL,
enabled => TRUE,
auto_drop => FALSE,
comments => '');
The 2 arguments are set as well, I just didn't add it here.
Any suggestions would be greatly appreciated!!!!!
I have the same issue, my issue is resolved by granting the permission to the Procedure and recreating the job scheduler on daily basis.
Below is the procedure I wrote:
create or replace PROCEDURE dist_auto_eod AS
v_sp_code VARCHAR2(100);
v_count_eod NUMBER;
v_count_atn NUMBER;
BEGIN
FOR data IN (
SELECT
sp_code,
company_code,
branch_code
FROM
dist_login_user
WHERE
is_mobile = 'Y'
) LOOP
BEGIN
SELECT
COUNT(track_type)
INTO
v_count_eod
FROM
dist_lm_location_tracking
WHERE
track_type = 'EOD'
AND
TO_DATE(submit_date) = trunc(SYSDATE)
AND
sp_code = data.sp_code;
END;
BEGIN
SELECT
COUNT(track_type)
INTO
v_count_atn
FROM
dist_lm_location_tracking
WHERE
track_type = 'ATN'
AND
TO_DATE(submit_date) = trunc(SYSDATE)
AND
sp_code = data.sp_code;
IF
v_count_eod = 0 AND v_count_atn = 1
THEN
INSERT INTO dist_lm_location_tracking (
sp_code,
submit_date,
latitude,
longitude,
track_type,
company_code,
branch_code,
remarks
) VALUES (
data.sp_code,
TO_DATE(
trunc(SYSDATE) || ' 07:22 PM',
'dd-mon-yy hh:mi AM'
),
'',
'',
'EOD',
data.company_code,
data.branch_code,
'Automatic EOD'
);
END IF;
END;
END LOOP;
COMMIT;
END;
Related
I have this table :
penalities(player,dateofpenality,penalityDays,status)
Based on certain criteria a player is added to this table where the status goes to 'yes'. I want his status to change to 'no' jusrt after the penality period (=penalityDays) is gone.
I thought of a trigger on date but I couldn't find it in plsql.
Please note that I don't want to delete the player as I need the history .
The only way to do this is to schedule a background job which kicks off once a day.
Write a simple stored procedure to apply the change of status:
create or replace procedure update_penalty_status as
begin
update penalties
set status = 'no'
where sysdate >= dateofpenality + penalityDays
and status = 'yes';
commit;
end update_penalty_status;
Then submit a job to run once a day. This uses DBMS_SCHEDULER (available since 10g) rather than the older DBMS_JOB.
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'your_schema.my_job1',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN update_penalty_status; END;',
start_date => trunc(sysdate)+1,
repeat_interval => 'FREQ=DAILY'
enabled => TRUE,
comments => 'Revoke expired penalties');
END;
/
Note that you will need the CREATE JOB privilege to do this. You may need to ask your DBA for help and guidance. Normally I would link to the Oracle documentation at this point, but I think the Oracle-Base article is a friendlier place to start.
Can anybody tell me how to schedule a job on a standby database using dbms_scheduler? The following PLSQL works on the primary but doesn't work on the standby. It schedules a job to drop a restore point.
DECLARE
rp_drop_time DATE;
BEGIN
SELECT to_date(to_char(next_working_day, 'DD-MON-YYYY')||' 19:00', 'DD-MON-YYYY HH24:MI') rp_drop
INTO rp_drop_time
FROM (
SELECT
CASE WHEN to_char(sysdate, 'D') IN (5,6) THEN next_day(sysdate, 'Monday')
ELSE sysdate + 1 END next_working_day
FROM dual
);
dbms_scheduler.create_job
( job_name => 'RP0567901235'
, job_type => 'PLSQL_BLOCK'
, job_action => 'BEGIN EXECUTE IMMEDIATE ''DROP RESTORE POINT "RP0567901235"''; END;'
, number_of_arguments => 0
, start_date => rp_drop_time
, enabled => TRUE
);
END;
/
It's not possible to schedule a job on a physical standby DB as it's in mount mode (normally). Use an alternative method to drop a GRP at a future date - like a cronjob, 'at' cmd, OEM Job etc.
I have this DBMS Job that run at the end of day to clean the data and I have this function available CLEAN_SNAPSHOT_DATA_F(7).
I try running this script below.
begin
sys.dbms_job.submit(job => :job,
what => 'select OPTIEXEC_ADMIN.CLEAN_SNAPSHOT_DATA_F(7) from dual',
next_date => to_date('11-06-2016', 'dd-mm-yyyy'),
interval => 'SYSDATE + 24/24');
commit;
end;
But the error return ORA-01008: not all variables bound
Can you advice what the issue about the script?
Try this . Hope it helps.
DECLARE
jb_av NUMBER;
BEGIN
sys.dbms_job.submit(job => jb_av,
what => 'DECLARE lv_var VARCHAR2(32676); BEGIN select OPTIEXEC_ADMIN.CLEAN_SNAPSHOT_DATA_F(7) INTO lv_var from dual;END;',
next_date => to_date('11-06-2016', 'dd-mm-yyyy'),
interval => 'SYSDATE + 24/24');
COMMIT;
END;
I'm currently using Oracle Apex 4.2 and I need a way to have the program run through a table and send a email if it has not been sent yet. What is the best way to do this and how?
It sounds like you just want something like this (I'm speculating about your table definition, the names of your columns, etc.)
FOR m IN (SELECT *
FROM email_table
WHERE sent_yet = 'N')
LOOP
apex_mail.send( p_to => m.to,
p_from => <<your email address>>,
p_body => m.text_of_email,
p_subj => m.subject );
UPDATE email_table
SET sent_yet = 'N'
WHERE primary_key = m.primary_key;
END LOOP;
The apex_mail.send procedure documentation shows more options that you can pass in. Note that if you're not already sending email in this environment using apex_mail, you probably want to have a separate job that actually sends the queued up emails. For example, this will submit a job that sends queued up emails every minute.
DECLARE
l_jobno pls_integer;
BEGIN
dbms_job.submit( l_jobno,
'begin apex_mail.push_queue( <<smtp server>>, <<port>> ); end;',
sysdate + interval '1' minute,
q'{sysdate + interval '1' minute}' );
commit;
END;
I figured out what was the issue. I need a line of code to allow apex to send emails through my application.
BEGIN
wwv_flow_api.set_security_group_id;
for rst in (
select aud.LAN_ID, aud.ID, sent.TEMPLATE_TEXT, temp.TEMPLATE_NAME from EMAIL_Audit aud
INNER JOIN EAMAIL_SENT sent
ON aud.TEMP_TEXT_ID = sent.id
INNER JOIN EMAIL_TEMP temp
ON sent.PROCESS_ID = temp.id
WHERE SENT_IND is null
)
loop
APEX_MAIL.SEND(
p_to => 'someEmail#email.com',
p_from => 'otherEmail#email.com',
p_body => rst.TEMPLATE_TEXT,
p_subj => rst.TEMPLATE_NAME );
END loop;
APEX_MAIL.PUSH_QUEUE;
END;
I am making a job with a determined repeat_interval. My goal was to retrieve this value from a table, so that I could change this value in the table afterwards and modify the job accordingly. For this, I made the following trigger:
CREATE OR REPLACE TRIGGER config_table_aur AFTER
UPDATE OF value ON config_table FOR EACH row WHEN (new.property = 'job_interval') DECLARE v_job NUMBER;
BEGIN
dbms_job.submit (v_job, 'begin
update_interval (' || :new.value || ');
end;');
END;
And this trigger calls the following procedure:
CREATE OR REPLACE
PROCEDURE update_interval(
p_new_interval IN config_table.value%type)
AS
BEGIN
dbms_scheduler.set_attribute ('jobu', 'repeat_interval', p_new_interval);
END update_interval;
Where p_new_interval is the value I'm retrieving from the table. The problem that I'm having is that if I try setting a value in the table like this:
FREQ=DAILY; INTERVAL=1;
Then I get an error saying:
Fila 1: ORA-06550: line 2, column 46:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
year month day hour minute second
The symbol ";" was ignored.
ORA-06512: at "SYS.DBMS_JOB", line 82
ORA-06512: at "SYS.DBMS_JOB", line 140
ORA-06512: at "SOMESCHEMA.CONFIG_TABLE_AUR", line 3
ORA-04088: error during execution of trigger 'SOMESCHEMA.CONFIG_TABLE_AUR'
I guess the problem is that the attribute value contains semicolons ';' because if I don't use them I don't get the error.
Do you have any suggestions to circumvent this problem?
Thank you
I guess the problem is that the attribute value contains semicolons ';' because if I don't use them I don't get the error.
Do you have any suggestions to circumvent this problem?
Err ... Your question makes no sense. You know the problem but you don't want to fix the syntax error you have in the repeat_interval calendaring syntax ?
For this simple example your trigger looks unnecessary complex (but you might have a valid reason to use DBMS_JOB though). Here is an example that first sets a scheduled job to run at every minute on 30th second and then later changes the repeat_interval via configuration table to run every 10 seconds:
--
-- scheduler configuration via tailored config table
--
create table scheduler_config (
Job_name varchar2(100) not null,
repeat_interval varchar2(100) not null
);
insert into scheduler_config values('logger1', 'FREQ=SECONDLY; BYSECOND=30');
commit;
create or replace trigger scheduler_config_trg
after update of repeat_interval
on scheduler_config
for each row
declare
pragma autonomous_transaction;
begin
-- Note: throws an exception if no such job
dbms_scheduler.set_attribute(name => :new.job_name,
attribute => 'repeat_interval',
value => :new.repeat_interval);
end;
/
show errors
--
-- a simple job we want to schedule
--
create table scheduler_log (
job_name varchar2(100),
time timestamp(3),
text varchar2(4000)
);
begin
dbms_scheduler.create_job(
job_name => 'logger1',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN insert into scheduler_log values(''logger1'', systimestamp, ''Executed!''); commit; END;',
start_date => systimestamp,
repeat_interval => 'FREQ=SECONDLY; BYSECOND=30',
end_date => null,
enabled => true,
comments => 'Testing configuration');
end;
/
--
-- check how much work has been done and when
--
col job_name for a10
col time for a25
col text for a20
select * from scheduler_log order by time;
--
-- I want more job for my money !
--
update scheduler_config
set repeat_interval = 'FREQ=SECONDLY; INTERVAL=10'
where job_name = 'logger1';
commit;
--
-- remove the job
--
exec dbms_scheduler.drop_job('logger1')