ORA-20000: Schema "HR" does not exist or insufficient privileges - oracle

I use Oracle 11g express. I try to install sample database HR. From cmd
sqlplus
system
123456
Error:
Comment created.
Commit complete.
BEGIN dbms_stats.gather_schema_stats( 'HR' , granularity => 'ALL' , cascade => TRUE , block_sample => TRUE ); END;
*
ERROR at line 1:
ORA-20000: Schema "HR" does not exist or insufficient privileges
ORA-06512: at "SYS.DBMS_STATS", line 3701
ORA-06512: at "SYS.DBMS_STATS", line 24470
ORA-06512: at "SYS.DBMS_STATS", line 24435
ORA-06512: at line 1
How I install sample database HR correctly?

Apparently the statement to create the user hr was not executed correctly, and despite that the execution of the hr_main.sql script is not stopped.
This worked for me:
Once as sysdba:
SQL> alter session set "_ORACLE_SCRIPT"=true;
Session altered.
SQL> create user hr identified by hr;
User created.
SQL> drop user hr cascade;
User droped.
SQL> #?/demo/schema/human_resources/hr_main.sql
...
User created.
...

Navigate to the PDB container as SYS user before executing the script
[oracle#af18354c958e /]$ sqlplus sys as sysdba
Enter password: password
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL> alter session set container = ORCLPDB1
SQL> #hr_main.sql
specify password for HR as parameter 1:
Enter value for 1: hr
specify default tablespeace for HR as parameter 2:
Enter value for 2: users
specify temporary tablespace for HR as parameter 3:
Enter value for 3: temp
specify log path as parameter 4:
Enter value for 4: $ORACLE_HOME/demo/schema/log/

The problem is the line
create user hr identified by 123456a#
Because user is not created, you are getting other errors.
To resolve it do either of below
Remove special character from password. Or use underscores _ in password.
create user hr identified by 123456a
OR
Try enclosing password in double quotes. (I am not able to test it now. But if it doesn't work, try first option. I referred this link)
create user hr identified by "123456a#"

Related

Cannot install HR schema for Oracle 21c express

I watched video tutorial at https://www.youtube.com/watch?v=IalqQN09OaA . My Oracle database version
select * from v$version;
Oracle Database 21c Express Edition Release 21.0.0.0.0 - Production
I download sample at https://github.com/donhuvy/db-sample-schemas/tree/main/human_resources .
Inside Oracle SQL Developer version 22.x , with user system, Run command
# C:\Users\Administrator\Downloads\db-sample-schemas-21.1\human_resources\hr_main.sql
I entered
Input 1: Password for HR: 123456
Input 2: Tablespace: SYSTEM
Input 3: Temporary tablespace: TEMP
Input 4: Password for SYSTEM user: 12345678
Input 5: Log path: C:\
Input 6: Connection string: localhost:1521/xe
My steps
localhost:1521/xe
Error
specify password for HR as parameter 1:
specify default tablespeace for HR as parameter 2:
specify temporary tablespace for HR as parameter 3:
specify password for SYS as parameter 4:
specify log path as parameter 5:
specify connect string as parameter 6:
Error starting at line : 86 File # C:\Users\Administrator\Downloads\db-sample-schemas-21.1\human_resources\hr_main.sql
In command -
DROP USER hr CASCADE
Error report -
ORA-01918: user 'HR' does not exist
01918. 00000 - "user '%s' does not exist"
*Cause: User does not exist in the system.
*Action: Verify the user name is correct.
Error starting at line : 95 File # C:\Users\Administrator\Downloads\db-sample-schemas-21.1\human_resources\hr_main.sql
In command -
CREATE USER hr IDENTIFIED BY &pass
Error report -
ORA-65096: invalid common user or role name
65096. 00000 - "invalid common user or role name"
*Cause: An attempt was made to create a common user or role with a name
that was not valid for common users or roles. In addition to the
usual rules for user and role names, common user and role names
must consist only of ASCII characters, and must contain the prefix
specified in common_user_prefix parameter.
*Action: Specify a valid common user or role name.
Error starting at line : 97 File # C:\Users\Administrator\Downloads\db-sample-schemas-21.1\human_resources\hr_main.sql
In command -
ALTER USER hr DEFAULT TABLESPACE &tbs
QUOTA UNLIMITED ON &tbs
Error report -
ORA-01918: user 'HR' does not exist
01918. 00000 - "user '%s' does not exist"
*Cause: User does not exist in the system.
*Action: Verify the user name is correct.
Error starting at line : 100 File # C:\Users\Administrator\Downloads\db-sample-schemas-21.1\human_resources\hr_main.sql
In command -
ALTER USER hr TEMPORARY TABLESPACE &ttbs
Error report -
ORA-01918: user 'HR' does not exist
01918. 00000 - "user '%s' does not exist"
*Cause: User does not exist in the system.
*Action: Verify the user name is correct.
Error starting at line : 102 File # C:\Users\Administrator\Downloads\db-sample-schemas-21.1\human_resources\hr_main.sql
In command -
GRANT CREATE SESSION, CREATE VIEW, ALTER SESSION, CREATE SEQUENCE TO hr
Error report -
ORA-01917: user or role 'HR' does not exist
01917. 00000 - "user or role '%s' does not exist"
*Cause: There is not a user or role by that name.
*Action: Re-specify the name.
Error starting at line : 103 File # C:\Users\Administrator\Downloads\db-sample-schemas-21.1\human_resources\hr_main.sql
In command -
GRANT CREATE SYNONYM, CREATE DATABASE LINK, RESOURCE , UNLIMITED TABLESPACE TO hr
Error report -
ORA-01917: user or role 'HR' does not exist
01917. 00000 - "user or role '%s' does not exist"
*Cause: There is not a user or role by that name.
*Action: Re-specify the name.
Connected.
Error starting at line : 110 File # C:\Users\Administrator\Downloads\db-sample-schemas-21.1\human_resources\hr_main.sql
In command -
GRANT execute ON sys.dbms_stats TO hr
Error report -
ORA-01917: user or role 'HR' does not exist
01917. 00000 - "user or role '%s' does not exist"
*Cause: There is not a user or role by that name.
*Action: Re-specify the name.
Error starting at line : 116 File # C:\Users\Administrator\Downloads\db-sample-schemas-21.1\human_resources\hr_main.sql
In command -
connect ...
Error report -
Connection Failed
USER = hr
URL = jdbc:oracle:thin:#localhost:1521/xe
Error Message = ORA-01017: invalid username/password; logon denied
Commit
SP2-0640: Not connected
SP2-0640: Not connected
Error starting at line : 124 File # C:\Users\Administrator\Downloads\db-sample-schemas-21.1\human_resources\hr_main.sql
In command -
#__SUB__CWD__/human_resources/hr_cre
Error report -
SP2-0310: Unable to open file: "__SUB__CWD__/human_resources/hr_cre.sql"
Error starting at line : 130 File # C:\Users\Administrator\Downloads\db-sample-schemas-21.1\human_resources\hr_main.sql
In command -
#__SUB__CWD__/human_resources/hr_popul
Error report -
SP2-0310: Unable to open file: "__SUB__CWD__/human_resources/hr_popul.sql"
Error starting at line : 136 File # C:\Users\Administrator\Downloads\db-sample-schemas-21.1\human_resources\hr_main.sql
In command -
#__SUB__CWD__/human_resources/hr_idx
Error report -
SP2-0310: Unable to open file: "__SUB__CWD__/human_resources/hr_idx.sql"
Error starting at line : 142 File # C:\Users\Administrator\Downloads\db-sample-schemas-21.1\human_resources\hr_main.sql
In command -
#__SUB__CWD__/human_resources/hr_code
Error report -
SP2-0310: Unable to open file: "__SUB__CWD__/human_resources/hr_code.sql"
Error starting at line : 148 File # C:\Users\Administrator\Downloads\db-sample-schemas-21.1\human_resources\hr_main.sql
In command -
#__SUB__CWD__/human_resources/hr_comnt
Error report -
SP2-0310: Unable to open file: "__SUB__CWD__/human_resources/hr_comnt.sql"
Error starting at line : 154 File # C:\Users\Administrator\Downloads\db-sample-schemas-21.1\human_resources\hr_main.sql
In command -
#__SUB__CWD__/human_resources/hr_analz
Error report -
SP2-0310: Unable to open file: "__SUB__CWD__/human_resources/hr_analz.sql"
How to fix?
Update
Use command
alter session set "_oracle_script"=true;
# C:\Users\Administrator\Downloads\db-sample-schemas-21.1\human_resources\hr_main.sql
Session altered.
specify password for HR as parameter 1:
specify default tablespeace for HR as parameter 2:
specify temporary tablespace for HR as parameter 3:
specify password for SYS as parameter 4:
specify log path as parameter 5:
specify connect string as parameter 6:
User HR dropped.
User HR created.
User HR altered.
User HR altered.
Grant succeeded.
Grant succeeded.
Connected.
Grant succeeded.
Connected.
Session altered.
Session altered.
Error starting at line : 124 File # C:\Users\Administrator\Downloads\db-sample-schemas-21.1\human_resources\hr_main.sql
In command -
#__SUB__CWD__/human_resources/hr_cre
Error report -
SP2-0310: Unable to open file: "__SUB__CWD__/human_resources/hr_cre.sql"
Error starting at line : 130 File # C:\Users\Administrator\Downloads\db-sample-schemas-21.1\human_resources\hr_main.sql
In command -
#__SUB__CWD__/human_resources/hr_popul
Error report -
SP2-0310: Unable to open file: "__SUB__CWD__/human_resources/hr_popul.sql"
Error starting at line : 136 File # C:\Users\Administrator\Downloads\db-sample-schemas-21.1\human_resources\hr_main.sql
In command -
#__SUB__CWD__/human_resources/hr_idx
Error report -
SP2-0310: Unable to open file: "__SUB__CWD__/human_resources/hr_idx.sql"
Error starting at line : 142 File # C:\Users\Administrator\Downloads\db-sample-schemas-21.1\human_resources\hr_main.sql
In command -
#__SUB__CWD__/human_resources/hr_code
Error report -
SP2-0310: Unable to open file: "__SUB__CWD__/human_resources/hr_code.sql"
Error starting at line : 148 File # C:\Users\Administrator\Downloads\db-sample-schemas-21.1\human_resources\hr_main.sql
In command -
#__SUB__CWD__/human_resources/hr_comnt
Error report -
SP2-0310: Unable to open file: "__SUB__CWD__/human_resources/hr_comnt.sql"
Error starting at line : 154 File # C:\Users\Administrator\Downloads\db-sample-schemas-21.1\human_resources\hr_main.sql
In command -
#__SUB__CWD__/human_resources/hr_analz
Error report -
SP2-0310: Unable to open file: "__SUB__CWD__/human_resources/hr_analz.sql"
Connection created by CONNECT script command disconnected
PL/SQL procedure successfully completed.
DBMS_SYSTEM.GET_ENV
Alias sqlcl_int_runme dropped
How to fix error
Error report -
SP2-0310: Unable to open file: "__SUB__CWD__/human_resources/hr_idx.sql"
Unfortunately the default sample script installation process is not great for the novice. Please head over to this blog post
https://connor-mcdonald.com/2021/11/02/quick-and-easy-sample-data/
which describes why this is the case, but more importantly will give you a workaround which involves just running a single script in SQL*Plus. That script will also try to guide you through the process to avoid any errors, eg
| 1) Preliminary checks
| =====================
|
| You should be connected to the database at this point.
| If you are, then you will see the following:
|
| >>> Connected as: YOUR_USER <<<
|
| If you are not, you're will see the following
|
| >>>> SP2-0640: Not connected <<<<
|
| If you get this error, press Ctrl-C to exit this script and
| connect first before running it again.
|
| Tip: For Express Edition, the command to connect is *probably*
|
| SQL> connect system/yourpassword#//localhost/XEPDB1
|
| Once you are connected OK, then press Enter to proceed
|
Connected as: MCDONAC
Enter to proceed, Ctrl-C to stop
|
| Checking that we can write a file to the current directory
| If we can't, then this script will exit here. Please make
| you are running the script from the directory you saved it to
| and this directory is writable
|
File test passed!
|
|
| Now checking database details. If any of these fail,
| the script will exit with the error that you need
| to resolve.
|
Container database. PDB PDB1 will be used for installation...proceeding
|
| Checking current user details
|
You are connected as MCDONAC, ie, not the HR schema.
Hence this installation will drop the HR schema entirely
and recreate it. If this was not what you wanted, then press Ctrl-C
the installation, otherwise press Enter to continue
Enter to proceed, Ctrl-C to stop
|
| Checking required privileges
|
Privilege ALTER ANY TABLE..................OK
Privilege ALTER ANY TRIGGER................OK
Privilege ALTER SESSION....................OK
Privilege ALTER USER.......................OK
Privilege ANALYZE ANY......................OK
Privilege COMMENT ANY TABLE................OK
Privilege CREATE ANY CLUSTER...............OK
Privilege CREATE ANY INDEX.................OK
Privilege CREATE ANY INDEXTYPE.............OK
Privilege CREATE ANY OPERATOR..............OK
Privilege CREATE ANY PROCEDURE.............OK
Privilege CREATE ANY SEQUENCE..............OK
Privilege CREATE ANY SYNONYM...............OK
Privilege CREATE ANY TABLE.................OK
Privilege CREATE ANY TRIGGER...............OK
Privilege CREATE ANY TYPE..................OK
Privilege CREATE ANY VIEW..................OK
Privilege CREATE SESSION...................OK
Privilege CREATE USER......................OK
Privilege DELETE ANY TABLE.................OK
Privilege DROP USER........................OK
Privilege GRANT ANY OBJECT PRIVILEGE.......OK
Privilege GRANT ANY PRIVILEGE..............OK
Privilege INSERT ANY TABLE.................OK
Privilege SELECT ANY TABLE.................OK
Privilege UPDATE ANY TABLE.................OK
Privilege SELECT ON GV$SESSION.............OK
|
| Checking tablespaces
|
Checks .......OK
|
| Checking existing HR details
|
Checks .......OK
|
| The new/replaced HR schema will be created now.
|
| Note down this password for the HR schema. You will need it to connect
|
| Password (case-sensitive): DAjcBlFOJq$986
|
| The script will exit on any error encountered, because it should run
| to completion with no errors at all
|
Press Enter to start
****** Creating REGIONS table ....
Table created.
Index created.
Table altered.
etc etc

Configuring Oracle XStream

I'm trying to configure Oracle XStream out by official documentation
So, shortly, I'm connecting as sysdba
sqlplus / as sysdba
Then executing commands create create CDB user and give him privileges
> CREATE TABLESPACE xstream_tbs DATAFILE '$ORACLE/cdb/orcl/xstream_tbs.dbf' SIZE 25M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;
> CREATE USER c##xstrmadmin IDENTIFIED BY password DEFAULT TABLESPACE xstream_tbs QUOTA UNLIMITED ON xstream_tbs container=all;
> GRANT CREATE SESSION, SET CONTAINER TO c##xstrmadmin CONTAINER=ALL;
After this step I should give permissions to user to use XStream
> BEGIN
DBMS_XSTREAM_AUTH.GRANT_ADMIN_PRIVILEGE(
grantee => 'c##xstrmadmin',
privilege_type => 'CAPTURE',
grant_select_privileges => TRUE,
container => 'ALL');
END;
/
On this stage, I'm getting this error:
ERROR at line 1:
ORA-44001: invalid schema
ORA-06512: at "SYS.DBMS_XSTREAM_AUTH_IVK", line 3383
ORA-06512: at line 1
ORA-06512: at "SYS.DBMS_XSTREAM_AUTH_IVK", line 3500
ORA-06512: at "SYS.DBMS_XSTREAM_AUTH", line 34
ORA-06512: at line 2
Current container is cdb$root
Googling gives actually nothing and I have no idea whats wrong as I'm following DBA documentation.
I guess I found workaround.
If you connect to oracle with
> sqlplus /nolog
And then connect as sysdba
> conn / as sysdba
Then all works fine!
If this is only one way to resolve problem with creating permissions then problem is in sqlplus or oracle itself. Sad!

Accessing a function against another owner in oracle?

I am having a function called fn_export and its owner is bhist. I am calling this function from ohist user using bhist.fn_export. While calling like this I am facing the below issue.
ORA-00942: table or view does not exist
ORA-06512: at "bhist.fn_export", line 442
ORA-06512: at line 20
I tried to verify all the tables in that function and I am able to access all those tables from ohist. I have execute grant on bhist.fn_export to ohist. Still I am having this issue. Can any one of you please help in resolving this issue?
Thanks,
Venkat
You need to grant EXECUTE privilege on this function to ohist user.
A syntax is:
GRANT EXECUTE ON function_name TO username;
You can connect as bhist user and grant the privilege using:
GRANT EXECUTE ON fn_export TO ohist;
You can also connect as SYS or SYSTEM, and use this command:
GRANT EXECUTE ON bhist.fn_export TO ohist;
See a below simple example (one user is named TEST and the other is named DEV):
SQL> connect test
Enter password:
Connected.
SQL> CREATE FUNCTION fn_export RETURN number AS
2 BEGIN
3 RETURN 20;
4 END;
5 /
Function created.
SQL> connect dev
Enter password:
Connected.
SQL> SELECT test.fn_export FROM dual;
SELECT test.fn_export FROM dual
*
ERROR at line 1:
ORA-00904: "TEST"."FN_EXPORT": invalid identifier
SQL> connect test
Enter password:
Connected.
SQL> grant execute on fn_export to dev;
Grant succeeded.
SQL> connect dev
Enter password:
Connected.
SQL> SELECT test.fn_export FROM dual;
FN_EXPORT
----------
20
SQL>

Trouble installing SQL Developer OE (Order Entry) sample database

I've been at this for literally hours. I've followed the instructions here - http://docs.oracle.com/database/121/COMSC/installation.htm#COMSC109 - but I get the following when arriving at the 'Installing Schema OE and Subschema OC' section and doing as it says, running oe_main.sql;
specify password for OE as parameter 1:
old:DEFINE pass = &1
new:DEFINE pass = oe
specify default tablespeace for OE as parameter 2:
old:DEFINE tbs = &2
new:DEFINE tbs = OE
specify temporary tablespace for OE as parameter 3:
old:DEFINE ttbs = &3
new:DEFINE ttbs = temp
specify password for HR as parameter 4:
old:DEFINE passhr = &4
new:DEFINE passhr = hr
specify password for SYS as parameter 5:
old:DEFINE pass_sys = &5
new:DEFINE pass_sys = manager
specify directory path for the data files as parameter 6:
old:DEFINE data_path = &6
new:DEFINE data_path = C:\
writeable directory path for the log files as parameter 7:
old:DEFINE log_path = &7
new:DEFINE log_path = C:\
specify version as parameter 8:
old:DEFINE vrs = &8
new:DEFINE vrs = 5
old:DEFINE spool_file = &log_path.oe_oc_&vrs..log
new:DEFINE spool_file = C:\oe_oc_5.log
old:SPOOL &spool_file
new:SPOOL C:\oe_oc_5.log
Error starting at line : 75 in command -
DROP USER oe CASCADE
Error report -
SQL Error: ORA-01918: user 'OE' does not exist
01918. 00000 - "user '%s' does not exist"
*Cause: User does not exist in the system.
*Action: Verify the user name is correct.
old:CREATE USER oe IDENTIFIED BY &pass
new:CREATE USER oe IDENTIFIED BY oe
Error starting at line : 86 in command -
CREATE USER oe IDENTIFIED BY oe
Error at Command Line : 86 Column : 30
Error report -
SQL Error: ORA-01031: insufficient privileges
01031. 00000 - "insufficient privileges"
*Cause: An attempt was made to perform a database operation without
the necessary privileges.
*Action: Ask your database administrator or designated security
administrator to grant you the necessary privileges
old:ALTER USER oe DEFAULT TABLESPACE &tbs QUOTA UNLIMITED ON &tbs
new:ALTER USER oe DEFAULT TABLESPACE temp QUOTA UNLIMITED ON temp
Error starting at line : 88 in command -
ALTER USER oe DEFAULT TABLESPACE &tbs QUOTA UNLIMITED ON &tbs
Error report -
SQL Error: ORA-01031: insufficient privileges
01031. 00000 - "insufficient privileges"
*Cause: An attempt was made to perform a database operation without
the necessary privileges.
*Action: Ask your database administrator or designated security
administrator to grant you the necessary privileges
old:ALTER USER oe TEMPORARY TABLESPACE &ttbs
new:ALTER USER oe TEMPORARY TABLESPACE temp
Error starting at line : 90 in command -
ALTER USER oe TEMPORARY TABLESPACE &ttbs
Error report -
SQL Error: ORA-01031: insufficient privileges
01031. 00000 - "insufficient privileges"
*Cause: An attempt was made to perform a database operation without
the necessary privileges.
*Action: Ask your database administrator or designated security
administrator to grant you the necessary privileges
Error starting at line : 92 in command -
GRANT CREATE SESSION, CREATE SYNONYM, CREATE VIEW TO oe
Error report -
SQL Error: ORA-01031: insufficient privileges
01031. 00000 - "insufficient privileges"
*Cause: An attempt was made to perform a database operation without
the necessary privileges.
*Action: Ask your database administrator or designated security
administrator to grant you the necessary privileges
Error starting at line : 93 in command -
GRANT CREATE DATABASE LINK, ALTER SESSION TO oe
Error report -
SQL Error: ORA-01031: insufficient privileges
01031. 00000 - "insufficient privileges"
*Cause: An attempt was made to perform a database operation without
the necessary privileges.
*Action: Ask your database administrator or designated security
administrator to grant you the necessary privileges
Error starting at line : 94 in command -
GRANT RESOURCE TO oe
Error report -
SQL Error: ORA-01031: insufficient privileges
01031. 00000 - "insufficient privileges"
*Cause: An attempt was made to perform a database operation without
the necessary privileges.
*Action: Ask your database administrator or designated security
administrator to grant you the necessary privileges
Error starting at line : 95 in command -
GRANT CREATE MATERIALIZED VIEW TO oe
Error report -
SQL Error: ORA-01031: insufficient privileges
01031. 00000 - "insufficient privileges"
*Cause: An attempt was made to perform a database operation without
the necessary privileges.
*Action: Ask your database administrator or designated security
administrator to grant you the necessary privileges
Error starting at line : 96 in command -
GRANT QUERY REWRITE TO oe
Error report -
SQL Error: ORA-01031: insufficient privileges
01031. 00000 - "insufficient privileges"
*Cause: An attempt was made to perform a database operation without
the necessary privileges.
*Action: Ask your database administrator or designated security
administrator to grant you the necessary privileges
old:CONNECT sys/&pass_sys AS SYSDBA
new:CONNECT sys/manager AS SYSDBA
Connected
Error starting at line : 103 in command -
GRANT execute ON sys.dbms_stats TO oe
Error report -
SQL Error: ORA-01917: user or role 'OE' does not exist
01917. 00000 - "user or role '%s' does not exist"
*Cause: There is not a user or role by that name.
*Action: Re-specify the name.
old:CONNECT hr/&passhr
new:CONNECT hr/hr
Connected
Error starting at line : 110 in command -
GRANT REFERENCES, SELECT ON employees TO oe
Error report -
SQL Error: ORA-01917: user or role 'OE' does not exist
01917. 00000 - "user or role '%s' does not exist"
*Cause: There is not a user or role by that name.
*Action: Re-specify the name.
Error starting at line : 111 in command -
GRANT REFERENCES, SELECT ON countries TO oe
Error report -
SQL Error: ORA-01917: user or role 'OE' does not exist
01917. 00000 - "user or role '%s' does not exist"
*Cause: There is not a user or role by that name.
*Action: Re-specify the name.
Error starting at line : 112 in command -
GRANT REFERENCES, SELECT ON locations TO oe
Error report -
SQL Error: ORA-01917: user or role 'OE' does not exist
01917. 00000 - "user or role '%s' does not exist"
*Cause: There is not a user or role by that name.
*Action: Re-specify the name.
Error starting at line : 113 in command -
GRANT SELECT ON jobs TO oe
Error report -
SQL Error: ORA-01917: user or role 'OE' does not exist
01917. 00000 - "user or role '%s' does not exist"
*Cause: There is not a user or role by that name.
*Action: Re-specify the name.
Error starting at line : 114 in command -
GRANT SELECT ON job_history TO oe
Error report -
SQL Error: ORA-01917: user or role 'OE' does not exist
01917. 00000 - "user or role '%s' does not exist"
*Cause: There is not a user or role by that name.
*Action: Re-specify the name.
Error starting at line : 115 in command -
GRANT SELECT ON departments TO oe
Error report -
SQL Error: ORA-01917: user or role 'OE' does not exist
01917. 00000 - "user or role '%s' does not exist"
*Cause: There is not a user or role by that name.
*Action: Re-specify the name.
old:CONNECT oe/&pass
new:CONNECT oe/oe
Error starting at line : 122 in command -
CONNECT oe/&pass
Error report -
Connection Failed
Commit
The problems start with 'User 'OE' doesn't exist'. Any Oracle DBA available for some guidance?
Running this in Oracle SQL Developer, and tried the same in SQLPlus - same results.
EDIT:
Now seeing this;
specify password for OE as parameter 1:
old:DEFINE pass = &1
new:DEFINE pass = oe
specify default tablespeace for OE as parameter 2:
old:DEFINE tbs = &2
new:DEFINE tbs = OE
specify temporary tablespace for OE as parameter 3:
old:DEFINE ttbs = &3
new:DEFINE ttbs = temp
specify password for HR as parameter 4:
old:DEFINE passhr = &4
new:DEFINE passhr = hr
specify password for SYS as parameter 5:
old:DEFINE pass_sys = &5
new:DEFINE pass_sys = password
specify directory path for the data files as parameter 6:
old:DEFINE data_path = &6
new:DEFINE data_path = C:\
writeable directory path for the log files as parameter 7:
old:DEFINE log_path = &7
new:DEFINE log_path = C:\log
specify version as parameter 8:
old:DEFINE vrs = &8
new:DEFINE vrs = v3
old:DEFINE spool_file = &log_path.oe_oc_&vrs..log
new:DEFINE spool_file = C:\logoe_oc_v3.log
old:SPOOL &spool_file
new:SPOOL C:\logoe_oc_v3.log
user OE dropped.
old:CREATE USER oe IDENTIFIED BY &pass
new:CREATE USER oe IDENTIFIED BY oe
user OE created.
old:ALTER USER oe DEFAULT TABLESPACE &tbs QUOTA UNLIMITED ON &tbs
new:ALTER USER oe DEFAULT TABLESPACE OE QUOTA UNLIMITED ON OE
Error starting at line : 96 in command -
ALTER USER oe DEFAULT TABLESPACE &tbs QUOTA UNLIMITED ON &tbs
Error report -
SQL Error: ORA-00959: tablespace 'OE' does not exist
00959. 00000 - "tablespace '%s' does not exist"
*Cause:
*Action:
old:ALTER USER oe TEMPORARY TABLESPACE &ttbs
new:ALTER USER oe TEMPORARY TABLESPACE temp
user OE altered.
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
old:CONNECT sys/&pass_sys AS SYSDBA
new:CONNECT sys/password AS SYSDBA
Connected
GRANT succeeded.
old:CONNECT hr/&passhr
new:CONNECT hr/hr
Connected
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
old:CONNECT oe/&pass
new:CONNECT oe/oe
Connected
session SET altered.
session SET altered.
old:DEFINE vscript = ?/demo/schema/order_entry/coe_&vrs
new:DEFINE vscript = ?/demo/schema/order_entry/coe_v3
old:#&vscript &vrs &pass &pass_sys
new:#?/demo/schema/order_entry/coe_v3 v3 oe password
Error starting at line : 139 in command -
#&vscript &vrs &pass &pass_sys
Error report -
Unable to open file: "?/demo/schema/order_entry/coe_v3.sql"
old:DEFINE vscript = ?/demo/schema/order_entry/loe_&vrs
new:DEFINE vscript = ?/demo/schema/order_entry/loe_v3
old:#&vscript &vrs &data_path &log_path &pass
new:#?/demo/schema/order_entry/loe_v3 v3 C:\ C:\log oe
Error starting at line : 146 in command -
#&vscript &vrs &data_path &log_path &pass
Error report -
Unable to open file: "?/demo/schema/order_entry/loe_v3.sql"
old:DEFINE vscript = ?/demo/schema/order_entry/poe_&vrs
new:DEFINE vscript = ?/demo/schema/order_entry/poe_v3
old:#&vscript &vrs
new:#?/demo/schema/order_entry/poe_v3 v3
Error starting at line : 153 in command -
#&vscript &vrs
Error report -
Unable to open file: "?/demo/schema/order_entry/poe_v3.sql"
Error starting at line : 159 in command -
#?/demo/schema/order_entry/oc_main
Error report -
Unable to open file: "?/demo/schema/order_entry/oc_main.sql"
Error starting at line : 165 in command -
#?/demo/schema/order_entry/oe_analz
Error report -
Unable to open file: "?/demo/schema/order_entry/oe_analz.sql"
Connection created by CONNECT script command disconnected
The first error is 'tablespace 'OE' does not exist' - surely the whole point is to create it? And then line above appears to be trying to do that.
There's also errors retrieving the data (Unable to open file) - is that because I specified only C:\ (incidentally when I have this working I'll change that, I just got fed up with copying and pasting the complete path every time)? I've tried specifying C:\app\Hamish\product\11.2.0\dbhome_1\demo\schema\order_entry which is where the data is but I get the same result as above.
EDIT 2:
Now I'm seeing this;
As per my comments to the guys who gave feedback below - am I supposed to put the /demo/... somewhere in the SQL Developer directory so it can automatically find the files?
specify password for OE as parameter 1:
old:DEFINE pass = &1
new:DEFINE pass = oe
specify default tablespeace for OE as parameter 2:
old:DEFINE tbs = &2
new:DEFINE tbs = users
specify temporary tablespace for OE as parameter 3:
old:DEFINE ttbs = &3
new:DEFINE ttbs = temp
specify password for HR as parameter 4:
old:DEFINE passhr = &4
new:DEFINE passhr = hr
specify password for SYS as parameter 5:
old:DEFINE pass_sys = &5
new:DEFINE pass_sys = password
specify directory path for the data files as parameter 6:
old:DEFINE data_path = &6
new:DEFINE data_path = C:/
writeable directory path for the log files as parameter 7:
old:DEFINE log_path = &7
new:DEFINE log_path = C:/log
specify version as parameter 8:
old:DEFINE vrs = &8
new:DEFINE vrs = v3
old:DEFINE spool_file = &log_path.oe_oc_&vrs..log
new:DEFINE spool_file = C:/logoe_oc_v3.log
old:SPOOL &spool_file
new:SPOOL C:/logoe_oc_v3.log
user OE dropped.
old:CREATE USER oe IDENTIFIED BY &pass
new:CREATE USER oe IDENTIFIED BY oe
user OE created.
old:ALTER USER oe DEFAULT TABLESPACE &tbs QUOTA UNLIMITED ON &tbs
new:ALTER USER oe DEFAULT TABLESPACE users QUOTA UNLIMITED ON users
user OE altered.
old:ALTER USER oe TEMPORARY TABLESPACE &ttbs
new:ALTER USER oe TEMPORARY TABLESPACE temp
user OE altered.
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
old:CONNECT sys/&pass_sys AS SYSDBA
new:CONNECT sys/password AS SYSDBA
Connected
GRANT succeeded.
old:CONNECT hr/&passhr
new:CONNECT hr/hr
Connected
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
old:CONNECT oe/&pass
new:CONNECT oe/oe
Connected
session SET altered.
session SET altered.
old:DEFINE vscript = ?/demo/schema/order_entry/coe_&vrs
new:DEFINE vscript = ?/demo/schema/order_entry/coe_v3
old:#&vscript &vrs &pass &pass_sys
new:#?/demo/schema/order_entry/coe_v3 v3 oe password
Error starting at line : 131 in command -
#&vscript &vrs &pass &pass_sys
Error report -
Unable to open file: "?/demo/schema/order_entry/coe_v3.sql"
old:DEFINE vscript = ?/demo/schema/order_entry/loe_&vrs
new:DEFINE vscript = ?/demo/schema/order_entry/loe_v3
old:#&vscript &vrs &data_path &log_path &pass
new:#?/demo/schema/order_entry/loe_v3 v3 C:/ C:/log oe
Error starting at line : 138 in command -
#&vscript &vrs &data_path &log_path &pass
Error report -
Unable to open file: "?/demo/schema/order_entry/loe_v3.sql"
old:DEFINE vscript = ?/demo/schema/order_entry/poe_&vrs
new:DEFINE vscript = ?/demo/schema/order_entry/poe_v3
old:#&vscript &vrs
new:#?/demo/schema/order_entry/poe_v3 v3
Error starting at line : 145 in command -
#&vscript &vrs
Error report -
Unable to open file: "?/demo/schema/order_entry/poe_v3.sql"
Error starting at line : 151 in command -
#?/demo/schema/order_entry/oc_main
Error report -
Unable to open file: "?/demo/schema/order_entry/oc_main.sql"
Error starting at line : 157 in command -
#?/demo/schema/order_entry/oe_analz
Error report -
Unable to open file: "?/demo/schema/order_entry/oe_analz.sql"
Connection created by CONNECT script command disconnected
EDIT 3: I went into each file and manually changed the #? for #C:/[path to..]/demo/schema ... etc. Once it could find the files the process completed but it was painful amending every single #? - if there's an easier way to do this I'd like to hear it.
FYI for anyone struggling with this process going forward (evidently that's not many people as there's very little on the internet about this):
Make sure you're logged in as sys/[sys password]. You can change this via SQLPlus if you're not sure by using sqlplus / as sysdba and then use an ALTER statement to change the password.
Specify for the input: default OE tablespace "users".
Update all the #? to the directory your files are stored.
The output shows a series of ORA-01031: insufficient privileges for activities like CREATE USER. Clearly you are not running this script whilst connected as SYSDBA account.
The script itself states:
rem NOTES
rem Run as SYS or SYSTEM
Note that you need to connect AS SYSDBA. It's better to use an OS account that's part of the DBA group. Check your connection properties in SQL Developer. See this. Or in SQL*Plus you do something like this:
SQL> show user
USER is "APC"
SQL> connect / as sysdba
Connected.
SQL> show user
USER is "SYS"
SQL>
By the way, it's very bad practice to specify the root directory for everything DEFINE data_path = C:\. I hope that's not what you're really doing. Finding files will be an absolute nightmare.
Although this is installation is for 12c, I have found that it does not reckon with that this must be performed against a pluggable database, and not against the container database. It seems it is built for 12C databases that do not use cdb/pdb. To make this work for a pdb you have to:
beforehand connect with sys to the pdb where you want the HR and OE schemas.
Edit the hr_main.sql and oe_main sql lines that do a CONNECT and add #[pdbname] to it. This has to be done for CONNECT with hr, oe and sys
Example: CONNECT oe/&pass has to be changed to CONNECT oe/&pass#[pdb name]

