Oracle - 功能不起作用
所以我不知道我做错了什么。我已经花了几个小时了,非常感谢一些帮助。
所以基本上我有两张桌子,一张叫做student
这是一个学生名单student_no
是主键,另一个表称为enrol
其中基本上包含了学生注册的课程列表。
所以我编写了一个函数来比较登录学生的用户名,在本例中是student_no
,添加到学生列表并确保登录用户是学生。然后它比较student_no
与enrol
表来查找用户注册的任何程序。所以本质上当我SELECT * FROM yaser.enrol
(表所有者是 yaser)我应该只看到注册列表中的几条记录。相反,我收到错误:failed to execute policy function
.
这是我的功能:
-- Create policy function to be called when 'ENROL' table is accessed
create or replace function f_policy_enrol (schema in varchar2, tab in varchar2)
-- Function will return a string that is used as a WHERE clause
return varchar2
as
v_student_no varchar2(10);
is_student number:=0;
v_user varchar2(100);
out_string varchar2(400) default '1=2 ';
begin
-- get session user
v_user := lower(sys_context('userenv','session_user'));
-- Is the user a student?
begin
select student_no into v_student_no from student where lower(student_no) = v_user;
is_student:=1;
exception
when no_data_found then
v_student_no := 0;
end;
-- If it's a student, then they are only allowed to see their record only.
if is_student = 1 then
out_string := out_string||'or student_no = '||v_student_no||' ';
end if;
return out_string;
end;
/
这是我调用的策略:
begin
dbms_rls.add_policy('yaser',
'enrol',
'accesscontrol_enrol',
'yaser',
'f_policy_enrol',
policy_type => dbms_rls.context_sensitive);
end;
/
正如之前所说......我不确定我哪里错了。无论是在政策上还是在功能上。任何帮助将不胜感激!如果您有任何疑问,我很乐意在工作空闲时间立即回答!
提前致谢!
Yaser