我正在学习oracle vpd,所以我创建了以下表格:
create table employees ( empid varchar(30) primary key,empname varchar(30), dept varchar(30));
insert into employees values ('E1','mark','ACCOUNTING');
insert into employees values ('E2','john','SALES');
insert into employees values ('E3','vpdadmin', 'RESEARCH');
create table payroll (empid varchar(30), dept varchar(30), total int, taxes int, foreign key(empid) references employees(empid));
insert into payroll values ('E1','ACCOUNTING',2400,100);
insert into payroll values ('E2','SALES',2500,75);
insert into payroll values ('E3','RESEARCH',3000,110);
,然后按如下所示创建策略功能:
create function policy_function (obj_schema varchar2, obj_name varchar2)
return varchar2 is
v_dept employees.dept% TYPE;
v_id employees.empid% TYPE;
begin
select dept into v_dept from employees where upper(EMPNAME)=SYS_CONTEXT('userenv','SESSION_USER');
select empid into v_id from employees where upper(EMPNAME)=SYS_CONTEXT('userenv','SESSION_USER');
if (v_dept != 'ACCOUNTING') then
return 'upper(EMPID)='|| v_id;
else
return '';
end IF ;
end policy_function;
然后:
begin dbms_rls.add_policy (
user,
'payroll',
'policy_on',
user,
'policy_function',
'select');
end;
但是当我从vpdadmin帐户的工资单中选择*时,我得到了错误:
Error information for ORA-28113:
Logon user : VPDADMIN
Table/View : VPDADMIN.PAYROLL
Policy name : POLICY_ON
Policy function: VPDADMIN.POLICY_FUNCTION
RLS view :
SELECT "EMPID","DEPT","TOTAL","TAXES" FROM "VPDADMIN"."PAYROLL" "PAYROLL" WHERE (upper(EMPID)=E3)
ORA-00904: "E3": invalid identifier
那怎么了?雇员和薪资表中都已经有E3了,我不知道发生了什么以及如何解决它
答案 0 :(得分:3)
看来#define S_PROJ
中的RETURN
语句应该是
POLICY_FUNCTION
EMPID是一个字符串,必须用单引号引起来。
好运。