Question

I am new to oracle, I have created two tables using 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 am 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 parenthesis

I have also tried with

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 getting same error. Can any one tell me that where I am doing mistake?

Was it helpful?

Solution

I'm no expert in oracle, but are you allowed to specify the (10) in salary int(10) NOT NULL?

OTHER TIPS

1: you should have a table called "test" with two columns, id and testdata. (This is just a dumb quick example, so I won't bother to specify any constraints on id.)

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

2: Next we'll create a sequence to use for the id numbers in our test table.

create sequence test_seq 
start with 1 
increment by 1 
nomaxvalue;

You could change "start with 1" to any number you want to begin with (e.g. if you already have 213 entries in a table and you want to begin using this for your 214th entry, replace with "start with 214"). The "increment by 1" clause is the default, so you could omit it. You could also replace it with "increment by n" if you want it to skip n-1 numbers between id numbers. The "nomaxvalue" tells it to keep incrementing forever as opposed to resetting at some point.i (I'm sure Oracle has some limitation on how big it can get, but I don't know what that limit is).

3: Now we're ready to create the trigger that will automatically insert 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;
/

There are two different ways to create a table with constraints:

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));  

When creating the index inline 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 details:

ORA-00907: missing right parenthesis

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top