Step 1 : I have created one package with procedures to create context and set value to the context.
create or replace PACKAGE Context_check AS
PROCEDURE set_context_vpd_proc (V_ISID in varchar2);
procedure set_context (v_isid_a in varchar2);
END Context_check;
create or replace PACKAGE BODY Context_check AS
PROCEDURE set_context_vpd_proc (V_ISID in varchar2)
AS
v_STAT VARCHAR2(200);
v_chk varchar2(2000);
BEGIN
DBMS_SESSION.SET_CONTEXT('VPD_CTX', 'ISID', V_ISID );
--v_STAT := '';
EXCEPTION
WHEN NO_DATA_FOUND THEN NULL;
END;
procedure set_context (v_isid_a in varchar2)
as
begin
EXECUTE IMMEDIATE 'CREATE OR REPLACE CONTEXT VPD_CTX using set_context_vpd_proc';
set_context_vpd_proc (v_isid_a);
EXCEPTION
WHEN NO_DATA_FOUND THEN NULL;
end set_context;
END Context_check;
Step 2: When I am trying to executing the procedure I am getting an error
EXECUTE Context_check.set_context('Ana');
Error starting at line 43 in command:
EXECUTE Context_check.set_context('Ana')
Error report:
ORA-01031: insufficient privileges
ORA-06512: at "SYS.DBMS_SESSION", line 114
ORA-06512: at "SEC_ADMIN.CONTEXT_CHECK", line 8
ORA-06512: at "SEC_ADMIN.CONTEXT_CHECK", line 20
ORA-06512: at line 1
01031. 00000 - "insufficient privileges"
*Cause: An attempt was made to change the current username or password
without the appropriate privilege. This error also occurs if
attempting to install a database without the necessary operating
system privileges.
When Trusted Oracle is configure in DBMS MAC, this error may occur
if the user was granted the necessary privilege at a higher label
than the current login.
*Action: Ask the database administrator to perform the operation or grant
the required privileges.
For Trusted Oracle users getting this error although granted the
the appropriate privilege at a higher label, ask the database
administrator to regrant the privilege at the appropriate label.
I have already given all the grants on that package.Still I am not able to execute this procedure.
Note : If I create the same procedures as stand alone ,its working fine and setting the context.
You need to create a context using a package, not using a procedure inside of a package.
Instead of
EXECUTE IMMEDIATE 'CREATE OR REPLACE CONTEXT VPD_CTX using set_context_vpd_proc';
Write
EXECUTE IMMEDIATE 'CREATE OR REPLACE CONTEXT VPD_CTX using Context_check';
Related
When I try to call dbms_metadata.get_ddl('TABLE', 'MYTABLE', 'MYSCHEMA') either in the pl/sql block or in the package procedure it works fine.
When I try to call dbms_metadata.get_ddl('TABLE', 'MYTABLE') (without schema explicitely provided) either in the pl/sql block or in the package procedure it works fine also.
When I try to call dbms_metadata.get_ddl('DIRECTORY', 'MYDIR') (without schema explicitely provided) in the pl/sql block it works fine also.
But,
When I try to call dbms_metadata.get_ddl('DIRECTORY', 'MYDIR', 'MYSCHEMA') either in the pl/sql block or in the package procedure it raises the error:
ORA-31600: invalid input value MYSCHEMA for parameter SCHEMA in function GET_DDL
When I try to call dbms_metadata.get_ddl('DIRECTORY', 'MYDIR') (without schema explicitely provided) in the package procedure it raises the error:
ORA-31603: object "MYDIR" of type DIRECTORY not found in schema "MYSCHEMA"
What is the problem?
EXECUTE_CATALOG_ROLE=true
SELECT_CATALOG_ROLE=true
'CREATE ANY DIRECTORY'=true
PL/SQL Release 12.2.0.1.0 - Production
You need to add the AUTHID CURRENT_USER clause (Docs)
create or replace procedure dir_ddl (dir_name in varchar2) AUTHID CURRENT_USER is
x clob;
begin
SELECT DBMS_METADATA.get_ddl ('DIRECTORY', dir_name) into x from dual;
dbms_output.put_line(x);
end dir_ddl;
/
set serveroutput on
exec dir_ddl('PLSHPROF_DIR')
And my output is...
Procedure DIR_DDL compiled
CREATE OR REPLACE DIRECTORY "PLSHPROF_DIR" AS '/home/oracle/profiler'
PL/SQL procedure successfully completed.
If I remove the AUTHID clause, I see the same error as you report.
I want to create procedure which will kill all session. After I run the statement i get error:
[Warning] ORA-24344: success with compilation error 10/13 PL/SQL:
ORA-00942: table or view does not exist 6/6 PL/SQL: SQL Statement
ignored 15/31 PLS-00364: loop index variable 'V_KILL' use is invalid
15/9 PL/SQL: Statement ignored (1: 0): Warning: compiled but with
compilation errors
CREATE OR REPLACE PROCEDURE KILL_ORACLE_SESSIONS
IS
BEGIN
FOR v_kill IN
(SELECT
'alter system kill session '''
||sid||','||serial#||',#1'|| ''' immediate;' as statement
FROM
v$session
WHERE
sql_id='sql_id_here'
)
LOOP
dbms_output.put_line (v_kill.statement);
END LOOP;
END;
/
Where is the catch ?
Thanks
Most likely you don't have permissions to select view v$session because your user received this privilege by a ROLE. Privileges inside a PL/SQL block must be granted directly to the user (i.e. GRANT SELECT ON V$SESSION TO {username};). A role (for example DBA ROLE) does not apply inside PL/SQL.
When I run this it gives me the error
ORA-00911: invalid character
CREATE OR REPLACE DIRECTORY CDATA AS 'D:\';
GRANT READ ON DIRECTORY CDATA TO PUBLIC;
DECLARE
MYFILE UTL_FILE.FILE_TYPE;
type array IS VARRAY(10) OF INTEGER;
arr array;
temp number;
curr number;
prev number;
n number;
BEGIN
MYFILE := UTL_FILE.FOPEN('CDATA','FILING.txt','W');
arr := array(98, 97, 78, 87, 92, 33, 12, 45, 45, 66);
n:= arr.count;
UTL_FILE.PUT(MYFILE, 'ORGANIZED DATA: ');
for i in 2..arr.count loop
curr:=i;
prev:=i-1;
while arr(prev) > arr(curr) loop
temp:= arr(curr);
arr(curr):= arr(prev);
arr(prev):= temp;
curr:= curr-1;
prev:= prev-1;
IF curr=1 THEN
EXIT;
END IF;
end loop;
end loop;
for i in 1.. arr.count loop
UTL_FILE.PUT_LINE(MYFILE, arr(i));
dbms_output.put_line(arr(i));
end loop;
UTL_FILE.FCLOSE(MYFILE);
END; //ORA-00911: invalid character
// File is not writting
Unable to write sorted data into file from insertion algorithm
I ran your query as a normal (public) user. There was no error as ORA-00911: invalid character. There was another error, which is expected as per the code you are running. When I ran your script as a dba user, there was no error at all.
First Approach: As a public user, you would get first error as
"insufficient privileges"
when the create directory line executes. Then you would get
"directory does not exist"
when the plsql script executes.
This is because, the directory creation and grant script have to run with dba privilege (it is a privilege that user account like 'sys' possess). The rest of the script i.e. that plsql block can run from a public user. As normal user does not have directory creation and grant privilege, hence the error.
Now, if you move directory creation to grant lines to run with a dba user, they will run fine, the above 2 errors would be gone. Then when you run the plsql block with a public user, there will be a third error
"directory access denied"
. This is because, in your grant script you have given read access on the directory object to public, while in your plsql block you are actually writing to it. To handle that, modify grant script to -
GRANT READ,WRITE ON DIRECTORY CDATA TO PUBLIC;
Second Approach
You can run the whole script including the plsql block using a dba user, where your script would encounter no errors at all.
I would suggest the best approach would be to run directory creation and grant script from a dba user and then run the plsql block from a normal nondba user, with the grant script modified as above.
I have a stored procedure with 3 parameters. I want to execute this from configuration in operation manager. I used like this :
begin
saman_test.CONVERTHISTORY('$Config/JobType$','$Config/HostFQDN$','$Config/Environment$'); end;
but it does not work without any error.
And I used this code:
exec
saman_test.CONVERTHISTORY('$Config/JobType$','$Config/HostFQDN$','$Config/Environment$')
but I get this error :
ORA-00900: invalid SQL statement
How do I execute my procedure?
I find the keyword for execute my procedure.
call
saman_test.CONVERTHISTORY('$Config/JobType$','$Config/HostFQDN$','$Config/Environment$')
I can connect to the database via sqlplus
sqlplus stepdba/<password>#steprds.<rds-hash-here>.<region>.rds.amazonaws.com:1521/STEP
and I am trying to write to a file.
According to AmazonRDS documentation regarding Oracle, create directory must be done with rdsadmin.rdsadmin_util.create_directory('MY_DIR'); which I have done.
To write to a file, I do the following:
DECLARE
fileHandler UTL_FILE.FILE_TYPE;
BEGIN
fileHandler := UTL_FILE.FOPEN('MY_DIR', 'test.txt', 'W');
UTL_FILE.PUTF(fileHandler, 'Writing TO a file\n');
UTL_FILE.FCLOSE(fileHandler);
END;
/
Which result in an error:
ERROR at line 1:
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at line 4
If I try to write to an Oracle provided directory DATA_PUMP_DIR, the above snippet executes correctly and the file is written.
The privileges to the two directories are the same
select grantee, privilege from dba_tab_privs where table_name='DATA_PUMP_DIR' and grantee = 'STEPDBA';
select grantee, privilege from dba_tab_privs where table_name='MY_DIR' and grantee = 'STEPDBA';
In the Amazon-RDS case, we can not manipulate the file/directory permissions on the OS level.
I seem to be missing something, any hint would be appreciated.
Hi I had exactly the same problem. Solved it by using higher version of Oracle software: Oracle SE One 11.2.0.4.v4
One that was causing the problems was Oracle SE One 11.2.0.4.v3