Error while changing job_class attribute in jobs - oracle

I have created a job_class having logging level as FULL.
SQL syntax for the same is :
BEGIN
dbms_scheduler.create_job_class(job_class_name => 'full_job_class',
comments => 'Job class having logging level as full.',
logging_level => dbms_scheduler.logging_full);
END;
Now I am trying to change attribute for all the listed JOB in my DB to set its job_class attribute to the newly created job_class.
SQL syntax for the same:
DECLARE
vs_statement VARCHAR2(100);
CURSOR c1 IS
SELECT '''' || owner || '.' || job_name || '''' as job_name
FROM dba_scheduler_jobs d
WHERE owner NOT IN ('SYS', 'DBSNMP', 'ORACLE_OCM', 'SYSTEM');
BEGIN
FOR rec IN c1 LOOP
execute immediate ('BEGIN dbms_scheduler.set_attribute(NAME => '||rec.job_name||', attribute => ''JOB_CLASS'', VALUE => ''FULL_JOB_CLASS''); END;');
END LOOP;
END;
But while running this code I am getting now and than below error:
ORA-27470: failed to re-enable "WEB"."REFRESH_PERFORMANCE" after making requested change
ORA-27476: "SYS"."FULL_JOB_CLASS" does not exist
ORA-06512: at "SYS.DBMS_ISCHED", line 4648
ORA-06512: at "SYS.DBMS_SCHEDULER", line 3052
ORA-06512: at line 1
But when I am executing one at a time to change job's attribute to set its job_class then I don't get any error.

Make sure you grant the EXECUTE object privilege as SYS to the schema attempting to make the change.
GRANT EXECUTE ON SYS.FULL_JOB_CLASS TO {JOB_OWNER};

Related

ORA-31011: XML parsing failed on function condition

On a client's database (which I do not have physical access to) we are getting some strange results when joining to a function.
I was able to guide them to replicate the issue on a completely new schema within the same database.
create or replace function GEN_FILENAME(p_file_name varchar2) return varchar2
is
l_filename varchar2(100);
begin
l_filename := 'Test' || '/' || 'Test' || '.' || initcap(p_file_name) || '.txt';
return l_filename;
end GEN_FILENAME;
/
The function generates the following error if I use equals on a join, but is fine when I use a sub select for the function.
ORA-00604: error occurred at recursive SQL level 1
ORA-31011: XML parsing failed
ORA-19213: error occurred in XML processing at lines 1
LPX-00007: unexpected end-of-file encountered
00604. 00000 - "error occurred at recursive SQL level %s"
*Cause: An error occurred while processing a recursive SQL statement
(a statement applying to internal dictionary tables).
*Action: If the situation described in the next error on the stack
-- this query does not work
select dt.file_name,
GEN_FILENAME(dt.file_name) as file_name,
mf.file_path
from ( select 'Test' FOLDER,
'Test' AREA,
'File_Name' FILE_NAME,
systimestamp LAST_MODIFIED
from dual
) dt
left outer join (select 'Test/Test.File_Name.txt' file_path from dual) mf on mf.file_path = GEN_FILENAME(dt.file_name);
-- this query is working
select dt.file_name,
GEN_FILENAME(dt.file_name) as file_name,
mf.file_path
from ( select 'Test' FOLDER,
'Test' AREA,
'File_Name' FILE_NAME,
systimestamp LAST_MODIFIED
from dual
) dt
left outer join (select 'Test/Test.File_Name.txt' file_path from dual) mf on mf.file_path = (select GEN_FILENAME(dt.file_name) from dual);
I have seen other odd issues as well. I have asked them to gather statistics of the tables in the schema.
begin
for i in (select TABLE_NAME from USER_TABLES) loop
--Gather Table Statistics
sys.dbms_stats.gather_table_stats ( ownname => 'TEST', tabname => i.TABLE_NAME, cascade => true);
end loop;
end;
/
This resulted in the following error:
ORA-20000: Unable to analyze TABLE "TEST"."LOGMNR_SESSION_EVOLVE$", insufficient privileges or does not exist
ORA-06512: at "SYS.DBMS_STATS", line 40751
ORA-06512: at "SYS.DBMS_STATS", line 40024
ORA-06512: at "SYS.DBMS_STATS", line 40183
ORA-06512: at "SYS.DBMS_STATS", line 40732
ORA-06512: at line 5
ORA-06512: at line 5
I think this is all related, but I have never seen this type of issues before.
Any ideas?

