Can't use DBMS_RANDOM functions - oracle

I use Oracle Database 11g and I have a fairly simple code:
set serveroutput on format wrapped;
declare
result_ clob;
begin
result_ := dbms_random.string('P', 10);
dbms_output.put_line(result_);
end;
When I try to run it gives me an error saying:
identifier 'DBMS_RANDOM' must be declared
Why dbms_random is not recognized as a valid identifier? Do I have to import it?

Probably this is a permissions problem. EXECUTE on DBMS_RANDOM is not granted by default, so you need a DBA user to grant you the EXECUTE privilege.
grant execute on dbms_random to << your_username >>;
There is an outside chance the package is not installed, although installation is the default. Again, you need a DBA user to check, and if need be run the installation script.

Related

oracle dbms_scheduler privileges issue

In my DB I set up 2 schemas, schemaA and schemaB.
In schemaA I create a job (jobA) and a procedure (procA) to set arguments and enable the job. I test the flow in schemaA and it's working correctly.
In schemaB I need to call schemaA.procA in order to run the job. I grant to schemaB the privileges needed to execute schemaA.procA but the error ORA-27486: insufficient privileges is raised.
Debugging procA I locate the exception at the beginning of dbms_scheduler instructions (DBMS_SCHEDULER.PURGE_LOG(job_name=>jobName);).
EDIT: Add informations as requested in the comment
VERSION : Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
GRANT : system # mydatabase
grant CREATE ANY JOB, CREATE EXTERNAL JOB , CREATE JOB to schemaA;
PROCEDURE : schemaA # mydatabase
procedure procA ...
...
DBMS_SCHEDULER.PURGE_LOG(...);
DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE(...);
DBMS_SCHEDULER.SET_ATTRIBUTE(...);
DBMS_SCHEDULER.ENABLE(...);
...
end procA;
GRANT : schemaA # mydatabase
grant execute on procA to schemaB
In procA there are others operations that are correctly executed until PURGE_LOG that raise the exception
Inspetting others users I found that I miss one system privilege :
MANAGE SCHEDULER
Granting it from sys the procA run successfully both from schemaA and SchemaB

I can't login to oracle system account

I recently installed oracle 12c and can't access the system local generated connection. (Ora-01017 error) eventhough I know for a fact its correct because I changed the password. Anyway, someone else on stackoverflow redirected me to this https://iwikte.wordpress.com/2008/11/28/unlock-oracle-system-account/, and I don't know how to set up these environment variables. I need help. If it makes any difference i'm using windows 10.
If these environment variables are not set automatically, do it manually
(export ORACLE_HOME=/opt/oracle/VIS/db/tech_st/10.2.0
export ORACLE_SID=VIS
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin)
Please first try without setting variables.
Please run SQLPlus as administrator and connect as sysdba without giving password. If your variables are set properly you can just type sqlplus in cmd if not please find SqlPlus in your programs. Then type:
conn / as sysdba
If that won't. Please go to your ORACLE HOME directory and edit %ORACLE_HOME%\network\admin\sqlnet.ora file and check if there is SQLNET.AUTHENTICATION_SERVICES = (NTS) if not NTS change to NTS and restart database. Then retry with conn / as sysdba
When connected you can just call:
alter user sys identified by YOUR_NEW_PASS; or for SYSTEM user alter user SYSTEM identified by YOUR_NEW_PASS account unlock; and login with new password.
By the way why do you need to log as SYSTEM? Not just sys as sysdba? Some comparison about system accounts.
The instruction you got is for linux. In Windows one set environmental variables like shown here
from oracle version 12.2.x users cannot login using case insensitive passwords, even though SEC_CASE_SENSITIVE_LOGON = FALSE if PASSWORD_VERSIONS of user is not 10g.
following sql should show the PASSWORD_VERSIONS for a user.
select USERNAME,ACCOUNT_STATUS,PASSWORD_VERSIONS from dba_users;
USERNAME ACCOUNT_STATUS PASSWORD_VERSIONS
--------------- -------------- -----------------
dummyuser OPEN 11G 12C
to make PASSWORD_VERSIONS compatible with 10g
add/modify line in sqlnet.ora of database to have SQLNET.ALLOWED_LOGON_VERSION_SERVER=8
restart database
change/expire password for existing user
new users created will also have same settings
after above steps PASSWORD_VERSIONS should be something like this
select USERNAME,ACCOUNT_STATUS,PASSWORD_VERSIONS from dba_users;
USERNAME ACCOUNT_STATUS PASSWORD_VERSIONS
--------------- -------------- -----------------
dummyuser OPEN 10G 11G 12C

