Home » SQL & PL/SQL » SQL & PL/SQL » Error when create policy after create view. What is the problem? (PLSQL)
icon5.gif  Error when create policy after create view. What is the problem? [message #649768] Tue, 05 April 2016 13:46 Go to next message
quytrieu
Messages: 1
Registered: April 2016
Location: Viet Nam
Junior Member
when i create view TO user NHANVIEN . Select, insert, update is still ok.
CREATE VIEW V_NHANVIEN
AS
SELECT MADA,TENDA,PHONGCHUTRI,TRUONGDA FROM DUAN_1312508_1312474;
GRANT SELECT ON V_NHANVIEN TO ROLE_NHANVIEN;

But i create policy to different user 'TRUONGDA', then user 'NHANVIEN' select, insert, update is ERROR;
CREATE OR REPLACE FUNCTION TEST_TRUONGDA(P_SCHEMA VARCHAR2, P_OBJ VARCHAR2)
RETURN VARCHAR2
AS
  USER VARCHAR2(100);  
BEGIN 
   IF (SYS_CONTEXT('USERENV', 'ISDBA') = 'TRUE') THEN 
	  RETURN '';
	ELSE
	  USER:=SYS_CONTEXT('USERENV', 'SESSION_USER');     
    RETURN 'DUAN IN(SELECT MADA FROM DUAN_1312508_1312474 WHERE TRUONGDA = '||USER||');';
	END IF;
END;
  
  BEGIN 
  DBMS_RLS.ADD_POLICY(
  object_schema => 'HQTCSDL_1312474_1312508',
  object_name => 'CHITIEU_1312508_1312474',
  policy_name => 'p_CHITIEU',
  function_schema => 'HQTCSDL_1312474_1312508',
  policy_function => 'TEST_TRUONGDA',
  statement_types => 'SELECT,UPDATE, INSERT',
  update_check => TRUE);
  END;

what is the problem?
What is relative between view and policy on a table? or my code have a problem?
thanks everyone saw.

[Updated on: Tue, 05 April 2016 13:52]

Report message to a moderator

Re: Error when create policy after create view. What is the problem? [message #649769 is a reply to message #649768] Tue, 05 April 2016 15:23 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

What is the error?
Use SQL*Plus and copy and paste your session, the WHOLE session including all object creations and statements in error, enough for us to be able to reproduce what you have.
Also always post your Oracle version, with 4 decimals, as solution depends on it.

USER is a reserved word (and an internal function), do not use it.

Re: Error when create policy after create view. What is the problem? [message #650276 is a reply to message #649769] Thu, 21 April 2016 07:17 Go to previous messageGo to next message
Bill B
Messages: 1971
Registered: December 2004
Senior Member
What error???? Without seeing what is failing, how do we help you out?
Re: Error when create policy after create view. What is the problem? [message #650278 is a reply to message #649768] Thu, 21 April 2016 07:31 Go to previous message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
Problem is in:

RETURN 'DUAN IN(SELECT MADA FROM DUAN_1312508_1312474 WHERE TRUONGDA = '||USER||');';

It has missing quotes and extra semi-colon. It should be either

RETURN 'DUAN IN(SELECT MADA FROM DUAN_1312508_1312474 WHERE TRUONGDA = '''||USER||''')';

Or better:


RETURN 'DUAN IN(SELECT MADA FROM DUAN_1312508_1312474 WHERE TRUONGDA = SYS_CONTEXT(''USERENV'', ''SESSION_USER''))';

Also USER is name of built-in function, so I'd stay away of naming PL/SQL variable USER. It will not work as expected if you reference it in a SQL statement.

SY.

[Updated on: Thu, 21 April 2016 07:40]

Report message to a moderator

Previous Topic: Counting overlapping ID's in intersection tables.
Next Topic: Nested table with object type
Goto Forum:
  


Current Time: Fri Apr 26 11:01:52 CDT 2024