Rather than hard-coding values dbms_scheduler.create_job repaeat_interval, i'd like to make it configurable. Therefore, I have created a new table that allows the repeat_interval from the job to be configured.
Procedure below takes the column as input parameters:
PROCEDURE scheduled_job IS
v_start_date swpurge_job_config.start_date%TYPE;
v_freq swpurge_job_config.freq%TYPE;
v_byday swpurge_job_config.byday%TYPE;
v_byhour swpurge_job_config.byhour%TYPE;
v_byminute swpurge_job_config.byminute%TYPE;
v_bysecond swpurge_job_config.bysecond%TYPE;
v_end_date swpurge_job_config.end_date%TYPE;
BEGIN
SELECT start_date
,freq
,byday
,byhour
,byminute
,bysecond
,end_date
INTO v_start_date
,v_freq
,v_byday
,v_byhour
,v_byminute
,v_bysecond
,v_end_date
FROM swpurge_job_config;
dbms_scheduler.create_job(job_name => 'Purge_MW_Log_Data'
,job_type => 'STORED_PROCEDURE'
,job_action => 'DBA_UTILS_OWNER.PURGE_TABLES'
,start_date => 'SYSTIMESTAMP'
,repeat_interval => 'freq' || '=' ||
v_freq || '; ' ||
'byday' || '=' ||
v_byday || '; ' ||
'byhour' || '=' ||
v_byhour || '; ' ||
'byminute' || '=' ||
v_byminute || '; ' ||
'bysecond' || '=' ||
v_bysecond || ';'
,end_date => NULL
,enabled => TRUE
,auto_drop => FALSE
,comments => 'runs weekly and looks for partitions that needs to be purged');
END scheduled_job;
Not sure how else to go about this. Any help is appreciated.
error messages:
ORA-01858: a non-numeric character was found where a numeric was expected
ORA-06512: at "DBA_UTILS_OWNER.SWPURGE", line 450 > "dbms_scheduler.create_job(job_name => 'Purge_MW_Log_Data'"
DECLARE
PROCEDURE scheduled_job IS
v_start_date swpurge_job_config.start_date%TYPE;
v_freq swpurge_job_config.freq%TYPE;
v_byday swpurge_job_config.byday%TYPE;
v_byhour swpurge_job_config.byhour%TYPE;
v_byminute swpurge_job_config.byminute%TYPE;
v_bysecond swpurge_job_config.bysecond%TYPE;
--v_end_date swpurge_job_config.end_date%TYPE;
BEGIN
SELECT start_date
,freq
,byday
,byhour
,byminute
,bysecond
-- ,end_date
INTO v_start_date
,v_freq
,v_byday
,v_byhour
,v_byminute
,v_bysecond
-- ,v_end_date
FROM swpurge_job_config;
dbms_scheduler.create_job(job_name => 'Purge_MW_Log_Data'
,job_type => 'STORED_PROCEDURE'
,job_action => 'OWNER.PROCEDURE'
,start_date => v_start_date
,repeat_interval => 'freq' || '=' ||
v_freq || '; ' ||
'byday' || '=' ||
v_byday || '; ' ||
'byhour' || '=' ||
v_byhour || '; ' ||
'byminute' || '=' ||
v_byminute || '; ' ||
'bysecond' || '=' ||
v_bysecond || ';'
,end_date => NULL
,enabled => TRUE
,auto_drop => FALSE
,comments => 'something');
END scheduled_job;
BEGIN
scheduled_job();
END;
/
Issue was the single quotes around start_date. Another important thing to note is v_end_date is not allowed to be parsed in as a parameter in the dbms_scheduler (not sure why) however, this is good enough for me.
Related
It's been a hard time not able to make my code to work with UTL_SMTP package.
Can some one guide me to change below code and make it work with UTL_SMTP method
I created a mailing application which sends mail to all user on their email id's with an attachment.
Took reference and I built it same exactly like this
https://blogs.oracle.com/apex/post/creating-email-campaign-app-with-oracle-apex
My Code :
declare
l_context apex_exec.t_context;
l_emailsidx pls_integer;
l_namesids pls_integer;
l_region_id number;
begin
-- Get the region id for the CUSTOMERS IR region
select region_id
into l_region_id
from apex_application_page_regions
where application_id = :APP_ID
and page_id = 1
and static_id = 'CUSTOMERS';
l_context := apex_region.open_query_context (
p_page_id => 1,
p_region_id => l_region_id );
-- Get the column positions for EMAIL and NAME columns
l_emailsidx := apex_exec.get_column_position( l_context, 'EMAIL' );
l_namesids := apex_exec.get_column_position( l_context, 'NAME' );
-- Loop throught the query of the context
while apex_exec.next_row( l_context ) loop
l_id : = apex_mail.send (
p_to => apex_exec.get_varchar2( l_context, l_emailsidx ),
p_template_static_id => 'NEW_YEAR_2020_PROMOTION_DUBAI_BRANCH',
p_placeholders => '{' ||
' "CUSTOMER":' || apex_json.stringify( apex_exec.get_varchar2( l_context, l_namesids )) ||
' ,"START_DATE":' || apex_json.stringify( :P2_START_DATE ) ||
' ,"END_DATE":' || apex_json.stringify( :P2_END_DATE ) ||
' ,"LOCATION":' || apex_json.stringify( :P2_LOCATION ) ||
' ,"NOTES":' || apex_json.stringify( :P2_NOTES ) ||
' ,"ITEMS":' || apex_json.stringify( :P2_ITEMS ) ||
' ,"MY_APPLICATION_LINK":' || apex_json.stringify( apex_mail.get_instance_url || apex_page.get_url( 1 )) ||
'}' );
end loop;
for rec in (
select filename, blob_content, mime_type
from apex_application_files
where flow_id = :APP_ID
and filename = 'apex_logo.png'
)
loop
apex_mail.add_attachment(
p_mail_id => l_id,
p_attachment => rec.blob_content,
p_filename => rec.filename,
p_mime_type => rec.mime_type);
end loop;
apex_mail_queue(
p_smtp_hostname => 'xyz.xmp.it',
p_smtp_portno => 45
)
apex_exec.close( l_context );
exception
when others then
apex_exec.close( l_context );
raise;
end;
Need to convert my above code below like this
UTL_MAIL.send (
sender => 'example#ac.cc',
recipents => 'abcexample#ac.cc',
cc => 'xyzexample#ac.cc',
subject => 'Testing',
mime_type => 'text/html',
message => 'ABC TESTING'
);
My below code does not support at my end. It throws network access denied as (ACL). Only UTL_SMTP is supported and mail is sent. But below code need to transform as above UTL_SMTP.send method
l_id : = apex_mail.send (
p_to => apex_exec.get_varchar2( l_context, l_emailsidx ),
p_template_static_id => 'NEW_YEAR_2020_PROMOTION_DUBAI_BRANCH',
p_placeholders => '{' ||
' "CUSTOMER":' || apex_json.stringify( apex_exec.get_varchar2( l_context, l_namesids )) ||
' ,"START_DATE":' || apex_json.stringify( :P2_START_DATE ) ||
' ,"END_DATE":' || apex_json.stringify( :P2_END_DATE ) ||
' ,"LOCATION":' || apex_json.stringify( :P2_LOCATION ) ||
' ,"NOTES":' || apex_json.stringify( :P2_NOTES ) ||
' ,"ITEMS":' || apex_json.stringify( :P2_ITEMS ) ||
' ,"MY_APPLICATION_LINK":' || apex_json.stringify( apex_mail.get_instance_url || apex_page.get_url( 1 )) ||
'}' );
end loop;
for rec in (
select filename, blob_content, mime_type
from apex_application_files
where flow_id = :APP_ID
and filename = 'apex_logo.png'
)
loop
apex_mail.add_attachment(
p_mail_id => l_id,
p_attachment => rec.blob_content,
p_filename => rec.filename,
p_mime_type => rec.mime_type);
end loop;
apex_mail_queue(
p_smtp_hostname => 'xyz.xmp.it',
p_smtp_portno => 45
)
Following is the YouTube followed to create the application
https://www.youtube.com/watch?v=aZQ04yjS7rQ
I'm trying to get to the bottom of ORA-00904 - Invalid Identifier error that I'm getting in my stored procedure.
Here is the code:
CREATE OR REPLACE PROCEDURE CDG4_HIER_GET_SUBTREE(pDimensionId IN VARCHAR2, pPeriodId IN NUMBER, pNodeId IN NUMBER, pMode IN CHAR, rCursor OUT SYS_REFCURSOR) IS
v_table_name VARCHAR2(30);
v_function_name VARCHAR2(30) := 'CDG4_HIER_MGR_HAS_CHILDREN'; -- some function defined in the same package
InvalidMode EXCEPTION;
---
v_sql VARCHAR2(2000);
BEGIN
-- Get dynamic table name
v_sql := 'SELECT UPPER(TABLE_ID)'
||'FROM CDG4_CFG_MAP_GER '
||'WHERE UPPER(DIMENSION_ID) = UPPER(''' || pDimensionId || ''') ';
EXECUTE IMMEDIATE v_sql INTO v_table_name;
IF pMode = 'F' THEN
-- Do something
ELSIF pMode = 'S' THEN
v_sql := 'SELECT A.PERIODO_K, '
||' A.FIGLIO_K, '
||' A.PADRE_K, '
||' A.F_LAYOUT, '
||' A.F_VISUALIZZA, '
||' DECODE(A.PADRE_K, NULL, NULL, B2.CODICE) AS CODICE_PADRE, '
||' A.F_ORDINE, '
||' DECODE(A.GEN1, ''2'', ''I'', A.GEN1) AS GEN1, '
||' A.GEN2, '
||' A.GEN3, '
||' ''[''|| B1.CODICE || ''] - '' || B1.DESCR AS DESCR, '
||' ''[''|| B1.CODICE || ''] - '' || B1.DESCR AS DESCRIZIONE, '
||' ' || v_function_name || '(''' || pDimensionId || ''', ' || pPeriodId || ', A.FIGLIO_K) AS HAS_CHILDREN '
||'FROM DM_GERARCHIE A, DIM_BO_CANALE_PRIMARIA B1, DIM_BO_CANALE_PRIMARIA B2 '
||'WHERE A.FIGLIO_K = B1.CODICE_K '
||'AND A.PADRE_K = B2.CODICE_K '
||'AND UPPER(A.DIMENSION_ID) = UPPER(''' || pDimensionId || ''') '
||'AND UPPER(B1.DIMENSION_ID) = UPPER(''' || pDimensionId || ''') '
||'AND UPPER(B2.DIMENSION_ID) = UPPER(''' || pDimensionId || ''') '
||'AND A.PERIODO_K = ' || pPeriodId
||' AND A.FIGLIO_K = ' || pNodeId;
ELSE
RAISE InvalidMode;
END IF;
OPEN rCursor FOR v_sql;
EXCEPTION
WHEN InvalidMode THEN
RAISE_APPLICATION_ERROR(-20005, 'Invalid selection mode.');
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20004, 'Generic error - '||SQLCODE||' -ERROR- '||SQLERRM);
END;
Oracle seems not to be able to identify the function v_function_name (it is in the same package) as it keeps returning ORA-00904 while opening the cursor rCursor.
Any hint to a plausible clause of this behaviour?
Thanks in advance.
Oracle seems not to be able to identify the function v_function_name (it is in the same package
Dynamic SQL is executed as SQL but outside of the scope of the package. That means we need to build a valid SQL statement. If you were running a similar static SELECT statement you would have written package_name.v_function_name because your SQL would execute outside the package. And that's what you need to do here.
Although now I've looked more closely at your code and I don't understand why you are using Dynamic SQL at all. You could execute your statements as static SQL with bind variables and parameters.
OPEN rCursor FOR
SELECT A.PERIODO_K,
A.FIGLIO_K,
A.PADRE_K,
A.F_LAYOUT,
A.F_VISUALIZZA,
DECODE(A.PADRE_K, NULL, NULL, B2.CODICE) AS CODICE_PADRE,
A.F_ORDINE,
DECODE(A.GEN1, ''2'', ''I'', A.GEN1) AS GEN1,
A.GEN2,
A.GEN3,
'[' || B1.CODICE || '] - ' || B1.DESCR AS DESCR,
'[' || B1.CODICE || '] - ' || B1.DESCR AS DESCRIZIONE,
package_name.v_function_name (pDimensionId ,pPeriodId , A.FIGLIO_K) AS HAS_CHILDREN
FROM DM_GERARCHIE A, DIM_BO_CANALE_PRIMARIA B1, DIM_BO_CANALE_PRIMARIA B2
WHERE A.FIGLIO_K = B1.CODICE_K
AND A.PADRE_K = B2.CODICE_K
AND UPPER(A.DIMENSION_ID) = UPPER( pDimensionId )
AND UPPER(B1.DIMENSION_ID) = UPPER( pDimensionId )
AND UPPER(B2.DIMENSION_ID) = UPPER( pDimensionId )
AND A.PERIODO_K = pPeriodId
AND A.FIGLIO_K = pNodeId;
The following procedure is failing with a "ORA-0097: missing equal sign error".
CREATE PROCEDURE AMEPSA.USP_ETL_BATCH_MASTER_UPDATE
(ENVIRONMENT in VARCHAR2, BATCH_STATUS in VARCHAR2, BATCH_USER_ID VARCHAR2, BATCH_JOB_NAME VARCHAR2)
AS
BEGIN
IF (BATCH_STATUS = 'Running') THEN
EXECUTE IMMEDIATE 'UPDATE AMEPSA.ETL_BATCH_MASTER SET
BATCH_STATUS_' || ENVIRONMENT || ' = ' || '''' || BATCH_STATUS || '''' || ',
BATCH_JOB_NAME_' || ENVIRONMENT || ' = ' || '''' || BATCH_JOB_NAME || '''' || ',' ||
'BATCH_USER_ID_' || ENVIRONMENT || ' = ' || '''' || BATCH_USER_ID || '''' || ',' ||
'BATCH_START_DATE_' || ENVIRONMENT || ' = TO_DATE(' || '''' || TO_CHAR(SYSDATE, 'MM/DD/YYYY HH24:MI:SS') || '''' || ', ' || '''' || 'MM/DD/YYYY HH24:MI:SS' || '''' || ') ' || ',' ||
'BATCH_END_DATE_' || ENVIRONMENT || ' = ' || 'NULL' || '
WHERE BATCH_NBR = (SELECT MAX(BATCH_NBR) FROM AMEPSA.ETL_BATCH_MASTER)';
ELSE
EXECUTE IMMEDIATE 'UPDATE AMEPSA.ETL_BATCH_MASTER SET
BATCH_STATUS_' || ENVIRONMENT || ' = ' || '''' || BATCH_STATUS || '''' || ',
BATCH_JOB_NAME_' || ENVIRONMENT || ' = ' || '''' || BATCH_JOB_NAME || '''' || ',' ||
'BATCH_END_DATE_' || ENVIRONMENT || ' = ' || 'TO_DATE(' || '''' || TO_CHAR(SYSDATE, 'MM/DD/YYYY HH24:MI:SS') || '''' || ', ' || '''' || 'MM/DD/YYYY HH24:MI:SS' || '''' || ')
WHERE BATCH_NBR = (SELECT MAX(BATCH_NBR) FROM AMEPSA.ETL_BATCH_MASTER)';
END IF;
COMMIT;
END;
GO
While debugging the issue, we replaced the EXECUTE IMMEDIATE statements with DBMS_OUTPUT.PUT_LINE statements. After doing so, the procedure returned a string (below) that executed successfully with no syntax errors.
UPDATE AMEPSA.ETL_BATCH_MASTER
SET BATCH_STATUS_STAGE = 'Running',
BATCH_JOB_NAME_STAGE = 'wf_TADM_Stage',
BATCH_END_DATE_STAGE = TO_DATE('08/14/2017 15:42:00', 'MM/DD/YYYY HH24:MI:SS')
WHERE BATCH_NBR = (SELECT MAX(BATCH_NBR) FROM AMEPSA.ETL_BATCH_MASTER)
Why would the EXECUTE IMMEDIATE statement think it's missing an equals sign when the resulting string returned from the DBMS_OUTPUT.PUT_LINE statement is syntactically correct?
Full exception from Informatica:
Severity: ERROR Timestamp: 8/15/2017 9:46:10 AM Node: didre2007
Thread: TRANSF_1_1_1 Process ID: 9072 Message Code: CMN_1022 Message:
Database driver error... CMN_1022 [ ORA-00927: missing equal sign
ORA-06512: at "AMEPSA.USP_ETL_BATCH_MASTER_UPDATE", line 14 ORA-06512:
at line 2
Database driver error... Function Name : ExecuteSP
Oracle Fatal Error Database driver error... Function Name : ExecuteSP
Oracle Fatal Error]
It looks like the parameter values being passed into the procedure have single quotes; specifically the first one, but possibly all of them. You can replicate by calling it directly:
exec USP_ETL_BATCH_MASTER_UPDATE('''STAGE''', '''Running''', '''someuser''', '''wf_TADM_Stage''');
which gets
Error report -
ORA-00927: missing equal sign
ORA-06512: at "AMEPSA.USP_ETL_BATCH_MASTER_UPDATE", line 14
ORA-06512: at line 1
00927. 00000 - "missing equal sign"
or just
exec USP_ETL_BATCH_MASTER_UPDATE('''STAGE''', 'Running', 'someuser', 'wf_TADM_Stage');
which goes into the other branch and gets:
Error report -
ORA-00927: missing equal sign
ORA-06512: at "AMEPSA.USP_ETL_BATCH_MASTER_UPDATE", line 6
ORA-06512: at line 1
00927. 00000 - "missing equal sign"
With debugs showing the code before it's executed you can see it ends up trying to run this:
UPDATE AMEPSA.ETL_BATCH_MASTER SET
BATCH_STATUS_'STAGE' = 'Running',
BATCH_JOB_NAME_'STAGE' = 'wf_TADM_Stage',BATCH_USER_ID_'STAGE' = 'someuser',BATCH_START_DATE_'STAGE' = TO_DATE('08/15/2017 19:37:00', 'MM/DD/YYYY HH24:MI:SS') ,BATCH_END_DATE_'STAGE' = NULL
WHERE BATCH_NBR = (SELECT MAX(BATCH_NBR) FROM AMEPSA.ETL_BATCH_MASTER)
with inappropriate quotes; the BATCH_STATUS_'STAGE' construct is throwing the exception.
If called without those extra single quotes, what you've shown works, in either branch.
So you need to look into why Informatica is adding those single quotes - possibly just a developer's confusion about how to handle strings as arguments - and stop it doing that. The problem isn't in the code you showed, and without seeing the Informatica code, I can't be more specific about how it should be fixed.
Incidentally, in comments it was mentioned that you could use bind variables via the using clause, and not convert sysdate to a string and back; it's nothing to do with the error you're getting, but that might look like:
CREATE PROCEDURE AMEPSA.USP_ETL_BATCH_MASTER_UPDATE
(ENVIRONMENT in VARCHAR2, BATCH_STATUS in VARCHAR2, BATCH_USER_ID VARCHAR2, BATCH_JOB_NAME VARCHAR2)
AS
BEGIN
IF (BATCH_STATUS = 'Running') THEN
EXECUTE IMMEDIATE 'UPDATE AMEPSA.ETL_BATCH_MASTER SET'
|| ' BATCH_STATUS_' || ENVIRONMENT || ' = :BATCH_STATUS,'
|| ' BATCH_JOB_NAME_' || ENVIRONMENT || ' = :BATCH_JOB_NAME,'
|| ' BATCH_USER_ID_' || ENVIRONMENT || ' = :BATCH_USER_ID,'
|| ' BATCH_START_DATE_' || ENVIRONMENT || ' = SYSDATE,'
|| ' BATCH_END_DATE_' || ENVIRONMENT || ' = NULL'
|| ' WHERE BATCH_NBR = (SELECT MAX(BATCH_NBR) FROM AMEPSA.ETL_BATCH_MASTER)'
USING BATCH_STATUS, BATCH_JOB_NAME, BATCH_USER_ID;
ELSE
EXECUTE IMMEDIATE 'UPDATE AMEPSA.ETL_BATCH_MASTER SET'
|| ' BATCH_STATUS_' || ENVIRONMENT || ' = :BATCH_STATUS,'
|| ' BATCH_JOB_NAME_' || ENVIRONMENT || ' = :BATCH_JOB_NAME,'
|| ' BATCH_END_DATE_' || ENVIRONMENT || ' = SYSDATE'
|| ' WHERE BATCH_NBR = (SELECT MAX(BATCH_NBR) FROM AMEPSA.ETL_BATCH_MASTER)'
USING BATCH_STATUS, BATCH_JOB_NAME;
END IF;
END;
I've been attempting to try out emailing an iCalendar event using Dan's blog
http://www.danielmcghan.us/2008/06/icalendar-event-via-email.html
I'm not getting a preview in outlook 2007 and just an attached file
not supported calendar message.ics
Though the attached file successfully creates a calendar entry.
Here's an example file: https://db.tt/tCOtafyO
This is how I am sending the calendar event:
if (P_OUTLOOK)
then
l_ical_event := hrm_ical_event(
-- p_start_date => to_date( '16-09-2014 09:00:00' , 'dd-mm-yyyy HH24:MI:SS') --TO_DATE(l_startdatum || l_starttijd,'DD-MM-YYYY HH24:MI:SS') --HH:MIPM')
--, p_end_date => to_date( '16-09-2014 16:30:00' , 'dd-mm-yyyy hh24:mi:ss') --TO_DATE(l_einddatum || l_eindtijd,'DD-MM-YYYY HH24:MI:SS') --HH:MIPM')
p_start_date =>TO_DATE(trunc(l_startdatum) || ' ' || l_begintijd,'DD-MM-YYYY HH24:MI:SS') --HH:MIPM')
, p_end_date => TO_DATE(trunc(l_einddatum) || ' ' || l_eindtijd,'DD-MM-YYYY HH24:MI:SS') --HH:MIPM')
, p_description => l_body
, p_location => l_locatie
, p_summary => l_subj
, p_organizer_name => 'HRD'
, p_organizer_email => p_afzender
);
hrm_mail_outlook(
p_from => p_afzender
, p_to => p_ontvanger
, p_subj => l_subj
, p_body_html => '<font size="2" face="Arial">' || l_body || '</font>'
, p_body_cal => l_ical_event
);
This is my hrm_ical_event:
CREATE OR REPLACE FUNCTION APP_ISI.HRM_ical_event (
p_summary IN VARCHAR2
, p_organizer_name IN VARCHAR2
, p_organizer_email IN VARCHAR2
, p_description IN VARCHAR2
, p_start_date IN DATE
, p_end_date IN DATE
, p_location IN VARCHAR2 := NULL
, p_version IN VARCHAR2 := NULL
, p_prodid IN VARCHAR2 := NULL
, p_calscale IN VARCHAR2 := NULL
, p_method IN VARCHAR2 := NULL
)
RETURN VARCHAR2
AS
l_retval VARCHAR2(32767);
l_lf CHAR(1) := CHR(10);
BEGIN
l_retval := ''
|| 'BEGIN:VCALENDAR' || l_lf
|| 'VERSION:' || NVL(p_version,'2.0') || l_lf
|| 'PRODID:' || NVL(p_prodid,'-/MN//NONSGML ICAL_EVENT//NL') || l_lf
|| 'CALSCALE:' || NVL(p_calscale,'GREGORIAN') || l_lf
|| 'METHOD:' || NVL(p_method,'REQUEST') || l_lf
|| 'BEGIN:VEVENT' || l_lf
|| 'SUMMARY:' || p_summary || l_lf
|| 'LOCATION:' || p_location || l_lf
|| 'ORGANIZER;CN="' || p_organizer_name || '":MAILTO:' || p_organizer_email || l_lf
|| 'DESCRIPTION:' || p_description || l_lf
|| 'DTSTART:' || TO_CHAR(p_start_date,'YYYYMMDD') || 'T' || TO_CHAR(p_start_date,'HH24MISS') || l_lf
|| 'DTEND:' || TO_CHAR(p_end_date,'YYYYMMDD') || 'T' || TO_CHAR(p_end_date,'HH24MISS') || l_lf
|| 'DTSTAMP:' || TO_CHAR(SYSDATE,'YYYYMMDD') || 'T' || TO_CHAR(SYSDATE,'HH24MISS') || l_lf
|| 'UID:' || RAWTOHEX(SYS_GUID()) || '#mn.nl' || l_lf
|| 'STATUS:NEEDS-ACTION' || l_lf
|| 'END:VEVENT' || l_lf
|| 'END:VCALENDAR';
RETURN l_retval;
END hrm_ical_event;
/
And this my hrm_mail_outlook:
CREATE OR REPLACE PROCEDURE APP_ISI.HRM_MAIL_OUTLOOK
(p_from IN VARCHAR2
, p_to IN VARCHAR2
, p_subj IN VARCHAR2
, p_body_html IN VARCHAR2
, p_body_cal IN VARCHAR2
)
IS
l_connection UTL_SMTP.CONNECTION;
l_mail_server VARCHAR2(255) := 'mail.yourserver.com';
l_mail_port PLS_INTEGER := 25;
l_msg_hrd VARCHAR2(32767);
l_msg_body VARCHAR2(32767);
l_lf VARCHAR2(2) := CHR(13)||CHR(10);
BEGIN
l_msg_body := ''
|| 'Date: ' || TO_CHAR(SYSDATE,'DAY, DD-MON-RR HH24:MI') || l_lf
|| 'From: <' || p_from || '> ' || l_lf
|| 'Subject: ' || p_subj || l_lf
|| 'To: ' || p_to || l_lf
|| 'MIME-Version: 1.0' || l_lf
|| 'Content-type: multipart/mixed; boundary="frontier"' || l_lf
|| '--frontier' || l_lf
|| 'Content-Type: text/calendar' || l_lf
|| 'charset="utf-8"' || l_lf
|| 'method=REQUEST' || l_lf
|| 'component=vevent' || l_lf
|| l_lf
|| p_body_cal || l_lf
|| '--frontier' || l_lf
|| 'Content-Type: text/html' || l_lf
|| 'charset="utf-8"' || l_lf
|| l_lf
|| p_body_html || l_lf
|| '--frontier--';
l_connection := utl_smtp.open_connection(l_mail_server, l_mail_port);
utl_smtp.helo(l_connection, l_mail_server);
utl_smtp.mail(l_connection, p_from);
utl_smtp.rcpt(l_connection, p_to);
utl_smtp.data(l_connection, l_msg_body);
utl_smtp.quit(l_connection);
END HRM_MAIL_OUTLOOK;
/
CREATE OR REPLACE FUNCTION APP_ISI.HRM_ical_event (
p_summary IN VARCHAR2
, p_organizer_name IN VARCHAR2
, p_organizer_email IN VARCHAR2
, p_start_date IN DATE
, p_end_date IN DATE
, p_location in varchar2 := null
, p_description in varchar2 := null
, p_trigger IN VARCHAR2 DEFAULT '60M'--(Code defaults to 60 minute warning)
, p_version IN VARCHAR2 := NULL -- (Code defaults it to 2.0 if null)
, p_prodid IN VARCHAR2 := NULL -- (Code defaults it to '-//Company Name//NONSGML ICAL_EVENT//EN' if null)
, p_calscale IN VARCHAR2 := NULL -- (Code defaults it to GREGORIAN if null)
, p_method IN VARCHAR2 := NULL) -- (Code defaults it to REQUEST if null)
RETURN VARCHAR2
AS
l_retval VARCHAR2(32767);
l_lf CHAR(2) := CHR(13)||CHR(10);
BEGIN
l_retval := ''
|| 'BEGIN:VCALENDAR' || l_lf
|| 'VERSION:' || NVL(p_version,'2.0') || l_lf
|| 'PRODID:' || NVL(p_prodid,'-//Company Id//NONSGML ICAL_EVENT//EN') || l_lf
|| 'CALSCALE:' || NVL(p_calscale,'GREGORIAN') || l_lf
|| 'METHOD:' || NVL(p_method,'REQUEST') || l_lf
|| 'BEGIN:VEVENT' || l_lf
|| 'SUMMARY:' || p_summary || l_lf
|| 'ORGANIZER;CN="' || p_organizer_name || '":MAILTO:' || p_organizer_email || l_lf
|| 'DTSTART:' || TO_CHAR(p_start_date,'YYYYMMDD') || 'T' || TO_CHAR(p_start_date,'HH24MISS') || l_lf
|| 'DTEND:' || TO_CHAR(p_end_date,'YYYYMMDD') || 'T' || TO_CHAR(p_end_date,'HH24MISS') || l_lf
|| 'LOCATION:' || p_location || l_lf
|| 'DESCRIPTION:' || p_description || l_lf
|| 'DTSTAMP:' || TO_CHAR(SYSDATE,'YYYYMMDD') || 'T' || TO_CHAR(SYSDATE,'HH24MISS') || l_lf
|| 'UID:' || RAWTOHEX(SYS_GUID()) || '#company.com' || l_lf
|| 'STATUS:NEEDS-ACTION' || l_lf
|| 'BEGIN:VALARM' || l_lf
|| 'TRIGGER:-PT'||p_trigger|| l_lf
|| 'REPEAT:1' || l_lf
|| 'DURATION:PT60M' || l_lf
|| 'ACTION:DISPLAY' || l_lf
|| 'DESCRIPTION' || p_description || l_lf
|| 'END:VALARM' || l_lf
|| 'END:VEVENT' || l_lf
|| 'END:VCALENDAR';
RETURN l_retval;
END hrm_ical_event;
I want to create a job that would drop a database object at a given date. The job created all right but the procedure is not executed. Tried executing the procedure alone and it works.
Here's the code for the create job
v_jobnam := v_objnam;
v_jobnam := DBMS_SCHEDULER.generate_job_name (v_jobnam);
v_startdate := to_timestamp(v_startdate);
select sysdate + (v_delhrs/1440)
into v_startdate
from dual;
DBMS_SCHEDULER.CREATE_JOB(job_name => v_jobnam, job_type => 'PLSQL_BLOCK', JOB_ACTION => 'BEGIN DROP_OBJ1(' || v_objnam|| ', ' || v_objtyp || ', '|| v_schema || ',' || v_objid ||'); END;', start_date => SYSTIMESTAMP, repeat_interval => 'freq=secondly; bysecond=0', end_date => NULL, enabled => TRUE, comments => 'Calls PLSQL once');
where v_delhrs is a number.
Here's the code for the procedure:
PROCEDURE DROP_OBJ1
(
p_objnam IN CHAR,
p_objtyp IN CHAR,
p_copyto IN ALL_OBJECTS.OWNER%TYPE,
p_objid IN NUMBER
)
IS
v_objnam VARCHAR2 (30);
v_objtyp VARCHAR2 (30);
v_copyto VARCHAR2 (30);
v_objid NUMBER (3);
BEGIN
v_objnam := UPPER (p_objnam);
v_objtyp := UPPER (p_objtyp);
v_copyto := UPPER (p_copyto);
v_objid := p_objid;
--v_copyby := UPPER (p_copyby);
EXECUTE IMMEDIATE ( ' DROP '
|| v_objtyp
|| ' '
|| v_copyto
|| '.'
|| v_objnam
);
EXECUTE IMMEDIATE ( ' DELETE FROM COPY_OBJ_DET WHERE OBJ_ID = '
|| v_objid
);
COMMIT;
END;
I know its a very minor problem.
Thanks in advance gurus.
Cheers!
It apears to me that you have missed some quote marks in the DBMS_JOBS setup call.
Try this:
DBMS_SCHEDULER.CREATE_JOB(job_name => v_jobnam,
job_type => 'PLSQL_BLOCK',
JOB_ACTION => 'BEGIN DROP_OBJ1(''' || v_objnam
|| ''', ''' || v_objtyp || ''', '''
|| v_schema || ''',' || v_objid
|| '); END;',
start_date => SYSTIMESTAMP,
repeat_interval => 'freq=secondly; bysecond=0',
end_date => NULL,
enabled => TRUE,
comments => 'Calls PLSQL once');
If this is not the solution I will setup your code on a database and try it myself.