0

我正在尝试在 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;

请帮忙。提前致谢

4

3 回答 3

0
v_block_qry := 'SELECT ''"'' || new.empno || ''", "'' || new.ename || ''", "'' || insertion_date ||''"'' AS ROWTXT FROM emp_audit ';
                  OPEN v_result FOR v_block_qry;

您不能在查询中使用new.empnoandnew.ename

代替

(SELECT ''"'' || new.empno || ''", "'' || new.ename || ''", "'' || insertion_date ||''"'' )

在您的查询中

(SELECT ''"'' || empno || ''", "'' || ename || ''", "'' || insertion_date ||''"'' )
于 2020-02-20T18:54:47.000 回答
0

|| S_状态 || ''", "'' || DISB_TOTAL_AMOUNT_NEW || ''"'' , "'' || OUTSTANDING_PRINCIPAL_NEW || ''", "'' || GROUPBR_新 || ''", "'' || 插入日期 || '''''

' 作为 ROWTXT

           FROM SMFB.LMFLOANSNEW where branch_numb = :new.branch_code;
于 2020-02-20T14:12:34.073 回答
0
v_block_qry := 'SELECT ''"'' || BRANCH_NUMB || ''", "'' || LOAN_CODE || ''", "'' || LOAN_PRODUCT_NUMB || ''"
               , "'' || BRM_NUM || "'', "'' || CURR_CODE || "'', "'' || NAME_DESN || ''", "'' || CNIC_NUMB || ''"
               , "'' || PRINCIPAL_NEW || ''", "'' || AMOUNT_APPLIED_NEW || ''", "'' || ACCT_BASC || ''", "'' || ACCT_SFIX || ''"
               , "'' || DATE_ADDED_NEW || ''", "'' || DATE_DUE_NEW || ''", "'' || B_STATUS || ''", "'' || S_STATUS || ''", "'' || DISB_TOTAL_AMOUNT_NEW || ''"''
               , "'' || OUTSTANDING_PRINCIPAL_NEW || ''", "'' || GROUPBR_NEW || ''", "'' || INSERTED_DATE || ''"''


               AS ROWTXT FROM SMFB.LMFLOANSNEW where branch_numb='||:new.branch_code;

在预期的地方找不到来自关键字。这是在现场环境中。以前的代码在我的数据库中

于 2020-02-20T13:41:48.363 回答