CREATE TABLE INSIDE PROCEDURE

I can't seem to create the table inside this procedure. I read it online that for any DDL, I need to use EXECUTE IMMEDIATE and tried following few examples online. However, even after trying several solutions it keeps failing. '
Error ""ORA-00904: "End": invalid identifier ORA-06512: at
"EXTRACT_AUTOMATED_CHECKS", line 89 "
CREATE OR REPLACE PROCEDURE EXTRACT_AUTOMATED_CHECKS AS
BEGIN
--DROP TABLE
BEGIN
EXECUTE IMMEDIATE ('DROP TABLE extract_checks') ;
EXCEPTION
WHEN OTHERS THEN NULL;
END;
--CREATE TABLE, INDEX
--TABLE
BEGIN
EXECUTE IMMEDIATE 'CREATE TABLE extract_checks
(
Card number(19) NOT NULL PRIMARY KEY
,Customer_Id number(19)
)';
COMMIT;
END;
--INDEX
BEGIN
EXECUTE IMMEDIATE('CREATE INDEX IDX_EXT_CHECKS extract_checks(Customer_Id)');
COMMIT;
END;
SOURCE.DBA_SEND_MAIL(
V_FROM=>'Notification#Company.com;',
V_RECIPIENT => 'employee#company.com',
V_SUBJECT => 'Automated Checks Completed',
V_MESSAGE => 'Automated Checks Completed' );
EXCEPTION WHEN OTHERS THEN
SOURCE.DBA_SEND_MAIL(
V_FROM=>'Notification#Company.com;',
V_RECIPIENT => 'employee#company.com',
V_SUBJECT => 'Automated Checks Failed',
V_MESSAGE => 'Automated Checks Failed' );
RAISE;
END EXTRACT_AUTOMATED_CHECKS;
There is no issue with CREATE TABLE.
you missed ; at the end of last call to send mail in exception block.
SOURCE.DBA_SEND_MAIL(
V_FROM=>'Notification#Company.com;',
V_RECIPIENT => 'employee#company.com',
V_SUBJECT => 'Automated PX Checks Failed',
V_MESSAGE => 'Automated PX Checks Failed' ); <<-- this ; is missing
Cheers!!

Oracle DBMS_FGA dynamically create an audit trail or policy

