Face with an error ORA-02030 when you try to give permission on a v$ view
SQL> grant select on v$session to hr;
grant select on v$session to hr
*
ERROR at line 1:
ORA-02030: can only select from fixed tables/views
Why it couldn’t give select privileges to a v$ view. If you tried to give permission to other v$views you will face same the error.
The problem is caused because of trying to give select privileges on a synonym. Oracle v$ views are named V_$VIEWNAME and they have synonyms in format V$VIEWNAME and you can’t give privilage on a synonym.
If you want to give permission to a V$ view you must grant permissions like below:
SQL> grant select on v_$session to hr;
Grant succeeded.
Wednesday, 29 November 2017
Wednesday, 15 November 2017
RAISE_APPLICATION_ERROR
The RAISE_APPLICATION_ERROR is actually a procedure defined by Oracle that allows the developer to raise an exception and associate an error number and message with the procedure. This allows the application to raise application errors rather than just Oracle errors. Error numbers are defined between -20,000 and -20,999. All other numbers belong to Oracle for its own errors. The message can be anything that will fit in a varchar2(2000).
RAISE_APPLICATION_ERROR can be used in either (or both) the executable section and the exception section of a PL/SQL program. The error number and message is displayed to the user.
Syntax:
RAISE_APPLICATION_ERROR ({error_number}, {error_message});
{error_number} - The Error number must be between -20000 and -20999
{error_message} - The Error message is the message you want to display when the error occurs
Using in Execution section
BEGIN
...
RAISE_APPLICATION_ERROR (-20001,'This is a user error message');
...
END;
Using in Exception section:
BEGIN
...
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR (-20003, 'This is another user error message');
END;
Examples:
Input:
DECLARE
l_number NUMBER;
BEGIN
SELECT 2 INTO l_number FROM DUAL;
dbms_output.put_line('l_number = '||l_number);
END;
Output:
l_number = 2
Input:
DECLARE
l_number NUMBER;
BEGIN
SELECT 2 INTO l_number FROM DUAL;
RAISE_APPLICATION_ERROR (-20001,'This is a user error message');
dbms_output.put_line('l_number = '||l_number);
END;
Output:
There is no output due to our ERROR
line 19: ORA-20001: This is a user error message
ORA-06512: at line 5
RAISE_APPLICATION_ERROR can be used in either (or both) the executable section and the exception section of a PL/SQL program. The error number and message is displayed to the user.
Syntax:
RAISE_APPLICATION_ERROR ({error_number}, {error_message});
{error_number} - The Error number must be between -20000 and -20999
{error_message} - The Error message is the message you want to display when the error occurs
Using in Execution section
BEGIN
...
RAISE_APPLICATION_ERROR (-20001,'This is a user error message');
...
END;
Using in Exception section:
BEGIN
...
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR (-20003, 'This is another user error message');
END;
Examples:
Input:
DECLARE
l_number NUMBER;
BEGIN
SELECT 2 INTO l_number FROM DUAL;
dbms_output.put_line('l_number = '||l_number);
END;
Output:
l_number = 2
Input:
DECLARE
l_number NUMBER;
BEGIN
SELECT 2 INTO l_number FROM DUAL;
RAISE_APPLICATION_ERROR (-20001,'This is a user error message');
dbms_output.put_line('l_number = '||l_number);
END;
Output:
There is no output due to our ERROR
line 19: ORA-20001: This is a user error message
ORA-06512: at line 5
Subscribe to:
Posts (Atom)