ORA-00907: missing right bracket. Error creating table?

I'm new to oracle, I created two tables using the following queries:

CREATE TABLE employee ( emp_name VARCHAR(20) NOT NULL, street VARCHAR(50) NOT NULL, city VARCHAR(20) NOT NULL, PRIMARY KEY(emp_name) ) 

and

 CREATE TABLE company ( comp_name VARCHAR(20) NOT NULL, city VARCHAR(20) NOT NULL, PRIMARY KEY(comp_name) ) 

Now I'm trying to create another table using some foreign keys,

 CREATE TABLE works ( emp_name varchar(20) NOT NULL, comp_name varchar(20) NOT NULL, salary int(10) NOT NULL, FOREIGN KEY(emp_name) REFERENCES employee(emp_name), FOREIGN KEY(comp_name) REFERENCES company(comp_name) ) 

Getting ERROR: ORA-00907: Missing Right Parentheses

I also tried using

 CREATE TABLE works ( emp_name varchar(20) NOT NULL, comp_name varchar(20) NOT NULL, salary int(10) NOT NULL, constraint wemployee FOREIGN KEY(emp_name) REFERENCES employee(emp_name), constraint wcompany FOREIGN KEY(comp_name) REFERENCES company(comp_name) ) 

But the same mistake. Can someone tell me where I am going wrong?

+6
source share
5 answers

I am not an expert in oracle, but is it possible to specify (10) in salary int(10) NOT NULL ?

+4
source

1: you should have a table called "test" with two columns, id and testdata. (This is just a dumb quick example, so I will not point out any restrictions on the identifier.)

 create table test (id number, testdata varchar2(255)); 

2: Next, we will create the sequence used for identifier numbers in our test pattern.

 create sequence test_seq start with 1 increment by 1 nomaxvalue; 

You can change "start from 1" to whatever number you want to start from (for example, if you already have 213 entries in the table and you want to start using this for your 214th entry, replace it with "start with 214" ), The "increment by 1" clause is the default, so you can omit it. You can also replace it with "increment by n" if you want it to pass the numbers n-1 between id numbers. The Nomaxvalue reports that it continues to increase forever, as opposed to a reset at some point. I (I am sure that Oracle has some restriction on how much it can increase, but I do not know what this restriction is).

3: Now we are ready to create a trigger that automatically inserts the next number from the sequence into the id column.

 create trigger test_trigger before insert on test for each row beginselect test_seq.nextval into :new.id from dual; end; / 
+2
source

When creating an inline index with the rest of the table creation statement, try dropping the FOREIGN KEY part:

 CREATE TABLE works ( emp_name varchar(20) NOT NULL, comp_name varchar(20) NOT NULL, salary int(10) NOT NULL, emp_name REFERENCES employee(emp_name), comp_name REFERENCES company(comp_name) ) 

See this question for more information:

ORA-00907: missing right parentheses

+1
source

There are two different ways to create a constrained table:

1)

  create table department( deptno number(5) primary key, deptname varchar2(30), empno number(5) references emp(empno)); 

2)

  create table department( deptno number(5), deptname varchar2(30), empno number(5), constraint pkey_deptno primary key(deptno), constraint fkey_empno foreign key(empno) references Emp(empno)); 
+1
source

I like how no one thought or made silly long messages, but I don’t know shit, then this guy comes and says a super simple and nice answer. dumbasses

-1
source

Source: https://habr.com/ru/post/927156/


All Articles