my goal is to run a select to a table and based on the certain rows dynamically create an audit trail or policy on them.
so..
create a set_policy function that gets called/Looped:
create or replace
function set_policy
( sch VARCHAR2 ,
tab VARCHAR2,
colm VARCHAR2,
pred VARCHAR2,
emailer VARCHAR2
)
return VARCHAR2 is
policy_sql_stmt varchar2(1000);
BEGIN
policy_sql_stmt :=
'BEGIN
SYS.DBMS_FGA.ADD_POLICY (
object_schema => :s,
object_name => :t,
policy_name => ''CHK_:s_:t'',
audit_column => :c,
audit_condition => :p,
handler_schema => ''SYSADMIN_FGA'',
handler_module => '''||emailer||'(:s,:t,''''CHK_:s_:t'''')'',
enable => TRUE,
statement_types => ''SELECT, UPDATE'',
audit_trail => SYS.DBMS_FGA.DB + SYS.DBMS_FGA.EXTENDED);
END;';
--DBMS_OUTPUT.PUT_LINE('policy_sql_stmt = :' || policy_sql_stmt);
BEGIN
EXECUTE IMMEDIATE policy_sql_stmt USING sch,tab,colm,pred;
--EXECUTE IMMEDIATE policy_sql_stmt USING pred;
EXCEPTION
WHEN OTHERS THEN
BEGIN
--dbms_output.put_line('set_policy error code: '||SQLCODE);
--dbms_output.put_line(DBMS_UTILITY.FORMAT_CALL_STACK);
RETURN ('set_policy error code: '||SQLCODE);
END;
END;
RETURN 'success';
END;
Then a procedure that calls the function...
CREATE OR REPLACE PROCEDURE audit_slac_tables
AS
--DECLARE
emailer VARCHAR2(40):='audit_email_alert';
isSuccess VARCHAR2(40);
CURSOR myCursor
IS
SELECT SCHEMA AS sch,
TABLE_NAME AS tab,
FILTER_COLUMN AS colm,
WHERE_COND AS pred
FROM SLAC_REDACTION_TABLE slac;
--WHERE slac.table_name IN ('RECIPIENT','CARD');
BEGIN
FOR curRec IN myCursor
LOOP
BEGIN
--emailer := getEmailer(curRec.sch ,curRec.tab);
isSuccess := set_policy(curRec.sch ,curRec.tab, curRec.colm, curRec.pred, emailer);
DBMS_OUTPUT.PUT_LINE('Proc isSuccess = :' || isSuccess);
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Proc error code: '||SQLCODE);
dbms_output.put_line('Proc error msg: '||SQLERRM);
--dbms_output.put_line(DBMS_UTILITY.FORMAT_CALL_STACK);
--dbms_output.put_line('================================================');
CONTINUE;
END;
--dbms_output.put_line('================================================');
END LOOP;
COMMIT;
END audit_slac_tables;
if I call it...
exec AUDIT_SLAC_TABLES;
I get the following bewildering error
Error starting at line : 6 in command -
exec AUDIT_SLAC_TABLES
Error report -
ORA-06550: line 12, column 18:
PLS-00201: identifier 'SYS.DBMS_FGA' must be declared
ORA-06550: line 2, column 3:
PL/SQL: Statement ignored
ORA-06512: at "GAPLITE.SET_POLICY", line 51
ORA-06512: at "GAPLITE.AUDIT_SLAC_TABLES", line 27
ORA-06512: at line 1
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Why a reference problem where the script DBMS_FGA.ADD_POLICY never had a problem?
I can run this script ( listed 1st above ) but not dynamically... it loses trhe contextual reference to the SYS packages somehow ??

ORA-29278: SMTP transient error: Service not available when running UTL_MAIL

We are planning to install the UTL_MAIL Package and we're currently testing the installation steps in our Development Environment.
After sucessfully installing the UTL_MAIL Package Scripts and creating the sufficient PUBLIC Synonyms and Grants,
we are getting the error ORA-29278 when running the test Anonymous Block below:
BEGIN
UTL_MAIL.SEND(sender => 'xxx#oracle.com'
, recipients => 'Migs.Isip.23#gmail.com'
, subject => 'Testmail'
, message => 'Hello');
END;
Full Details of the error Message:
ORA-29278: SMTP transient error: 421 4.3.2 Service not available
ORA-06512: at "SYS.UTL_MAIL", line 662
ORA-06512: at "SYS.UTL_MAIL", line 679
ORA-06512: at line 3
29278. 00000 - "SMTP transient error: %s"
*Cause: A SMTP transient error occurred.
*Action: Correct the error and retry the SMTP operation.
As per research from related links (Send Email Using PLSQL),
i may need to setup the proper access control list (ACL) for this to work. However, upon executing the script below, i'm still getting the same error.
DECLARE
-- ACL name to be used for email access reuse the same value for all
-- future calls
l_acl VARCHAR2 (30) := 'utl_smtp.xml';
-- Oracle user to be given permission to send email
l_principal VARCHAR2 (30) := 'APPS';
-- Name of email server
g_mailhost VARCHAR2 (60) := 'smtprelay.xxxxx.com';
l_cnt INTEGER;
PROCEDURE validate_smtp_server
AS
l_value v$parameter.VALUE%TYPE;
l_parameter v$parameter.name%TYPE := 'smtp_out_server';
BEGIN
SELECT VALUE
INTO l_value
FROM v$parameter
WHERE name = l_parameter;
IF l_value IS NULL
THEN
raise_application_error (
-20001
, 'Oracle parameter '
|| l_parameter
|| ' has not been set'
|| UTL_TCP.crlf
|| 'it s/b smtprelay.alorica.com'
);
END IF;
DBMS_OUTPUT.put_line ('parameter ' || l_parameter || ' value is ' || l_value);
END validate_smtp_server;
PROCEDURE create_if_needed (p_acl IN VARCHAR2)
AS
l_cnt INTEGER;
BEGIN
SELECT COUNT (*) c
INTO l_cnt
FROM dba_network_acls a
WHERE SUBSTR (acl, INSTR (acl, '/', -1) + 1) = p_acl;
IF l_cnt = 0
THEN
DBMS_OUTPUT.put_line ('creating acl ' || p_acl);
DBMS_NETWORK_ACL_ADMIN.create_acl (
acl => p_acl
, description => 'Allow use of utl_smtp'
, principal => l_principal
, is_grant => TRUE
, privilege => 'connect'
);
DBMS_NETWORK_ACL_ADMIN.assign_acl (acl => p_acl, HOST => g_mailhost);
COMMIT;
ELSE
DBMS_OUTPUT.put_line (p_acl || ' acl already exists');
END IF;
END create_if_needed;
PROCEDURE add_if_needed (
p_principal IN VARCHAR2
, p_acl IN VARCHAR2
)
AS
l_cnt INTEGER;
BEGIN
SELECT COUNT (*) c
INTO l_cnt
FROM dba_network_acl_privileges
WHERE SUBSTR (acl, INSTR (acl, '/', -1) + 1) = p_acl
AND principal = p_principal;
IF l_cnt = 0
THEN
DBMS_NETWORK_ACL_ADMIN.add_privilege (
acl => 'utl_smtp.xml'
, principal => p_principal
, is_grant => TRUE
, privilege => 'connect'
);
COMMIT;
DBMS_OUTPUT.put_line ('access to ' || p_acl || ' added for ' || p_principal);
ELSE
DBMS_OUTPUT.put_line (p_principal || ' already has access to ' || p_acl);
END IF;
END add_if_needed;
BEGIN
EXECUTE IMMEDIATE 'grant execute on utl_mail to ' || l_principal;
create_if_needed (p_acl => l_acl);
add_if_needed (p_principal => l_principal, p_acl => l_acl);
DBMS_OUTPUT.put_line ('Verification SQL:');
DBMS_OUTPUT.put_line (' SELECT * FROM dba_network_acls;');
DBMS_OUTPUT.put_line (' SELECT * FROM dba_network_acl_privileges;');
COMMIT;
validate_smtp_server;
END;
What other steps can i take or what other instructions do i need to provide to the DBAs for this?
Oracle Database Version:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
"CORE 11.2.0.4.0 Production"
TNS for Solaris: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production
Thank you very much.
I was able to resolve this by contacting our System Administrator and asking for the details of the Mail Server.
Turns out, if we'll only be sending the email internally, we are advised to use a different server mail.xxx.xxx.xxxx since its not going to be blocked by the firewall.
On the other hand, if we'll be sending email externally, another server is involved smtprelay.xxxxx.com
and this involves an extra step of Whitelisting the External Servers to be sent to.
As i checked in V$PARAMETER, we were using the smtprelay.xxxxx.com server and decided to try the other server mail.xxx.xxx.xxxx.
I issued the Alter command as below:
alter system set smtp_out_server = 'mail.xxx.xxx.xxxx';
and ran the anonymous block and was able to recieve the email successfully.
BEGIN
UTL_MAIL.SEND(sender => 'xxx#oracle.com'
, recipients => 'Migs.Isip.23#gmail.com'
, subject => 'Testmail'
, message => 'Hello');
END;
I came up with SMTP email challenges for 19c database. I was able to solve it. Below is the complete solution:-
Give grant to corresponding schema name for utl_tcp,utl_smtp and utl_http.
grant execute on utl_tcp to schemaname;
grant execute on utl_smtp to schemaname;
grant execute on utl_http to schemaname;
CREATE_ACL using DBMS_NETWORK_ACL_ADMIN sys package:-
BEGIN
DBMS_NETWORK_ACL_ADMIN.CREATE_ACL (
acl => '/sys/acls/utl_http.xml',
description => 'Allowing SMTP Connection',
principal => 'SCHEMANAME',
is_grant => TRUE,
privilege => 'connect',
start_date => SYSTIMESTAMP,
end_date => NULL);
COMMIT;
END;
/
ADD_PRIVILEGE to schema using DBMS_NETWORK_ACL_ADMIN package:-
BEGIN
DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(
acl => '/sys/acls/utl_http.xml',
principal => 'SCHEMANAME',
is_grant => true,
privilege => 'resolve');
COMMIT;
END;
/
ASSIGN_ACL to mail server using DBMS_NETWORK_ACL_ADMIN package:-
BEGIN
DBMS_NETWORK_ACL_ADMIN.ASSIGN_ACL (
acl => '/sys/acls/utl_http.xml',
host => 'mailhostname');
COMMIT;
END;
/

How to present job_name to DBMS_SCHEDULER.ADD_JOB_EMAIL_NOTIFICATION

I am having trouble adding email notifications to Oracle 11g (11.2.0.1.0). It seems like a bug but I'm really not sure. I've tried doing this using SQL Developer to build the code as well as examples from the internet but it's not working.
I can create and enable a job easily enough:
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => '"SCHEMA"."test1"',
job_type => 'PLSQL_BLOCK',
job_action => 'begin
null;
end;
',
auto_drop => FALSE
);
DBMS_SCHEDULER.enable(
name => '"SCHEMA"."test1"');
END;
/
anonymous block completed
As a precaution, I remove the job email notification - this works.
BEGIN
DBMS_SCHEDULER.REMOVE_JOB_EMAIL_NOTIFICATION (
job_name => '"SCHEMA"."test1"'
);
end;
/
anonymous block completed
But when I try to add an email notification it's as if it can't find the object, I'm working in my own schema and have the DBA role so I would have thought any potential permission issues should be overcome (though in my own schema I would have assumed I could make scheduled jobs easily enough)
BEGIN
DBMS_SCHEDULER.ADD_JOB_EMAIL_NOTIFICATION (
job_name => '"SCHEMA"."test1"',
recipients => 'email_address#test.com',
events => 'JOB_BROKEN, JOB_CHAIN_STALLED, JOB_FAILED, JOB_OVER_MAX_DUR, JOB_SCH_LIM_REACHED'
);
END;
/
ORA-27476: "SCHEMA.SCHEMA" does not exist
ORA-06512: at "SYS.DBMS_ISCHED", line 4856
ORA-06512: at "SYS.DBMS_ISCHED", line 7117
ORA-01403: no data found
ORA-06512: at "SYS.DBMS_SCHEDULER", line 4030
ORA-06512: at line 3
Note it says SCHEMA.SCHEMA as if it didn't read the line properly. When I change it from '"SCHEMA"."test1"' to 'test1' it still doesn't work but says ORA-27476: "SCHEMA.TEST1" does not exist.
All my jobs work correctly and behave and I have gotten a UTL_MAIL implementation going but I'd really like to get the oracle stuff working for simplicity if possible.
A possible issue is that by default object names in Oracle are case insensitive, unless you surround them with double quotes.
Here is a test case:
SQL> select * from v$version where rownum = 1;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
SQL> create user STACKOVERFLOW identified by STACKOVERFLOW;
User created.
SQL> grant connect, create job to STACKOVERFLOW;
Grant succeeded.
SQL> conn STACKOVERFLOW/STACKOVERFLOW
SQL> l
1 BEGIN
2 DBMS_SCHEDULER.CREATE_JOB (
3 job_name => '"STACKOVERFLOW"."test1"',
4 job_type => 'PLSQL_BLOCK',
5 job_action => 'begin
6 null;
7 end;
8 ',
9 auto_drop => FALSE
10 );
11 DBMS_SCHEDULER.enable(
12 name => '"STACKOVERFLOW"."test1"');
13* END;
SQL> /
PL/SQL procedure successfully completed.
If you name your job "test1" Oracle will create it with a lowercase name. You can confirm this by checking the catalog view dba_scheduler_jobs:
SQL> select owner, job_name from dba_scheduler_jobs where job_name = 'TEST1';
no rows selected
SQL> select owner, job_name from dba_scheduler_jobs where job_name = 'test1';
OWNER JOB_NAME
------------------------------ ------------------------------
STACKOVERFLOW test1
Therefore, this will work:
SQL> l
1 BEGIN
2 DBMS_SCHEDULER.ADD_JOB_EMAIL_NOTIFICATION (
3 job_name => '"STACKOVERFLOW"."test1"',
4 recipients => 'email_address#test.com',
5 events => 'JOB_BROKEN, JOB_CHAIN_STALLED, JOB_FAILED, JOB_OVER_MAX_DUR, JOB_SCH_LIM_REACHED'
6 );
7* END;
SQL> /
PL/SQL procedure successfully completed.
But this won't:
SQL> l
1 BEGIN
2 DBMS_SCHEDULER.ADD_JOB_EMAIL_NOTIFICATION (
3 job_name => '"STACKOVERFLOW".TEST1',
4 recipients => 'email_address#test.com',
5 events => 'JOB_BROKEN, JOB_CHAIN_STALLED, JOB_FAILED, JOB_OVER_MAX_DUR, JOB_SCH_LIM_REACHED'
6 );
7* END;
SQL> /
BEGIN
*
ERROR at line 1:
ORA-27476: "STACKOVERFLOW.STACKOVERFLOW" does not exist
ORA-06512: at "SYS.DBMS_ISCHED", line 4921
ORA-06512: at "SYS.DBMS_ISCHED", line 7613
ORA-01403: no data found
ORA-06512: at "SYS.DBMS_SCHEDULER", line 4063
ORA-06512: at line 2

Resources