Following two new PL/SQL features came with Oracle 18c Database -
PL/SQL Hierarchical Profiler (DBMS_HPROF) Enhancements
PL/SQL Qualified Expressions
PL/SQL Hierarchical Profiler (DBMS_HPROF) Enhancements
PL/SQL Qualified Expressions
Halim is a Sr. Database Engineer/Data Architect (in Atlanta, USA) who is an Oracle certified (OCP) DBA, (OCP) Developer, Certified Cloud Architect Professional as well as OCI Autonomous DB specialist with extensive expertise in Database design, configuration, tuning, capacity planning, RAC, DG, Scripting, Python, PL/SQL etc. He achieved 16th position in worldwide first-ever PL/SQL Challenge cup playoff- http://plsql-challenge.blogspot.com/2010/07/winners-of-first-plsql-challenge.html
CREATE OR REPLACE PACKAGE SAY_HELLO_FROM_DB
IS
PROCEDURE pro_send_emails_with_attach (
sender_email_address VARCHAR2,
recipient_email_addresses VARCHAR2,
email_subject VARCHAR2,
email_body_text VARCHAR2,
email_attachment_text CLOB,
email_attachment_file_name VARCHAR2);
PROCEDURE pro_send_emails_without_attach (
sender_email_address VARCHAR2,
recipient_email_addresses VARCHAR2,
email_subject VARCHAR2,
email_body_text VARCHAR2);
END;
/
CREATE OR REPLACE PACKAGE BODY SAY_HELLO_FROM_DB
IS
PROCEDURE pro_send_emails_with_attach (
sender_email_address VARCHAR2,
recipient_email_addresses VARCHAR2,
email_subject VARCHAR2,
email_body_text VARCHAR2,
email_attachment_text CLOB,
email_attachment_file_name VARCHAR2)
IS
c UTL_TCP.connection;
rc BINARY_INTEGER;
v_next_column BINARY_INTEGER;
v_recipient_email_length BINARY_INTEGER;
v_recipient_email_addresses VARCHAR2 (500);
v_single_recipient_email_addr VARCHAR2 (100);
j BINARY_INTEGER;
current_position BINARY_INTEGER := 1;
email_attachment_text_segment CLOB;
--- v_date varchar2(100);
BEGIN
v_recipient_email_addresses := recipient_email_addresses;
v_recipient_email_length := LENGTH (v_recipient_email_addresses);
v_recipient_email_addresses := v_recipient_email_addresses || ',';
v_next_column := 1;
IF INSTR (v_recipient_email_addresses, ',') = 0
THEN
v_single_recipient_email_addr := v_recipient_email_addresses;
v_recipient_email_length := 1;
END IF;
-- -- CHANGE SMTP SERVER'S ip AND port
c := UTL_TCP.open_connection ('192.168.X.XXX', 25);
rc := UTL_TCP.write_line (c, 'HELO localhost');
DBMS_OUTPUT.put_line (UTL_TCP.get_line (c, TRUE));
WHILE v_next_column <= v_recipient_email_length
LOOP
v_single_recipient_email_addr :=
SUBSTR (
v_recipient_email_addresses,
v_next_column,
INSTR (v_recipient_email_addresses, ',', v_next_column)
- v_next_column);
v_next_column :=
INSTR (v_recipient_email_addresses, ',', v_next_column) + 1;
rc := UTL_TCP.write_line (c, 'MAIL FROM: ' || sender_email_address);
DBMS_OUTPUT.put_line (UTL_TCP.get_line (c, TRUE));
rc :=
UTL_TCP.write_line (c,
'RCPT TO: ' || v_single_recipient_email_addr);
DBMS_OUTPUT.put_line (UTL_TCP.get_line (c, TRUE));
rc := UTL_TCP.write_line (c, 'DATA');
DBMS_OUTPUT.put_line (UTL_TCP.get_line (c, TRUE));
rc :=
UTL_TCP.write_line (
c,
'Date: ' || TO_CHAR (SYSDATE, 'dd Mon yy hh24:mi:ss'));
---- v_date := 'Date: ' || TO_CHAR (SYSDATE, 'dd Mon yy hh24:mi:ss') ;
rc := UTL_TCP.write_line (c, 'From: ' || sender_email_address);
rc := UTL_TCP.write_line (c, 'MIME-Version: 1.0');
rc := UTL_TCP.write_line (c, 'To: ' || v_single_recipient_email_addr);
rc := UTL_TCP.write_line (c, 'Subject: ' || email_subject);
rc := UTL_TCP.write_line (c, 'Content-Type: multipart/mixed;');
rc := UTL_TCP.write_line (c, ' boundary="-----SECBOUND"');
rc := UTL_TCP.write_line (c, '');
rc := UTL_TCP.write_line (c, '-------SECBOUND');
rc := UTL_TCP.write_line (c, 'Content-Type: text/plain');
rc := UTL_TCP.write_line (c, 'Content-Transfer-Encoding: 7bit');
rc := UTL_TCP.write_line (c, '');
rc := UTL_TCP.write_line (c, email_body_text);
rc := UTL_TCP.write_line (c, '');
rc := UTL_TCP.write_line (c, '-------SECBOUND');
rc := UTL_TCP.write_line (c, 'Content-Type: text/plain;');
rc :=
UTL_TCP.write_line (
c,
' name="' || email_attachment_file_name || '"');
rc := UTL_TCP.write_line (c, 'Content-Transfer_Encoding: 8bit');
rc := UTL_TCP.write_line (c, 'Content-Disposition: attachment;');
rc := UTL_TCP.write_line (c, '');
current_position := 1;
j := (ROUND (LENGTH (email_attachment_text)) / 32000) + 1;
DBMS_OUTPUT.put_line (
'j= ' || j || ' length= ' || LENGTH (email_attachment_text));
FOR i IN 1 .. j
LOOP
email_attachment_text_segment :=
SUBSTR (email_attachment_text, current_position, 32000);
rc := UTL_TCP.write_line (c, email_attachment_text_segment);
current_position := current_position + 32000;
END LOOP;
rc := UTL_TCP.write_line (c, '-------SECBOUND--');
rc := UTL_TCP.write_line (c, '');
rc := UTL_TCP.write_line (c, '.');
DBMS_OUTPUT.put_line (UTL_TCP.get_line (c, TRUE));
DBMS_OUTPUT.put_line (
'***** Single E-mail= '
|| v_single_recipient_email_addr
|| ' '
|| v_next_column);
END LOOP;
rc := UTL_TCP.write_line (c, 'QUIT');
DBMS_OUTPUT.put_line (UTL_TCP.get_line (c, TRUE));
UTL_TCP.close_connection (c);
END;
PROCEDURE pro_send_emails_without_attach (
sender_email_address VARCHAR2,
recipient_email_addresses VARCHAR2,
email_subject VARCHAR2,
email_body_text VARCHAR2)
IS
c UTL_TCP.connection;
rc BINARY_INTEGER;
v_next_column BINARY_INTEGER;
v_recipient_email_length BINARY_INTEGER;
v_recipient_email_addresses VARCHAR2 (500);
v_single_recipient_email_addr VARCHAR2 (100);
BEGIN
v_recipient_email_addresses := recipient_email_addresses;
v_recipient_email_length := LENGTH (v_recipient_email_addresses);
v_recipient_email_addresses := v_recipient_email_addresses || ',';
v_next_column := 1;
IF INSTR (v_recipient_email_addresses, ',') = 0
THEN
v_single_recipient_email_addr := v_recipient_email_addresses;
v_recipient_email_length := 1;
END IF;
-- CHANGE SMTP SERVER'S ip AND port
c := UTL_TCP.open_connection ('192.168.XX.XX', 25);
DBMS_OUTPUT.put_line (UTL_TCP.get_line (c, TRUE));
rc := UTL_TCP.write_line (c, 'HELO localhost');
DBMS_OUTPUT.put_line (UTL_TCP.get_line (c, TRUE));
WHILE v_next_column <= v_recipient_email_length
LOOP
v_single_recipient_email_addr :=
SUBSTR (
v_recipient_email_addresses,
v_next_column,
INSTR (v_recipient_email_addresses, ',', v_next_column)
- v_next_column);
v_next_column :=
INSTR (v_recipient_email_addresses, ',', v_next_column) + 1;
rc := UTL_TCP.write_line (c, 'MAIL FROM: ' || sender_email_address);
DBMS_OUTPUT.put_line (UTL_TCP.get_line (c, TRUE));
rc :=
UTL_TCP.write_line (c,
'RCPT TO: ' || v_single_recipient_email_addr);
DBMS_OUTPUT.put_line (UTL_TCP.get_line (c, TRUE));
rc := UTL_TCP.write_line (c, 'DATA');
DBMS_OUTPUT.put_line (UTL_TCP.get_line (c, TRUE));
rc :=
UTL_TCP.write_line (
c,
'Date: ' || TO_CHAR (SYSDATE, 'dd Mon yy hh24:mi:ss'));
rc := UTL_TCP.write_line (c, 'From: ' || sender_email_address);
rc := UTL_TCP.write_line (c, 'MIME-Version: 1.0');
rc := UTL_TCP.write_line (c, 'To: ' || v_single_recipient_email_addr);
rc := UTL_TCP.write_line (c, 'Subject: ' || email_subject);
rc := UTL_TCP.write_line (c, email_body_text);
rc := UTL_TCP.write_line (c, '.');
DBMS_OUTPUT.put_line (UTL_TCP.get_line (c, TRUE));
DBMS_OUTPUT.put_line (
'***** Single E-mail= '
|| v_single_recipient_email_addr
|| ' '
|| v_next_column);
END LOOP;
rc := UTL_TCP.write_line (c, 'QUIT');
DBMS_OUTPUT.put_line (UTL_TCP.get_line (c, TRUE));
UTL_TCP.close_connection (c);
END;
END;
/
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
SQL> FLASHBACK DATABASE TO RESTORE POINT before_stress_test_pr;
SQL> ALTER DATABASE OPEN RESETLOGS ;
Checking SCN number in primary –(just for confirmation it is greater that standby by SCN number later)
SQL> SELECT CURRENT_SCN FROM V$DATABASE;
6) Start Managed recovery on the standby –
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
SQL> FLASHBACK DATABASE TO RESTORE POINT before_stress_test_pr;
SQL> ALTER DATABASE OPEN RESETLOGS ;
Checking SCN number in primary –(just for confirmation it is greater that standby by SCN number later)
SQL> SELECT CURRENT_SCN FROM V$DATABASE;
5) On Standby –
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
Checking SCN number in standby – for confirmation it is lesser than primary SCN number.
SQL> SELECT CURRENT_SCN FROM V$DATABASE;
SQL> FLASHBACK STANDBY DATABASE TO RESTORE POINT before_stress_test_st ;
6) Start Managed recovery on the standby –
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;