3

I have a new fresh instance of Oracle Express 11g. I'm trying to create a new Schema with a Table and a View in the default db (xe).

My script is:

create user XAuthority identified by mysecret;

alter session set current_schema = XAuthority;

create schema authorization XAuthority
create table CUSTOMER (  ID int, CUSTOMER text)
create view CUSTOMER_VIEW as select * from CUSTOMER
grant select on CUSTOMER_VIEW to xareadonly;

but I get an error:

SQL Error: ORA-02421: missing or invalid schema authorization identifier 02421. 00000 - "missing or invalid schema authorization identifier"

*Cause: the schema name is missing or is incorrect in an authorization clause of a create schema statement.

*Action: If the name is present, it must be the same as the current schema.

I'm familiar with Postgres and MySql but it seems Oracle is quite different. Can anyone tell me what's wrong here?

1 Answer 1

2

CREATE SCHEMA

Purpose

Use the CREATE SCHEMA statement to create multiple tables and views and perform multiple grants in your own schema in a single transaction.

Well you have multiple issues. First of all you need to have CREATE SESSION system privilege granted to the newly created user. Secondly your data types are incompatible in Oracle(int should be converted to number and text to varchar2).

In order to use CREATE SCHEMA statement you need to be connected to database as the user which you have specified on the statement.

The problem is you are not connected to database as xauthority by altering the session.

SQL> conn sys/password
Connected.

SQL> create user XAuthority identified by mysecret;

User created.

SQL> alter session set current_schema = XAuthority;

Session altered.

SQL> create schema authorization XAuthority
create table CUSTOMER(ID number, CUSTOMER_name varchar2(20))
create view CUSTOMER_VIEW as select * from CUSTOMER
grant select on CUSTOMER_VIEW to xareadonly;  2    3    4  
create schema authorization XAuthority
*
ERROR at line 1:
ORA-02421: missing or invalid schema authorization identifier

SQL> show user
USER is "SYS"

The user should be xauthority but it is still SYS.

You need create session system privilege to connect to the database.

SQL> grant create session to xauthority;

Grant succeeded.

You need quota on tablespace to create schema objects such as table.

SQL> alter user xauthority quota unlimited on orapdb1_tbs1;

User altered.

SQL> conn xauthority/mysecret
Connected.

SQL> conn xauthority/mysecret
Connected.
SQL> create schema authorization XAuthority
create table CUSTOMER(ID number, CUSTOMER_name varchar2(20))
create view CUSTOMER_VIEW as select * from CUSTOMER;

Schema created.
2
  • thanks you, but just one thing. What is orapdb1_tbs1, or what should it be in my case?
    – Black
    Commented Jan 10, 2017 at 10:07
  • @Francis: I that is my tablespace name on which I have assigned the quota to the newly created user. In your case it might be different like USERS or other.
    – atokpas
    Commented Jan 10, 2017 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.