Oracle SQL FGA sys_context('userenv','current_sql') 被截断
Posted
技术标签:
【中文标题】Oracle SQL FGA sys_context(\'userenv\',\'current_sql\') 被截断【英文标题】:Oracle SQL FGA sys_context(‘userenv’,’current_sql’) truncatedOracle SQL FGA sys_context('userenv','current_sql') 被截断 【发布时间】:2017-09-23 01:53:50 【问题描述】:我想记录针对特定表的所有语句,使用 FGA 和 sys_context('userenv','current_sql') 我接近我需要的,但似乎 current_sql 总是被截断为 256 个字符。
我尝试查看 current_sql1 到 7,但它们始终为空。这是我用来设置的代码:
create table emp_audit
( whodidit varchar2(40)
, whenwasit timestamp
, sql_executed varchar2(4000)
, sql_executed1 varchar2(4000)
, sql_executed2 varchar2(4000)
, sql_executed3 varchar2(4000)
, sql_executed4 varchar2(4000)
, sql_executed5 varchar2(4000)
, sql_executed6 varchar2(4000)
, sql_executed7 varchar2(4000)
);
create or replace
package AUDIT_HANDLER
is
PROCEDURE HANDLE_EMP_SAL_ACCESS
( object_schema VARCHAR2
, object_name VARCHAR2
, policy_name VARCHAR2
);
end;
create or replace
package body AUDIT_HANDLER
is
PROCEDURE HANDLE_EMP_SAL_ACCESS
( object_schema VARCHAR2
, object_name VARCHAR2
, policy_name VARCHAR2
) is
PRAGMA AUTONOMOUS_TRANSACTION;
begin
insert into emp_audit
( whodidit, whenwasit, sql_executed, SQL_EXECUTED1, SQL_EXECUTED2, SQL_EXECUTED3, SQL_EXECUTED4, SQL_EXECUTED5, SQL_EXECUTED6, SQL_EXECUTED7)
values
( user, systimestamp, sys_context('userenv','current_sql'),sys_context('userenv','current_sql1'),sys_context('userenv','current_sql2'),sys_context('userenv','current_sql3'),sys_context('userenv','current_sql4'),sys_context('userenv','current_sql5'),sys_context('userenv','current_sql6'),sys_context('userenv','current_sql7'))
;
commit;
end HANDLE_EMP_SAL_ACCESS;
end;
begin
dbms_fga.add_policy
( object_schema=>'EPAT'
, object_name=>'PERSON'
, policy_name=>'PHI_ACCESS_HANDLED'
, handler_schema => 'SBOUCHAR'
, handler_module => 'AUDIT_HANDLER.HANDLE_EMP_SAL_ACCESS'
);
end;
【问题讨论】:
【参考方案1】:看来您必须在调用 sys_context 时指定长度:
sys_context('userenv','current_sql',4000)
【讨论】:
以上是关于Oracle SQL FGA sys_context('userenv','current_sql') 被截断的主要内容,如果未能解决你的问题,请参考以下文章
Oracle 12c how to purge the FGA audit records before a certain date