alexk23
asked on
Utilize DBMS_JOB.SUBMIT to schedule daily job.
Hi,
I have following SQL statement that I need to run every day at midnight. What is the best way of scheduling it with DBMS_JOB.SUBMIT?
UPDATE SYS.TEST_IUB_CD_APPLICATIO N SET STATUS = '5'
WHERE APPLICANT_ID IN
(SELECT distinct APPLICANT_ID FROM SYS.TEST_IUB_CD_APPLICATIO N WHERE PURGE_DATE < TRUNC(SYSDATE));'
I have following SQL statement that I need to run every day at midnight. What is the best way of scheduling it with DBMS_JOB.SUBMIT?
UPDATE SYS.TEST_IUB_CD_APPLICATIO
WHERE APPLICANT_ID IN
(SELECT distinct APPLICANT_ID FROM SYS.TEST_IUB_CD_APPLICATIO
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
please try this:
exec DBMS_JOB.SUBMIT(:Jobno, 'UPDATE SYS.TEST_IUB_CD_APPLICATIO N SET STATUS = "5" WHERE APPLICANT_ID IN
(SELECT distinct APPLICANT_ID FROM SYS.TEST_IUB_CD_APPLICATIO N WHERE PURGE_DATE < TRUNC(SYSDATE));',
trunc(sysdate),trunc(sysda te)+1);');
commit;
end;
exec DBMS_JOB.SUBMIT(:Jobno, 'UPDATE SYS.TEST_IUB_CD_APPLICATIO
(SELECT distinct APPLICANT_ID FROM SYS.TEST_IUB_CD_APPLICATIO
trunc(sysdate),trunc(sysda
commit;
end;
you should use two single quotes '' whenever a single quote ' appears inside a string.
Use as angelIII has given.
Use as angelIII has given.
ASKER
Something is still not right when query ran:
variable Jobno number;
exec DBMS_JOB.SUBMIT(:Jobno, 'UPDATE SYS.TEST_IUB_CD_APPLICATIO N SET STATUS = "5" WHERE APPLICANT_ID IN
(SELECT distinct APPLICANT_ID FROM SYS.TEST_IUB_CD_APPLICATIO N WHERE PURGE_DATE < TRUNC(SYSDATE));',
trunc(sysdate),trunc(sysda te)+1);');
commit;
end;
ERROR:
ORA-01756: quoted string not properly terminated
(SELECT distinct APPLICANT_ID FROM SYS.TEST_IUB_CD_APPLICATIO N WHERE PURGE_DATE < TRUNC(SYSDATE));',
*
ERROR at line 1:
ORA-00911: invalid character
variable Jobno number;
exec DBMS_JOB.SUBMIT(:Jobno, 'UPDATE SYS.TEST_IUB_CD_APPLICATIO
(SELECT distinct APPLICANT_ID FROM SYS.TEST_IUB_CD_APPLICATIO
trunc(sysdate),trunc(sysda
commit;
end;
ERROR:
ORA-01756: quoted string not properly terminated
(SELECT distinct APPLICANT_ID FROM SYS.TEST_IUB_CD_APPLICATIO
*
ERROR at line 1:
ORA-00911: invalid character
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
variable Jobno number;
exec DBMS_JOB.SUBMIT(:Jobno,'UP DATE SYS.TEST_IUB_CD_APPLICATIO N SET STATUS = "5" WHERE APPLICANT_ID IN (SELECT distinct APPLICANT_ID FROM SYS.TEST_IUB_CD_APPLICATIO N WHERE PURGE_DATE < TRUNC(SYSDATE));',trunc(sy sdate),tru nc(sysdate )+1);
commit;
Try this out.
exec DBMS_JOB.SUBMIT(:Jobno,'UP
commit;
Try this out.
variable Jobno number;
exec DBMS_JOB.SUBMIT(:Jobno,'UP DATE SYS.TEST_IUB_CD_APPLICATIO N SET STATUS = ''5'' WHERE APPLICANT_ID IN (SELECT distinct APPLICANT_ID FROM SYS.TEST_IUB_CD_APPLICATIO N WHERE PURGE_DATE < TRUNC(SYSDATE));',trunc(sy sdate),tru nc(sysdate )+1);
commit;
Try this out.
exec DBMS_JOB.SUBMIT(:Jobno,'UP
commit;
Try this out.
ASKER
Re-ran recommended statement. What does ORA-23319: parameter value "13-DEC-06" is not appropriate error mean?
SQL> !cat abc.sql
variable Jobno number;
exec DBMS_JOB.SUBMIT(:Jobno,'UP DATE SYS.TEST_IUB_CD_APPLICATIO N SET STATUS = ''5'' WHERE APPLICANT_ID IN (SELECT distinct APPLICANT_ID FROM SYS.TEST_IUB_CD_APPLICATIO N WHERE PURGE_DATE < TRUNC(SYSDATE));',trunc(sy sdate),tru nc(sysdate )+1);
commit;
end;
/
SQL> @abc.sql
BEGIN DBMS_JOB.SUBMIT(:Jobno,'UP DATE SYS.TEST_IUB_CD_APPLICATIO N SET STATUS = ''5'' WHERE APPLICANT_ID IN (SELECT distinct APPLICANT_ID FROM SYS.TEST_IUB_CD_APPLICATIO N WHERE PURGE_DATE < TRUNC(SYSDATE));',trunc(sy sdate),tru nc(sysdate )+1); END;
*
ERROR at line 1:
ORA-23319: parameter value "13-DEC-06" is not appropriate
ORA-06512: at "SYS.DBMS_JOB", line 57
ORA-06512: at "SYS.DBMS_JOB", line 134
ORA-06512: at line 1
SQL> !cat abc.sql
variable Jobno number;
exec DBMS_JOB.SUBMIT(:Jobno,'UP
commit;
end;
/
SQL> @abc.sql
BEGIN DBMS_JOB.SUBMIT(:Jobno,'UP
*
ERROR at line 1:
ORA-23319: parameter value "13-DEC-06" is not appropriate
ORA-06512: at "SYS.DBMS_JOB", line 57
ORA-06512: at "SYS.DBMS_JOB", line 134
ORA-06512: at line 1
http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96612/d_job2.htm#1001490
use the above url for your reference.
variable Jobno number;
exec DBMS_JOB.SUBMIT(:Jobno,'UP DATE SYS.TEST_IUB_CD_APPLICATIO N SET STATUS = ''5'' WHERE APPLICANT_ID IN (SELECT distinct APPLICANT_ID FROM SYS.TEST_IUB_CD_APPLICATIO N WHERE PURGE_DATE < TRUNC(SYSDATE));',trunc(sy sdate),'sy sdate+1');
commit;
The 4th argument should be varchar2 not date data type.
use the above url for your reference.
variable Jobno number;
exec DBMS_JOB.SUBMIT(:Jobno,'UP
commit;
The 4th argument should be varchar2 not date data type.
ASKER
Here is what I put together, as recommended by examples provided.
SQL> !cat abc.sql
variable Jobno number;
exec DBMS_JOB.SUBMIT(:Jobno, 'UPDATE SYS.TEST_IUB_CD_APPLICATIO
WHERE APPLICANT_ID IN
(SELECT distinct APPLICANT_ID FROM SYS.TEST_IUB_CD_APPLICATIO
trunc(sysdate),trunc(sysda
commit;
end;
/
SQL> @abc.sql
ERROR:
ORA-01756: quoted string not properly terminated
SP2-0734: unknown command beginning "WHERE APPL..." - rest of line ignored.
ERROR:
ORA-01756: quoted string not properly terminated
Please advise.