I get the below error while executing code
create or replace
function contact_restriction_function(obj_schema varchar2, obj_name varchar2)
return varchar2 is
v_contact_info_visible hr_user_access.contact_info_visible%type;
begin
-- Here you can put any business logic for filtering
select nvl(max(contact_info_visible),'N')
into v_contact_info_visible
from hr_user_access
where user_name = user;
-- SQL filter / policy predicate
return ''''||v_contact_info_visible||''' = ''Y'' ';
end;
/
after show erros command i got this
show errors Errors for FUNCTION CONTACT_RESTRICTION: LINE/COL ERROR -------- ----------------------------------------------------------------- 3/1 PLS-00103: Encountered the symbol "?" when expecting one of the following: begin function pragma procedure subtype type current cursor delete exists prior external language
This is the remaining code:
begin
dbms_rls.add_policy(object_schema => 'HR' ,
object_name => 'EMPLOYEES' ,
policy_name => 'Contact_Restriction_Policy' ,
policy_function => 'contact_restriction_function' ,
sec_relevant_cols=>'EMAIL,PHONE_NUMBER'Contact Info ,
sec_relevant_cols_opt=>dbms_rls.all_rows);
end;
below is the actual code which i am executing before show errors:
create or replace function contact_restriction(obj_schema varchar2, obj_name varchar2)
return varchar2
is
v_contact_info_visible IN user_access.contact_info_visible%type;
begin
select nvl(max(contact_info_visible),'N')
into v_contact_info_visible
from user_access where username = user;
return 'v_contact-info_visible ='|| 'Y';
end;
contact_restriction_function
, but the error is forCONTACT_RESTRICTION
. Please show the code you actually executed immediately before callingshow errors
. – Alex PooleDBMS_RLS.ADD_POLICY
mentioned in your comment (above) you're passingpolicy_function => 'contact_restriction_function'
- but because unquoted identifiers in Oracle default to UPPER CASE this should bepolicy_function => 'CONTACT_RESTRICTION_FUNCTION'
. This may not be the source of this problem but may be helpful in the future. Share and enjoy. – Bob Jarvis - Reinstate Monica"?"
; but it will complain about theIN
in the declaration ofv_contact_info_visible
. Not sure why you're stripped the quote handling from the sample you copied; you've also changed an underscore to a hyphen, which will cause another error. – Alex Poole