Oracle:游标内的游标
我对 PL/SQL 很陌生,需要快速帮助。整个游标处理令人不安,但我正在习惯它。请仅关注游标 1) cur_cheese_proprietary 和 2)cur_cheese_mms。我正在尝试从 cur_cheese_mms 中检索那些行,这些行在迭代时与游标 cur_cheese_proprietary 当前行中的 CheeseNumber 具有相同的 CheeseNumber。我想要一个 CSV 字符串,在 Excel 中打开时如下所示:
我还想列出仅存在于 cur_cheese_proprietary 或 cur_cheese_mms 中的所有行(其代码在以下 pl/ 块中完全丢失) sql)
示例文件: 开始
col1 col2 col3 ......(来自 cur_cheese_proprietary )
'CHOM DATA'
col1 col2 col3 (来自 cur_cheese_mms)
行仅存在于 cur_cheese_proprietary 中 col1 col2 col3
行仅存在于 cur_cheese_mms 中 col1 col2 col3
示例文件:结束
言归正传,这就是我目前所拥有的。
问题 1) 在哪里以及如何从 ROWTYPE 变量 cur_rec_cheese cur_cheese_proprietary%ROWTYPE; 填充 v_cheeseNumber?请参阅下面的代码。
问题 2) 如何查找不匹配的行(仅基于任一表中的 v_cheeseNumber 列)?
如果您有时间,请仅回答问题1。在阅读更多 pl/sql 语法后,我也许能够弄清楚问题 2。我想外连接可以解决这个问题——意味着更多的游标!
CREATE OR REPLACE PROCEDURE sp_monthly_status
IS
v_from VARCHAR2 (80);
v_subject VARCHAR2 (80);
crlf VARCHAR2 (2);
v_mail_host VARCHAR2 (80);
v_event_csv VARCHAR2 (32767);
v_cheese_csv VARCHAR2 (32767);
v_user_csv VARCHAR2 (32767);
v_recipient VARCHAR2 (2000);
v_rcpts VARCHAR2 (2000);
v_to VARCHAR2 (100);
v_error VARCHAR2 (2000);
n_event_count NUMBER;
n_cheese_count NUMBER;
n_user_count NUMBER;
n_pos NUMBER;
v_mail_conn UTL_SMTP.connection;
v_cheeseNumber VARCHAR2 (256);
CURSOR cur_event_log IS
SELECT REPLACE (l.evt_name, ',', ' ') || ',' ||
REPLACE (l.evt_params, ',', ' ') || ',' ||
l.evt_user || ',' ||
TO_CHAR (l.evt_start_time, 'MM/DD/YYYY HH24:MI:SS') evt_info
FROM chom_event_log l
WHERE UPPER (l.evt_type) = 'REPORT'
AND l.evt_start_time > ADD_MONTHS (SYSDATE, -1);
CURSOR cur_cheese_proprietary IS
SELECT NVL (TO_CHAR (p.data_name), '<blank>') || ',' ||
NVL (TO_CHAR (ls.external_data_id), '<blank>') || ',' ||
NVL (TO_CHAR (ls.block_number), '<blank>') || ',' ||
NVL (TO_CHAR (ls.TikTok), '<blank>') || ',' ||
NVL (TO_CHAR (ls.TikTok_area), '<blank>') || ',' ||
NVL (TO_CHAR (ls.cheese_number), '<blank>') || ',' ||
NVL (TO_CHAR (ls.sbu), '<blank>') || ',' ||
NVL (TO_CHAR (ls.comments), '<blank>') || ',' ||
NVL (TO_CHAR (le.company_name), '<blank>') || ',' ||
NVL (TO_CHAR (le.TikTok_percent), '<blank>')
cheese_prop_data
FROM chom_cheese_proprietary ls, chom_lessee_proprietary le, chom_data p
WHERE ls.cheese_lessee_key = le.cheese_lessee_key
AND ls.external_data_id = p.external_data_id
AND ls.sbu = 'chom DW'
ORDER BY ls.sbu, p.data_name, block_number;
CURSOR cur_cheese_mms IS
SELECT NVL (TO_CHAR (p.data_name), '<blank>') || ',' ||
NVL (TO_CHAR (ls.external_data_id), '<blank>') || ',' ||
NVL (TO_CHAR (ls.block_number), '<blank>') || ',' ||
NVL (TO_CHAR (ls.TikTok), '<blank>') || ',' ||
NVL (TO_CHAR (ls.TikTok_area), '<blank>') || ',' ||
NVL (TO_CHAR (ls.cheese_number), '<blank>') || ',' ||
NVL (TO_CHAR (ls.sbu), '<blank>') || ',' ||
NVL (TO_CHAR (ls.comments), '<blank>') || ',' ||
NVL (TO_CHAR (le.company_name), '<blank>') || ',' ||
NVL (TO_CHAR (gles.TikTok_percent), '<blank>')
cheese_mms_data
FROM chom_cheese_proprietary ls, chom_lessee_proprietary le, chom_data p, explore.chom_cheese gl, chom_lessee gles
WHERE ls.cheese_lessee_key = le.cheese_lessee_key
AND ls.external_data_id = p.external_data_id
--AND gl.TikTok(+) = ls.TikTok
AND gl.TikTok(+) = ls.TikTok
--AND gl.cheese_NUMBER = gles.cheese_NUMBER
AND gles.cheese_NUMBER=v_cheeseNumber
AND ls.sbu = 'chom DW'
ORDER BY ls.sbu, p.data_name, ls.block_number;
CURSOR cur_user_list IS
SELECT DISTINCT l.evt_user
FROM chom_event_log l
WHERE l.evt_start_time > ADD_MONTHS (SYSDATE, -1)
AND UPPER (l.evt_name) = 'LOGIN INFORMATION';
cur_rec cur_event_log%ROWTYPE;
cur_rec_cheese cur_cheese_proprietary%ROWTYPE;
cur_rec_mms cur_cheese_mms%ROWTYPE;
cur_rec_user cur_user_list%ROWTYPE;
-- Adds recipients for each comma separated values
PROCEDURE sp_chom_add_recipient (p_rcpts VARCHAR2)
IS
BEGIN
v_rcpts := p_rcpts;
LOOP
IF v_rcpts IS NULL
THEN
EXIT;
END IF;
n_pos := INSTR (v_rcpts, ',');
IF n_pos > 0
THEN
v_to := TRIM (SUBSTR (v_rcpts, 1, n_pos - 1));
v_rcpts := SUBSTR (v_rcpts, n_pos + 1);
IF LENGTH (v_to) > 0
THEN
UTL_SMTP.rcpt (v_mail_conn, v_to);
END IF;
ELSE
v_to := TRIM (v_rcpts);
EXIT;
END IF;
END LOOP;
IF LENGTH (v_to) > 0
THEN
UTL_SMTP.rcpt (v_mail_conn, v_to);
END IF;
END;
-- Begin of main procedure
BEGIN
-- Initiallize parameters
v_from := '[email protected]';
v_subject := 'chom Monthly Report';
crlf := CHR (13) || CHR (10);
n_event_count := 0;
n_cheese_count := 0;
n_user_count := 0;
SELECT value INTO v_mail_host
FROM chom_config_param
WHERE UPPER (name) = 'SMTP_MAIL_HOST';
SELECT value INTO v_recipient
FROM chom_config_param
WHERE UPPER (name) = 'MONTHLY_REPORT_MAIL_LIST';
-- Header row for CSV file
v_event_csv := 'Name,Description,User,Date Time' || crlf;
v_cheese_csv := 'data Name,data ID,Block Number,Star Block,Protraction Area,cheese Number,SBU,Comments,Company Name,Lessee Percent' || crlf;
v_user_csv := 'User CAI' || crlf;
IF cur_event_log%ISOPEN THEN
CLOSE cur_event_log;
OPEN cur_event_log;
ELSE
OPEN cur_event_log;
END IF;
-- Create data in CSV format for chom event
LOOP
FETCH cur_event_log INTO cur_rec;
EXIT WHEN cur_event_log%NOTFOUND;
n_event_count := n_event_count + 1;
v_event_csv := v_event_csv || cur_rec.evt_info || crlf;
END LOOP;
CLOSE cur_event_log;
IF cur_cheese_proprietary%ISOPEN THEN
CLOSE cur_cheese_proprietary;
OPEN cur_cheese_proprietary;
ELSE
OPEN cur_cheese_proprietary;
END IF;
-- Create data in CSV format
LOOP
FETCH cur_cheese_proprietary INTO cur_rec_cheese;
EXIT WHEN cur_cheese_proprietary%NOTFOUND;
n_cheese_count := n_cheese_count + 1;
v_cheese_csv := v_cheese_csv || cur_rec_cheese.cheese_prop_data || crlf;
v_cheese_csv := v_cheese_csv || 'CHOM DATA' || crlf;
IF cur_cheese_mms%ISOPEN THEN
CLOSE cur_cheese_mms;
OPEN cur_cheese_mms;
ELSE
OPEN cur_cheese_mms;
END IF;
LOOP
FETCH cur_cheese_mms INTO cur_rec_mms;
EXIT WHEN cur_cheese_mms%NOTFOUND;
n_cheese_count := n_cheese_count + 1;
v_cheese_csv := v_cheese_csv || cur_rec_mms.cheese_mms_data || crlf;
END LOOP;
END LOOP;
CLOSE cur_cheese_proprietary;
IF cur_user_list%ISOPEN THEN
CLOSE cur_user_list;
OPEN cur_user_list;
ELSE
OPEN cur_user_list;
END IF;
-- Create data in CSV format for USER list
LOOP
FETCH cur_user_list INTO cur_rec_user;
EXIT WHEN cur_user_list%NOTFOUND;
n_user_count := n_user_count + 1;
v_user_csv := v_user_csv || cur_rec_user.evt_user || crlf;
END LOOP;
CLOSE cur_user_list;
v_mail_conn := UTL_SMTP.open_connection (v_mail_host, 25);
UTL_SMTP.helo (v_mail_conn, v_mail_host);
UTL_SMTP.mail (v_mail_conn, v_from);
-- email recipient
sp_chom_add_recipient(v_recipient);
UTL_SMTP.OPEN_DATA(v_mail_conn);
-- Use MIME mail header
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Date: ' || TO_CHAR (SYSDATE, 'Dy, DD Mon YYYY hh24:mi:ss') || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'From: ' || v_from || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Subject: ' || v_subject || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'To: ' || v_recipient || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'MIME-Version: 1.0' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Content-Type: multipart/mixed; boundary="chom_SEC_BOUND"' || crlf || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'This is multipart message' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, '--chom_SEC_BOUND' || crlf);
-- Message body
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Content-Type: text/plain;' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Content-Transfer_Encoding: 7bit' || crlf || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Hello User,' || crlf);
IF n_event_count = 0 AND n_cheese_count = 0 AND n_user_count = 0 THEN
UTL_SMTP.WRITE_DATA(v_mail_conn, ' No information available.' || crlf);
ELSE
UTL_SMTP.WRITE_DATA(v_mail_conn, ' Attached pcheese find chom data .' || crlf);
END IF;
UTL_SMTP.WRITE_DATA(v_mail_conn, ' ' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Thanks' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, ' Support Team' || crlf);
-- Attachment section chom Event log
UTL_SMTP.WRITE_DATA(v_mail_conn, '--chom_SEC_BOUND' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Content-Type: text/plain;' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, ' name="excel.csv"' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Content-Transfer_Encoding: 8bit' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Content-Disposition: attachment;' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, ' filename="chom_Monthly_Report.csv"' || crlf || crlf);
IF n_event_count > 0 THEN
-- Start CSV content of attachment
UTL_SMTP.WRITE_DATA(v_mail_conn, v_event_csv);
-- End CSV content of attachment
ELSE
UTL_SMTP.WRITE_DATA(v_mail_conn, 'No information available.' || crlf);
END IF;
-- Attachment section cheese proprietary
UTL_SMTP.WRITE_DATA(v_mail_conn, '--chom_SEC_BOUND' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Content-Type: text/plain;' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, ' name="excel.csv"' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Content-Transfer_Encoding: 8bit' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Content-Disposition: attachment;' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, ' filename="cheese_Proprietary.csv"' || crlf || crlf);
IF n_cheese_count > 0 THEN
-- Start CSV content of attachment
UTL_SMTP.WRITE_DATA(v_mail_conn, v_cheese_csv);
-- End CSV content of attachment
ELSE
UTL_SMTP.WRITE_DATA(v_mail_conn, 'No information available.' || crlf);
END IF;
-- Attachment section user access list
UTL_SMTP.WRITE_DATA(v_mail_conn, '--chom_SEC_BOUND' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Content-Type: text/plain;' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, ' name="excel.csv"' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Content-Transfer_Encoding: 8bit' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Content-Disposition: attachment;' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, ' filename="User_Access_List.csv"' || crlf || crlf);
IF n_cheese_count > 0 THEN
-- Start CSV content of attachment
UTL_SMTP.WRITE_DATA(v_mail_conn, v_user_csv);
-- End CSV content of attachment
ELSE
UTL_SMTP.WRITE_DATA(v_mail_conn, 'No information available.' || crlf);
END IF;
-- End MIME mail
UTL_SMTP.WRITE_DATA(v_mail_conn, crlf || crlf || '--chom_SEC_BOUND--');
UTL_SMTP.CLOSE_DATA(v_mail_conn);
UTL_SMTP.QUIT (v_mail_conn);
sp_chom_email_status('Monthly report sent successfully.');
EXCEPTION
WHEN OTHERS
THEN
v_error := TO_CHAR (SQLCODE) || ': ' || SQLERRM;
INSERT INTO chom_event_log
(evt_id, evt_source, evt_type,
evt_name, evt_user, evt_start_time, evt_end_time,
evt_params
)
VALUES (chom_seq_evt_id.NEXTVAL, 'SP_chom_EMAIL_STATUS', 'Error',
'SP_chom_EMAIL_STATUS', 'JOB', SYSDATE, SYSDATE,
v_error
);
sp_chom_email_status('Error in sending monthly report.' ||
crlf || SQLCODE || ': ' || SQLERRM);
END sp_chom_monthly_status
/
I am failry new to PL/SQL and need a quick help with this.The whole cursor deal is unnerving but I am getting used to it. Please focus only on cursors 1) cur_cheese_proprietary and 2)cur_cheese_mms.I am trying to retrieve those rows from cur_cheese_mms which have the same cheeseNumber as the cheeseNumber in current row of cursor cur_cheese_proprietary while iteration. I would like to to have a CSV string that will look like following when opened in excel:
I would also like to list all those rows which exist only in cur_cheese_proprietary or in cur_cheese_mms ( the code for which is entirely mising in following block of pl/sql)
Sample file: Begin
col1 col2 col3 ......(from cur_cheese_proprietary )
'CHOM DATA'
col1 col2 col3 (from cur_cheese_mms)
ROWS ONLY PRESENT IN cur_cheese_proprietary
col1 col2 col3
ROWS ONLY PRESENT IN cur_cheese_mms
col1 col2 col3
Sample File: End
Without further ado, this is what I have currently.
Question 1) Where and how do I populate v_cheeseNumber from the ROWTYPE variable cur_rec_cheese cur_cheese_proprietary%ROWTYPE;? Pleas see code below.
Question 2) How do I find non-matching rows (based only on column v_cheeseNumber in either table) ?
Please answer only question 1 if you have time. I may be able to figure out question 2 after reading more pl/sql syntax. I guess outer join would do the trick-- means more cursors !
CREATE OR REPLACE PROCEDURE sp_monthly_status
IS
v_from VARCHAR2 (80);
v_subject VARCHAR2 (80);
crlf VARCHAR2 (2);
v_mail_host VARCHAR2 (80);
v_event_csv VARCHAR2 (32767);
v_cheese_csv VARCHAR2 (32767);
v_user_csv VARCHAR2 (32767);
v_recipient VARCHAR2 (2000);
v_rcpts VARCHAR2 (2000);
v_to VARCHAR2 (100);
v_error VARCHAR2 (2000);
n_event_count NUMBER;
n_cheese_count NUMBER;
n_user_count NUMBER;
n_pos NUMBER;
v_mail_conn UTL_SMTP.connection;
v_cheeseNumber VARCHAR2 (256);
CURSOR cur_event_log IS
SELECT REPLACE (l.evt_name, ',', ' ') || ',' ||
REPLACE (l.evt_params, ',', ' ') || ',' ||
l.evt_user || ',' ||
TO_CHAR (l.evt_start_time, 'MM/DD/YYYY HH24:MI:SS') evt_info
FROM chom_event_log l
WHERE UPPER (l.evt_type) = 'REPORT'
AND l.evt_start_time > ADD_MONTHS (SYSDATE, -1);
CURSOR cur_cheese_proprietary IS
SELECT NVL (TO_CHAR (p.data_name), '<blank>') || ',' ||
NVL (TO_CHAR (ls.external_data_id), '<blank>') || ',' ||
NVL (TO_CHAR (ls.block_number), '<blank>') || ',' ||
NVL (TO_CHAR (ls.TikTok), '<blank>') || ',' ||
NVL (TO_CHAR (ls.TikTok_area), '<blank>') || ',' ||
NVL (TO_CHAR (ls.cheese_number), '<blank>') || ',' ||
NVL (TO_CHAR (ls.sbu), '<blank>') || ',' ||
NVL (TO_CHAR (ls.comments), '<blank>') || ',' ||
NVL (TO_CHAR (le.company_name), '<blank>') || ',' ||
NVL (TO_CHAR (le.TikTok_percent), '<blank>')
cheese_prop_data
FROM chom_cheese_proprietary ls, chom_lessee_proprietary le, chom_data p
WHERE ls.cheese_lessee_key = le.cheese_lessee_key
AND ls.external_data_id = p.external_data_id
AND ls.sbu = 'chom DW'
ORDER BY ls.sbu, p.data_name, block_number;
CURSOR cur_cheese_mms IS
SELECT NVL (TO_CHAR (p.data_name), '<blank>') || ',' ||
NVL (TO_CHAR (ls.external_data_id), '<blank>') || ',' ||
NVL (TO_CHAR (ls.block_number), '<blank>') || ',' ||
NVL (TO_CHAR (ls.TikTok), '<blank>') || ',' ||
NVL (TO_CHAR (ls.TikTok_area), '<blank>') || ',' ||
NVL (TO_CHAR (ls.cheese_number), '<blank>') || ',' ||
NVL (TO_CHAR (ls.sbu), '<blank>') || ',' ||
NVL (TO_CHAR (ls.comments), '<blank>') || ',' ||
NVL (TO_CHAR (le.company_name), '<blank>') || ',' ||
NVL (TO_CHAR (gles.TikTok_percent), '<blank>')
cheese_mms_data
FROM chom_cheese_proprietary ls, chom_lessee_proprietary le, chom_data p, explore.chom_cheese gl, chom_lessee gles
WHERE ls.cheese_lessee_key = le.cheese_lessee_key
AND ls.external_data_id = p.external_data_id
--AND gl.TikTok(+) = ls.TikTok
AND gl.TikTok(+) = ls.TikTok
--AND gl.cheese_NUMBER = gles.cheese_NUMBER
AND gles.cheese_NUMBER=v_cheeseNumber
AND ls.sbu = 'chom DW'
ORDER BY ls.sbu, p.data_name, ls.block_number;
CURSOR cur_user_list IS
SELECT DISTINCT l.evt_user
FROM chom_event_log l
WHERE l.evt_start_time > ADD_MONTHS (SYSDATE, -1)
AND UPPER (l.evt_name) = 'LOGIN INFORMATION';
cur_rec cur_event_log%ROWTYPE;
cur_rec_cheese cur_cheese_proprietary%ROWTYPE;
cur_rec_mms cur_cheese_mms%ROWTYPE;
cur_rec_user cur_user_list%ROWTYPE;
-- Adds recipients for each comma separated values
PROCEDURE sp_chom_add_recipient (p_rcpts VARCHAR2)
IS
BEGIN
v_rcpts := p_rcpts;
LOOP
IF v_rcpts IS NULL
THEN
EXIT;
END IF;
n_pos := INSTR (v_rcpts, ',');
IF n_pos > 0
THEN
v_to := TRIM (SUBSTR (v_rcpts, 1, n_pos - 1));
v_rcpts := SUBSTR (v_rcpts, n_pos + 1);
IF LENGTH (v_to) > 0
THEN
UTL_SMTP.rcpt (v_mail_conn, v_to);
END IF;
ELSE
v_to := TRIM (v_rcpts);
EXIT;
END IF;
END LOOP;
IF LENGTH (v_to) > 0
THEN
UTL_SMTP.rcpt (v_mail_conn, v_to);
END IF;
END;
-- Begin of main procedure
BEGIN
-- Initiallize parameters
v_from := '[email protected]';
v_subject := 'chom Monthly Report';
crlf := CHR (13) || CHR (10);
n_event_count := 0;
n_cheese_count := 0;
n_user_count := 0;
SELECT value INTO v_mail_host
FROM chom_config_param
WHERE UPPER (name) = 'SMTP_MAIL_HOST';
SELECT value INTO v_recipient
FROM chom_config_param
WHERE UPPER (name) = 'MONTHLY_REPORT_MAIL_LIST';
-- Header row for CSV file
v_event_csv := 'Name,Description,User,Date Time' || crlf;
v_cheese_csv := 'data Name,data ID,Block Number,Star Block,Protraction Area,cheese Number,SBU,Comments,Company Name,Lessee Percent' || crlf;
v_user_csv := 'User CAI' || crlf;
IF cur_event_log%ISOPEN THEN
CLOSE cur_event_log;
OPEN cur_event_log;
ELSE
OPEN cur_event_log;
END IF;
-- Create data in CSV format for chom event
LOOP
FETCH cur_event_log INTO cur_rec;
EXIT WHEN cur_event_log%NOTFOUND;
n_event_count := n_event_count + 1;
v_event_csv := v_event_csv || cur_rec.evt_info || crlf;
END LOOP;
CLOSE cur_event_log;
IF cur_cheese_proprietary%ISOPEN THEN
CLOSE cur_cheese_proprietary;
OPEN cur_cheese_proprietary;
ELSE
OPEN cur_cheese_proprietary;
END IF;
-- Create data in CSV format
LOOP
FETCH cur_cheese_proprietary INTO cur_rec_cheese;
EXIT WHEN cur_cheese_proprietary%NOTFOUND;
n_cheese_count := n_cheese_count + 1;
v_cheese_csv := v_cheese_csv || cur_rec_cheese.cheese_prop_data || crlf;
v_cheese_csv := v_cheese_csv || 'CHOM DATA' || crlf;
IF cur_cheese_mms%ISOPEN THEN
CLOSE cur_cheese_mms;
OPEN cur_cheese_mms;
ELSE
OPEN cur_cheese_mms;
END IF;
LOOP
FETCH cur_cheese_mms INTO cur_rec_mms;
EXIT WHEN cur_cheese_mms%NOTFOUND;
n_cheese_count := n_cheese_count + 1;
v_cheese_csv := v_cheese_csv || cur_rec_mms.cheese_mms_data || crlf;
END LOOP;
END LOOP;
CLOSE cur_cheese_proprietary;
IF cur_user_list%ISOPEN THEN
CLOSE cur_user_list;
OPEN cur_user_list;
ELSE
OPEN cur_user_list;
END IF;
-- Create data in CSV format for USER list
LOOP
FETCH cur_user_list INTO cur_rec_user;
EXIT WHEN cur_user_list%NOTFOUND;
n_user_count := n_user_count + 1;
v_user_csv := v_user_csv || cur_rec_user.evt_user || crlf;
END LOOP;
CLOSE cur_user_list;
v_mail_conn := UTL_SMTP.open_connection (v_mail_host, 25);
UTL_SMTP.helo (v_mail_conn, v_mail_host);
UTL_SMTP.mail (v_mail_conn, v_from);
-- email recipient
sp_chom_add_recipient(v_recipient);
UTL_SMTP.OPEN_DATA(v_mail_conn);
-- Use MIME mail header
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Date: ' || TO_CHAR (SYSDATE, 'Dy, DD Mon YYYY hh24:mi:ss') || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'From: ' || v_from || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Subject: ' || v_subject || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'To: ' || v_recipient || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'MIME-Version: 1.0' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Content-Type: multipart/mixed; boundary="chom_SEC_BOUND"' || crlf || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'This is multipart message' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, '--chom_SEC_BOUND' || crlf);
-- Message body
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Content-Type: text/plain;' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Content-Transfer_Encoding: 7bit' || crlf || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Hello User,' || crlf);
IF n_event_count = 0 AND n_cheese_count = 0 AND n_user_count = 0 THEN
UTL_SMTP.WRITE_DATA(v_mail_conn, ' No information available.' || crlf);
ELSE
UTL_SMTP.WRITE_DATA(v_mail_conn, ' Attached pcheese find chom data .' || crlf);
END IF;
UTL_SMTP.WRITE_DATA(v_mail_conn, ' ' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Thanks' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, ' Support Team' || crlf);
-- Attachment section chom Event log
UTL_SMTP.WRITE_DATA(v_mail_conn, '--chom_SEC_BOUND' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Content-Type: text/plain;' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, ' name="excel.csv"' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Content-Transfer_Encoding: 8bit' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Content-Disposition: attachment;' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, ' filename="chom_Monthly_Report.csv"' || crlf || crlf);
IF n_event_count > 0 THEN
-- Start CSV content of attachment
UTL_SMTP.WRITE_DATA(v_mail_conn, v_event_csv);
-- End CSV content of attachment
ELSE
UTL_SMTP.WRITE_DATA(v_mail_conn, 'No information available.' || crlf);
END IF;
-- Attachment section cheese proprietary
UTL_SMTP.WRITE_DATA(v_mail_conn, '--chom_SEC_BOUND' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Content-Type: text/plain;' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, ' name="excel.csv"' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Content-Transfer_Encoding: 8bit' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Content-Disposition: attachment;' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, ' filename="cheese_Proprietary.csv"' || crlf || crlf);
IF n_cheese_count > 0 THEN
-- Start CSV content of attachment
UTL_SMTP.WRITE_DATA(v_mail_conn, v_cheese_csv);
-- End CSV content of attachment
ELSE
UTL_SMTP.WRITE_DATA(v_mail_conn, 'No information available.' || crlf);
END IF;
-- Attachment section user access list
UTL_SMTP.WRITE_DATA(v_mail_conn, '--chom_SEC_BOUND' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Content-Type: text/plain;' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, ' name="excel.csv"' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Content-Transfer_Encoding: 8bit' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, 'Content-Disposition: attachment;' || crlf);
UTL_SMTP.WRITE_DATA(v_mail_conn, ' filename="User_Access_List.csv"' || crlf || crlf);
IF n_cheese_count > 0 THEN
-- Start CSV content of attachment
UTL_SMTP.WRITE_DATA(v_mail_conn, v_user_csv);
-- End CSV content of attachment
ELSE
UTL_SMTP.WRITE_DATA(v_mail_conn, 'No information available.' || crlf);
END IF;
-- End MIME mail
UTL_SMTP.WRITE_DATA(v_mail_conn, crlf || crlf || '--chom_SEC_BOUND--');
UTL_SMTP.CLOSE_DATA(v_mail_conn);
UTL_SMTP.QUIT (v_mail_conn);
sp_chom_email_status('Monthly report sent successfully.');
EXCEPTION
WHEN OTHERS
THEN
v_error := TO_CHAR (SQLCODE) || ': ' || SQLERRM;
INSERT INTO chom_event_log
(evt_id, evt_source, evt_type,
evt_name, evt_user, evt_start_time, evt_end_time,
evt_params
)
VALUES (chom_seq_evt_id.NEXTVAL, 'SP_chom_EMAIL_STATUS', 'Error',
'SP_chom_EMAIL_STATUS', 'JOB', SYSDATE, SYSDATE,
v_error
);
sp_chom_email_status('Error in sending monthly report.' ||
crlf || SQLCODE || ': ' || SQLERRM);
END sp_chom_monthly_status
/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不太明白问题 1,但我会尝试...
cur_cheese_mns
光标使用v_cheeseNumber
。因此,在打开cur_cheese_mns
游标之前,必须为v_cheeseNumber
分配一个值。您声称该值取自
cur_rec_cheese
,它是从cur_cheese_proprietary
游标获取的。cur_cheese_proprietary
光标没有任何包含您的cheeseNumber
的列。您将需要修改光标才能返回此列。I don't quite understand question 1, but I will try...
The
cur_cheese_mns
cursor usesv_cheeseNumber
. Therefore,v_cheeseNumber
must be assigned a value before thecur_cheese_mns
cursor is opened.You claim that this value is taken from
cur_rec_cheese
which is fetched from thecur_cheese_proprietary
cursor. Thecur_cheese_proprietary
cursor does not have any column that appears to contain yourcheeseNumber
. You will need to modify the cursor to return this column.