我正在尝试在 EMP 表上创建一个触发器,该触发器将审核 EMP_AUDIT 表中的插入并将邮件发送到相应的 empno。我没有得到的是在 v_block_query 中生成的 CSV 附件中新插入的记录。我想获得 :new.FIELD_NAME 的数据基础,但它抛出了错误:
ORA-01008:并非所有变量都绑定 ORA-06512:在“SCOTT.EMP_AFTER_INSERT”,第 18 行 ORA-04088:执行触发器“SCOTT.EMP_AFTER_INSERT”时出错
create or replace TRIGGER emp_after_insert
AFTER INSERT
ON emp
FOR EACH ROW
DECLARE
v_block_qry VARCHAR2(3000);
v_block_row VARCHAR2(6000);
TYPE bl_cur IS REF CURSOR;
v_result bl_cur;
v_rowcount NUMBER;
v_attachment CLOB;
v_username varchar2(10);
v_no number(4);
v_name varchar2(10);
v_email varchar2(30);
v_subj varchar2(30);
BEGIN
insert into emp_audit(id,name,insertion_date) values(:new.empno,:new.ename,sysdate);
dbms_output.put_line('inserted'||:new.empno);
v_attachment := '"COL1", "COL2"' || CHR(13) || CHR(10);
v_block_qry := 'SELECT ''"'' || new.empno || ''", "'' || new.ename || ''", "'' || insertion_date ||''"'' AS ROWTXT FROM emp_audit ';
OPEN v_result FOR v_block_qry;
LOOP
v_rowcount := v_result%ROWCOUNT;
FETCH v_result INTO v_block_row;
EXIT WHEN v_result%NOTFOUND;
v_attachment := v_attachment || v_block_row || chr(13) || chr(10);
END LOOP;
CLOSE v_result;
dbms_output.put_line(v_attachment);
select email into v_email from dept_email where deptno=:new.empno;
dbms_output.put_line(v_email);
v_subj:= 'MAIL_SUBJECT ' || TO_CHAR(TRUNC(SYSDATE-1), 'YYYY-MM-DD');
UTL_MAIL.send_attach_varchar2(sender => 'abc@gmail.com',
recipients => v_email,
subject => 'mail testing',
message => 'current record',
mime_type => 'text/html; charset=us-ascii', -- send html e-mail
attachment => v_attachment,
att_inline => FALSE,
att_filename => 'Change_Report' || TO_CHAR(TRUNC(SYSDATE-1), 'YYYY-MM-DD') || '.csv');
END;
请帮忙。提前致谢