I'm attempting to create a job using DBMS_SCHEDULER in an Oracle 11g DB but having some trouble setting the job class attribute. I have already looked in the SYS schema and there is a job class named "SCHED$_LOG_ON_ERRORS_CLASS" that only outputs to the log if a job fails, which is what I want instead of having it log every time the job succeeds. Here is the script I am using to create the job:
BEGIN
DBMS_SCHEDULER.CREATE_JOB(
job_name => 'DIRXML.CHECK_EVENTLOG',
job_type => 'STORED_PROCEDURE',
job_action => 'DIRXML.P_Check_Eventlog',
job_class => 'DIRXML.SCHED$_LOG_ON_ERRORS_CLASS',
repeat_interval => 'FREQ=SECONDLY;INTERVAL=30',
enabled => TRUE
);
END;
/
The script will execute without errors if I remove the job_class attribute but when I add it I get the following error:
ORA-27476: "SYS.SCHED$_LOG_ON_ERRORS_CLASS" does not exist ORA-06512:
at "SYS.DBMS_ISCHED", line 124 ORA-06512: at "SYS.DBMS_SCHEDULER",
line 271 ORA-06512: at line 2
The only thing I could think of is that permissions aren't set up correctly for my user?
It looks like there wasn't a public execute grant on that specific job class, which explains why it wasn't finding it.
Related
I have set in ORDS without APEX when I try to enable the schema, I get an error. What am I doing wrong?
BEGIN
ORDS.ENABLE_SCHEMA(p_enabled => TRUE,
p_schema => 'DEVUSER',
p_url_mapping_type => 'BASE_PATH',
p_url_mapping_pattern => 'devuser',
p_auto_rest_auth => FALSE);
commit;
END;
Error report -
ORA-20024: REST enablement for maintained schema disallowed : DEVUSER
ORA-06512: на "ORDS_METADATA.ORDS", line 183
ORA-06512: на "ORDS_METADATA.ORDS_INTERNAL", line 281
ORA-06512: на "ORDS_METADATA.ORDS_INTERNAL", line 688
ORA-06512: на "ORDS_METADATA.ORDS_INTERNAL", line 640
ORA-06512: на "ORDS_METADATA.ORDS_INTERNAL", line 779
ORA-06512: на "ORDS_METADATA.ORDS", line 167
ORA-06512: на line 3
The most probable cause is because the schema has been created as an Oracle Maintained user. An Oracle Maintained user cannot be enabled for ORDS based REST services.
In order to correct this problem, you must delete and recreate the target schema.
1.To drop the user:
alter session set "_ORACLE_SCRIPT"=true;
drop user DEVUSER;
alter session set "_ORACLE_SCRIPT"=false;
2.Recreate the user:
create user DEVUSER identified by <PASSWORD>;
grant create session to <SCHEMA>;
Perform any other grants needed for this user. If you have data to save, export it first ( using Datapump, for example ) and import it back again.
ORA-20010: DBMS_STATS INTERNAL ERROR in fill_cstats : both dmin/dmax and nmin/nmax are null for table SOA, column KEY , ssize 29892
ORA-06512: at "MOSTI", line 165
ORA-06512: at line 1
The above error occurred in production, can someone please explain why it has occurred and solution?
It seems due to an oracle internal bug.
ORA-20010: DBMS_STATS INTERNAL ERROR In Fill_cstat During Analyze A
Table (文档 ID 2247315.1)
Getting following error when gathering the table statistics:
EXEC DBMS_STATS.gather_table_stats(ownname => 'S', tabname => 'TEST',
estimate_percent => 100, cascade => TRUE, granularity=> 'ALL', degree
=> 2, no_invalidate=>FALSE);
* ERROR at line 1: ORA-20010: DBMS_STATS INTERNAL ERROR in fill_cstats : both dmin/dmax and nmin/nmax are null for table S.TEST , column
FIRST_NAME , ssize 430241 ORA-06512: at "SYS.DBMS_STATS", line 34757
ORA-06512: at line 1
The bug is fixed in 12.2
Workaround for the bug is to delete statistics and re-gather statistics
If the above workaround does not work, another potential workaround is using parallel degree of 1:
SYS#EXEC DBMS_STATS.gather_table_stats(ownname => 'SCOTT', tabname => 'TEST', estimate_percent => 100, cascade => TRUE, degree => 1);
but it matches oracle 12.1
I want to create a trigger in Oracle 11g. The problem is that I want a trigger which runs every time when there is a SELECT statement. Is this possible or is there other way to achieve the same result. This is the PL/SQL block:
CREATE TRIGGER time_check
BEFORE INSERT OR UPDATE OF users, passwd, last_login ON table
FOR EACH ROW
BEGIN
delete from table where last_login < sysdate - 30/1440;
END;
I'm trying to implement a table where I can store user data. I want to "flush" the rows which are old than one hour. Are there other alternatives to how I could implement this?
p.s Can you tell me is this PL/SQL block is correct. Are there any mistakes?
BEGIN
sys.dbms_scheduler.create_job(
job_name => '"ADMIN"."USERSESSIONFLUSH"',
job_type => 'PLSQL_BLOCK',
job_action => 'begin
-- Insert PL/SQL code here
delete from UserSessions where last_login < sysdate - 30/1440;
end;',
repeat_interval => 'FREQ=MINUTELY;INTERVAL=2',
start_date => systimestamp at time zone 'Asia/Nicosia',
job_class => '"DEFAULT_JOB_CLASS"',
comments => 'Flushes expired user sessions',
auto_drop => FALSE,
enabled => FALSE);
sys.dbms_scheduler.set_attribute( name => '"ADMIN"."USERSESSIONFLUSH"', attribute => 'job_priority', value => 5);
sys.dbms_scheduler.set_attribute( name => '"ADMIN"."USERSESSIONFLUSH"', attribute => 'logging_level', value => DBMS_SCHEDULER.LOGGING_FAILED_RUNS);
sys.dbms_scheduler.enable( '"ADMIN"."USERSESSIONFLUSH"' );
END;
I'm not aware of a way of having a trigger on select. From the documentation, the only statements you can trigger on are insert/delete/update (and some DDL).
For what you want to do, I would suggest a simpler solution: use the DBMS_SCHEDULER package to schedule a cleanup job every so often. It won't add overhead to your select queries, so it should have less performance impact globally.
You'll find lots of examples in: Examples of Using the Scheduler
I'd like to create ddl scripts for most of my database objects. dbms_metadata.get_ddl works for most of the object types. For instance the following creates the ddl for a view:
select dbms_metadata.get_ddl ( 'VIEW', 'SAMPLE_VIEW') from dual
On the other hand it's not working for object_type 'JOB'. The following:
select dbms_metadata.get_ddl( 'JOB', 'SAMPLE_JOB' ) from dual
gives the following error:
ORA-31604: invalid NAME parameter "NAME" for object type JOB in function SET_FILTER
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 116
ORA-06512: at "SYS.DBMS_METADATA_INT", line 4705
ORA-06512: at "SYS.DBMS_METADATA_INT", line 8582
ORA-06512: at "SYS.DBMS_METADATA", line 2882
ORA-06512: at "SYS.DBMS_METADATA", line 2748
ORA-06512: at "SYS.DBMS_METADATA", line 4333
ORA-06512: at line 1
If I list my jobs using
select * from user_objects where object_type='JOB'
it shows SAMPLE_JOB (just like it shows SAMPLE_VIEW if filtered for object_type='VIEW').
Why is it working for VIEW (and TABLE, INDEX, TRIGGER, ...) and not for JOB?
I'm using Oracle 10g.
select dbms_metadata.get_ddl('PROCOBJ', 'yourJobNameGoesHere') from dual;
PROCOBJ's are procedural objects.
select dbms_metadata.get_ddl('PROCOBJ',['JOB'|'PROGRAM'|'SCHEDULE'],'OWNER') from dual;
The PROCOBJ can be JOB, PROGRAM and SCHEDULE.
Alternative, get all jobs from the database with their DDL:
select owner, job_name, dbms_metadata.get_ddl('PROCOBJ', job_name, owner) as ddl_output from ALL_SCHEDULER_JOBS
Even I tried all above to get DDL in Oracle version 10g, but no success.
Here is what I figure out to get the detail of the job:
set pages 200 lines 200
col owner format a20
col job_name format a25
col JOB_ACTION format a75
col COMMENTS format a60
select owner, job_name, next_run_date, state, enabled from dba_scheduler_jobs where job_name like '%AUDIT%';
-- get the detail of scheduled jobs.
select OWNER,JOB_NAME, JOB_ACTION, COMMENTS FROM DBA_SCHEDULER_JOBS where JOB_NAME='PURGE_AUDIT_LOG';
-- get the limited detail from the selected column.
select * FROM DBA_SCHEDULER_JOBS where JOB_NAME='PURGE_AUDIT_LOG';
-- to get the complete detail of a specific job along with code and other details.
We have a system that allows users interfacing data into the database to set up various rules that are used to alter data before it is merged in to the main table. For example, an order might have a rule that sets up what delivery company to use based on a customer's address.
This is originally intended to operate only on the data being loaded in, so it's limited to functions that you can call from a select statement. An important point to note is that the data is not in the destination table yet.
Now, I have a project that requires an update to another table (fine - I can use an autonomous_transaction pragma for that). However, there are some functions I need to run that require the data to be inserted before they run (i.e. they are aggregating data).
So, I really want to just queue up running my procedure till some time later (it's not time dependent).
How do I do that in Oracle? The wealth of documentation is rather overwhelming when I just want to do something simple.
BEGIN
DBMS_SCHEDULER.create_job (
job_name => 'daily_tasks_job',
job_type => 'STORED_PROCEDURE',
job_action => 'prc_daily_tasks',
repeat_interval => 'FREQ=DAILY; INTERVAL=1',
enabled => TRUE,
comments => 'Calls stored procedure once a day'
);
END;
BEGIN
DBMS_SCHEDULER.create_job(
job_name => 'SHELL_JOB',
repeat_interval => 'FREQ=DAILY; BYHOUR=2',
job_type => 'EXECUTABLE',
job_action => '/u01/app/oracle/admin/tools/shell_job.sh',
enabled => TRUE,
comments => 'Perform stuff'
);
END;
The standard aproach for this would be to use dbms_jobs to schedule a job calling the procedure.
If there is some precondition, the job could check the precondition. If it is fulfilled, the job continues, if not it reschedules itself and exit.