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?
Best Answer
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 tonumber
andtext
tovarchar2
).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.The user should be
xauthority
but it is stillSYS
.You need
create session
system privilege to connect to the database.You need quota on tablespace to create schema objects such as table.