syntax error for command: "GRANT EXECUTE ON USERNAME.PKG.PROCEDURE TO OTHERUSER;"

I want to grant execute permission to user B so that it can execute a packaged procedure belonging to user A.
procedure name = PKGNAME.PROCEDURENAME
user = USERA
I am trying below command:
GRANT EXECUTE ON USERA.PKGNAME.PROCEDURENAME TO USERB;
But it gives me error:
ERROR at line 1:
ORA-00905: missing keyword
is there a syntax problem ? I used this link :
Granting Rights on Stored Procedure to another user of Oracle
you can't grant permissions on a procedure which is within a package, either grant permissions to the entire package or move the procedure outside of the package so it's a stand alone one and then grant permission
so either
GRANT EXECUTE ON USERA.PKGNAME TO USERB;
or
GRANT EXECUTE ON USERA.PROCEDURENAME TO USERB;

Oracle 11g XE initialization on ubuntu 12.04

I was following this tutorial:
http://sysadminnotebook.blogspot.com/2012/10/installing-oracle-11g-r2-express.html
and I sucessfully installed and started oracle database. Now I wanted to connect to that DB from bash, so I found that command:
sqlplus sys as sysdba
It asks for password, which in my case is oracle, and after I supply it, I get:
ORA-01031: insufficient privileges
What should I do?
EDIT:
I needed to add group dba and add myself to that group. However I've got other problem now. I wanted to create user, so I did:
CREATE USER myuser IDENTIFIED BY password
default tablespace users
temporary tablespace temp;
And I got: ORA-01034: ORACLE not available.
I tried: STARTUP But I got:
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/xe/dbs/initXE.ora'
I have '/u01/app/oracle/product/11.2.0/xe/dbs/init.ora' file but not initXE.ora
Is the o/s user a member of the dba group?
If this is a new installed Oracle and you do not have initXE.ora parameter file here /u01/app/oracle/product/11.2.0/xe/dbs/, that means you need to create XE DB first. To do that run /u01/app/oracle/product/11.2.0/xe/bin/createdb.sh script first.

How to run dbms_crypto functions in Oracle as regular user?

I have problem with using dbms_crypto.hash() function in Oracle.
I connected to database server using sqlplus as "sys/passwd as sysdba",
then I installed dbms_crypto package:
#/home/oracle/app/oracle/product/11.2.0/dbhome_1/rdbms/admin/dbmsobtk.sql
#/home/oracle/app/oracle/product/11.2.0/dbhome_1/rdbms/admin/prvtobtk.plb
Grant execute on dbms_crypto to public;
Grant execute on dbms_sqlhash to public;
Grant execute on dbms_obfuscation_toolkit to public;
Grant execute on dbms_obfuscation_toolkit_ffi to public;
Grant execute on dbms_crypto_ffi to public;
Everything looks good, so I tested hash() function:
SQL> select dbms_crypto.hash(utl_raw.cast_to_raw('zorg'), 3) from dual;
DBMS_CRYPTO.HASH(UTL_RAW.CAST_TO_RAW('ZORG'),3)
--------------------------------------------------------------------------------
60C440F9954CA4744204CDA9CC93567059C1EC82
I disconnected and connected to that database as regular user, but then I got error:
SQL> select dbms_crypto.hash(utl_raw.cast_to_raw('zorg'), 3) from dual;
select dbms_crypto.hash(utl_raw.cast_to_raw('zorg'), 3) from dual
*
ERROR at line 1:
ORA-06521: PL/SQL: Error mapping function
ORA-06512: at "MN.DBMS_CRYPTO_FFI", line 131
ORA-06512: at "MN.DBMS_CRYPTO", line 72
Why I cannot use this function as regular user? How to allow other users to use it?
I work with:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
Problem solved. I created package as wrong user. Proper way:
connect using:
sqlplus / as sysdba
Install packages:
#/home/oracle/app/oracle/product/11.2.0/dbhome_1/rdbms/admin/dbmsobtk.sql
#/home/oracle/app/oracle/product/11.2.0/dbhome_1/rdbms/admin/prvtobtk.plb
Connect as regular user and use functions from dbms_crypto package.

Resources