Error: ORA-06502: PL/SQL: 数字或值错误 : character string buffer too small(触发器中使用系统动态视图导致)

oracle 触发器中,在工具toad中使用F5报错
15:27:51 Error: ORA-06502: PL/SQL: 数字或值错误 : character string buffer too small
ORA-06512: 在 line 14
使用F9报错
[Error] ORA-00942 (29: 11): PL/SQL: ORA-00942: 表或视图不存在

 create table tab_del_recored(
SID# number,
USERNAME varchar2(100),
PROGRAM# varchar2(100),
MACHINE varchar2(100),
IPADD varchar2(32),
MODITIME date,
TABLE_NAME varchar2(100),
TYPE_TRI varchar2(10)
);

触发器

/* Formatted on 2020/7/1 15:27:33 (QP5 v5.256.13226.35510) */
CREATE OR REPLACE TRIGGER USERSES_tr
   BEFORE DELETE
   ON SCOTT.USERSES
   FOR EACH ROW
DECLARE
   V_SYSDATE      DATE DEFAULT SYSDATE;
   V_TABLE_NAME   VARCHAR2 (100);
   V_TRI_TYPE     VARCHAR2 (100);
   V_ID           NUMBER;
   V_USERNAME     VARCHAR2 (100);
   V_PROGRAM      VARCHAR2 (100);
   V_MACHINE      VARCHAR2 (100);
   V_IP           VARCHAR2 (100);
BEGIN
   V_TABLE_NAME := 'SCOTT_USERSES';
   V_TRI_TYPE := 'DELETE';

   SELECT sid,
          username,
          program,
          machine,
          SYS_CONTEXT ('userenv', 'ip_address')
     INTO V_ID,
          V_USERNAME,
          V_PROGRAM,
          V_MACHINE,
          V_IP
     FROM v$session
    WHERE audsid = USERENV ('sessionid');

   INSERT INTO tab_del_recored (SID#,
                                USERNAME,
                                PROGRAM#,
                                MACHINE,
                                IPADD,
                                MODITIME,
                                TABLE_NAME,
                                TYPE_TRI)
        VALUES (V_ID,
                V_USERNAME,
                V_PROGRAM,
                V_MACHINE,
                V_IP,
                V_SYSDATE,
                V_TABLE_NAME,
                V_TRI_TYPE);
END;

直接使用sql是可以执行的,但是在触发器的编译中会报错。

查阅资料,

需要赋予权限
使用sys账号执行
 grant select on sys.v_$session to SCOTT;

 

posted @ 2020-08-24 09:52  春困秋乏夏打盹  阅读(2365)  评论(0编辑  收藏  举报