Oracle privilege missing for DBMS_SCHEDULER, ORA-27486 after GRANT CREATE JOB, CREATE EXTERNAL JOB

What additional privilege am I missing?
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL>
SQL> create user myUser identified by password default tablespace theData temporary tablespace temp;
User created.
SQL> grant connect, resource to myUser;
Grant succeeded.
SQL> GRANT READ,WRITE ON DIRECTORY tmp TO myUser;
Grant succeeded.
SQL> GRANT CREATE JOB TO myUser;
Grant succeeded.
SQL> GRANT CREATE EXTERNAL JOB TO myUser;
Grant succeeded.
SQL> connect myUser/password
Connected.
SQL>
SQL>
1 CREATE PROCEDURE shellScript
2 AS
3 /*-----------------------*/
4 v_sql UTL_FILE.FILE_TYPE;
5 v_shell UTL_FILE.FILE_TYPE;
6 /*=======================*/
7 BEGIN
8 /*=======================*/
9 -- write the sql script to /tmp/myUser-tmp-script.sql
10 v_sql:= UTL_FILE.FOPEN('TMP','myUser-tmp-script.sql','w');
11 UTL_FILE.PUT_LINE(v_sql,'select to_char(sysdate,''YYYYMMDDHR24MISS'') from dual'||';', FALSE);
12 UTL_FILE.FFLUSH(v_sql);
13 UTL_FILE.FCLOSE(v_sql);
14 -- write the shell script to /tmp/myUser-tmp-script.sh
15 v_shell:= UTL_FILE.FOPEN('TMP','myUser-tmp-script.sh','w');
16 UTL_FILE.PUT_LINE(v_shell,'#!/bin/bash', FALSE);
17 UTL_FILE.PUT_LINE(v_shell,'sqlplus myUser/password#sbox #/tmp/myUser-tmp-script.sql > /tmp/myUser-tmp-script.err', FALSE);
18 UTL_FILE.FFLUSH(v_shell);
19 UTL_FILE.FCLOSE(v_shell);
20 -- execute the shell script which executes the sql script
21 DBMS_SCHEDULER.PURGE_LOG(JOB_NAME=>'myJob');
22 DBMS_SCHEDULER.CREATE_JOB(JOB_NAME=>'myJob', JOB_TYPE=>'EXECUTABLE', JOB_ACTION=>'/bin/bash', NUMBER_OF_ARGUMENTS=>1, START_DATE=>SYSTIMESTAMP, ENABLED=>FALSE);
23 DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE('myJob', 1, '/tmp/myUser-tmp-script.sh');
24 DBMS_SCHEDULER.ENABLE('myJob');
25 USER_LOCK.SLEEP(500); -- give it 5 seconds to complete
26 -- clean up
27 UTL_FILE.FREMOVE('TMP', 'myUser-tmp-script.sh');
28 UTL_FILE.FREMOVE('TMP', 'myUser-tmp-script.sql');
29 /*=======================*/
30 END shellScript;
/
Procedure created.
SQL> SHOW ERRORS PROCEDURE shellScript
No errors.
SQL>
SQL>
SQL> execute shellScript;
BEGIN shellScript; END;
*
ERROR at line 1:
ORA-27486: insufficient privileges
ORA-06512: at "SYS.DBMS_ISCHED", line 411
ORA-06512: at "SYS.DBMS_ISCHED", line 452
ORA-06512: at "SYS.DBMS_SCHEDULER", line 1082
ORA-06512: at "MYUSER.SHELLSCRIPT", line 21
ORA-06512: at line 1
SQL>
According to TFM, PURGE_LOG requires the MANAGE SCHEDULER privilege:
GRANT MANAGE SCHEDULER TO xxx;
Wow, I found the problem... "myJob" was an existing package object in the database. I'm guessing my "insufficient privileges" were to replace the package object with a job object.
if you get the manage scheduler privilege, the next thing where this will fail is the none existing execute bits on the shell script. If the execute bits are in place, it will fail because it lacks the environment settings like PATH and ORACLE_HOME, needed to run SQL*Plus.
Besides that, why stick to 10g?
Oracle 11g has much better options to run external jobs, security implemented by credentials instead of some file in $ORACLE_HOME that defines the user to run the job.
There is some very nice reading available on this subject, see my profile.
I hope this helps,
Ronald.

Resources