I'm trying to create a table, but I keep getting this error:
ORA-00904: : invalid identifier
Please help.
CREATE TABLE salesreport
(
pid number(10) NOT NULL,
uid number(10) NOT NULL,
pname varchar2(50) NOT NULL,
price number(10) NOT NULL,
qty number(10) NOT NULL,
dateoforder varchar2(20) DEFAULT NULL,
total varchar2(30) NOT NULL
)
CREATE INDEX pid ON salesreport (pid, uid);
uid is a reserved word. Pick something else and it should work.
OR write it like this
CREATE TABLE salesreport (
pid number(10) NOT NULL,
"uid" number(10) NOT NULL,
pname varchar2(50) NOT NULL,
price number(10) NOT NULL,
qty number(10) NOT NULL,
dateoforder date DEFAULT SYSDATE,
total varchar2(30) NOT NULL
);
INDEX pid ON salesreport (pid,"uid");
Related
CREATE TABLE CUSTOMER1
(
CUSTOMERID VARCHAR2(2) NOT NULL,
FIRSTNAME VARCHAR2(50) NOT NULL,
LASTNAME VARCHAR2(50) NOT NULL,
PHONENUMBER VARCHAR2(50) NOT NULL,
BIRTHDATE DATE NOT NULL,
DRIVERLICENSENUMBER NUMBER,
STATUS VARCHAR2(50),
CREDITCARENUMBER NUMBER,
CONSTRAINT CustomerID_PK PRIMARY KEY(CUSTOMERID)
);
CREATE TABLE CCATEGORY
(
CATEGORYID INT NOT NULL,
CATEGORYNAME VARCHAR2(50) NOT NULL,
CONSTRAINT categoryID_pk PRIMARY KEY (CATEGORYID)
);
CREATE TABLE TAPE
(
TAPEID NUMBER(5) NOT NULL,
TAPETITLE VARCHAR2(200) NOT NULL,
RELEASEYEAR NUMBER(5) NOT NULL,
DATEPURCHASED DATE NOT NULL,
PRICE NUMERIC(5) NOT NULL,
RENTEDOUT VARCHAR2(20) NOT NULL,
RATING VARCHAR2(10) NOT NULL,
ACTIONONRETURN VARCHAR2(50) NOT NULL,
PRIMARY KEY(TAPEID),
CONSTRAINT FK_CATEGORYID FOREIGN KEY(CATEGORYID) REFERENCES CCATEGORY(CATEGORYID),
CONSTRAINT FK_RESERVEDBY FOREIGN KEY(CUSTOMERID) REFERENCES CUSTOMER(CUSTOMERID)
);
Customer, and CCategory table are created. When I try to create TAPE table I get the following error: SQL Error: ORA-00904: "CATEGORYID": invalid identifier. Can't seem to figure out why. I created the customer table first, then the category table before trying to create the TAPE table.
Problem is that you have not defined CATEGORYID and CUSTOMERID in TAPE table. Add it and it would work.
Complete statement would be
CREATE TABLE TAPE
(
TAPEID NUMBER(5) NOT NULL,
TAPETITLE VARCHAR2(200) NOT NULL,
RELEASEYEAR NUMBER(5) NOT NULL,
DATEPURCHASED DATE NOT NULL,
PRICE NUMERIC(5) NOT NULL,
RENTEDOUT VARCHAR2(20) NOT NULL,
RATING VARCHAR2(10) NOT NULL,
ACTIONONRETURN VARCHAR2(50) NOT NULL,
CATEGORYID INT NOT NULL,
CUSTOMERID VARCHAR2(2) NOT NULL,
CONSTRAINT tape_primary_key PRIMARY KEY(TAPEID),
CONSTRAINT FK_CATEGORYID FOREIGN KEY(CATEGORYID) REFERENCES CCATEGORY(CATEGORYID),
CONSTRAINT FK_RESERVEDBY FOREIGN KEY(CUSTOMERID) REFERENCES CUSTOMER1(CUSTOMERID)
);
Having started at the same statements over and over again, I still cannot find the missing right parenthesis. It's appeared when running both of these statements and in order to run the rest of my tables I need to be able to locate the right parenthesis.
I've selected the parenthesis used in the statements and all seemed to match up to the right ones. Can anyone suggest anything?
CREATE TABLE booking (
bookingNo NUMBER(8) PRIMARY KEY,
customerNo NUMBER(8) NOT NULL
REFERENCES customer(customerNo),
registrationNo VARCHAR2(10) NOT NULL
REFERENCES vehicle(registrationNo),
dateOfBooking DATE NOT NULL
DEFAULT SYSDATE,
pickupStreetAddressLine VARCHAR2(30) NOT NULL,
pickupTown VARCHAR2(30) NOT NULL,
pickupPostcode VARCHAR2(10) NOT NULL,
startTime NUMBER(4,2) NOT NULL,
startDate DATE NOT NULL
DEFAULT SYSDATE,
endTime NUMBER(4,2) NOT NULL,
endDate DATE NOT NULL
DEFAULTSYSDATE,
noOfPassengers NUMBER(3) NOT NULL
CONSTRAINT CHECK(noOfPassengers > 0 AND noOfPassengers <= 73)
price NUMBER(8,2) NOT NULL
);
CREATE TABLE employees (
nationalInsuranceNo VARCHAR2(10) PRIMARY KEY,
fullName VARCHAR2(50) NOT NULL,
streetAddress VARCHAR2(30) NOT NULL,
town VARCHAR2(30),
postcode VARCHAR2(10) NOT NULL,
homeNo NUMBER(11)
dateOfBirth DATE NOT NULL,
gender VARCHAR2(8) NOT NULL
CONSTRAINT CHECK(gender="Male" OR gender="Female"),
jobDescription VARCHAR2(30) NOT NULL,
currentSalary NUMBER(6) NOT NULL
CONSTRAINT CHECK(currentSalary>0)
);
Try using a standard indentation scheme to visually verify your formatting.
Here I moved each significant paren to a newline and indented each piece separately.
I put comments next to a few items that seem wrong:
CREATE TABLE
booking
(
bookingNo NUMBER(8) PRIMARY KEY,
customerNo NUMBER(8) NOT NULL
REFERENCES customer(customerNo),
registrationNo VARCHAR2(10) NOT NULL
REFERENCES vehicle(registrationNo),
dateOfBooking DATE NOT NULL
DEFAULT SYSDATE,
pickupStreetAddressLine VARCHAR2(30) NOT NULL,
pickupTown VARCHAR2(30) NOT NULL,
pickupPostcode VARCHAR2(10) NOT NULL,
startTime NUMBER(4,2) NOT NULL,
startDate DATE NOT NULL
DEFAULT SYSDATE,
endTime NUMBER(4,2) NOT NULL,
endDate DATE NOT NULL
DEFAULT SYSDATE, -- THERE WAS A MISSING SPACE HERE *********************
noOfPassengers NUMBER(3) NOT NULL, -- MISSING COMMA ********
CONSTRAINT Check_noOfPassengers CHECK -- ADD A CONSTRAINT NAME *********
(
noOfPassengers > 0
AND noOfPassengers <= 73
), -- THERE WAS A MISSING COMMA HERE *******************
price NUMBER(8,2) NOT NULL
);
CREATE TABLE
employees
(
nationalInsuranceNo VARCHAR2(10) PRIMARY KEY,
fullName VARCHAR2(50) NOT NULL,
streetAddress VARCHAR2(30) NOT NULL,
town VARCHAR2(30),
postcode VARCHAR2(10) NOT NULL,
homeNo NUMBER(11), -- THERE WAS A MISSING COMMA HERE ***************
dateOfBirth DATE NOT NULL,
gender VARCHAR2(8) NOT NULL, -- MISSING COMMA *****
CONSTRAINT Check_gender CHECK -- ADD A CONSTRAINT NAME *********
(
gender="Male"
OR gender="Female"
),
jobDescription VARCHAR2(30) NOT NULL,
currentSalary NUMBER(6) NOT NULL, -- MISSING COMMA
CONSTRAINT Check_currentSalary CHECK -- ADD A CONSTRAINT NAME *********
(
currentSalary>0
)
);
I don't have Oracle installed to test, but is there a missing comma for the column noOfPassengers above? More generally, it may not be a missing right parens, but a parens that is out of place because of another syntax error. Hope that helps.
Change this DEFAULTSYSDATE to this DEFAULT SYSDATE on the 17th line
Also, add the column name before each CHECK and after the CONSTRAINT words. And add a comma after the first CONSTRAINT statement.
Hope it helps :)
I am trying to create two tables, which is throwing ORA-00902 error, can't figure out what's wrong here...
CREATE TABLE VEHICLE_STORE
(
MODEL_NO VARCHAR2(12) NOT NULL,
DESCRIPTION VARCHAR2(1000) NOT NULL,
UNIT_PRICE NUMBER(10) NOT NULL,
CURRENT_STOCK NUMBER(5) NOT NULL,
CC NUMBER(3) NOT NULL,
CONSTRAINT vehicle_store_pk PRIMARY KEY(MODEL_NO)
);
CREATE TABLE VEHICLE_BOOKING
(
BOOKING_ID VARCHAR2(12) NOT NULL,
CUSTOMER_NAME VARCHAR2(30) NOT NULL,
EMAIL_ID VARCHAR2(30) NOT NULL,
CONTACT NUMBER(15) NOT NULL,
ADDRESS VARCHAR2(500) NOT NULL,
PINCODE NUMBER(10) NOT NULL,
MODEL_NO VARCHAR2(12) NOT NULL,
DATE_OF_BOOKING VARCHAR2(12) NOT NULL,
EXPECTED_DATE_OF_DELIVERY VARCHAR2(12) NOT NULL,
CONSTRAINT vehicle_booking_pk PRIMARY KEY(BOOKING_ID),
CONSTRAINT vehicle_booking_fk FOREIGN_KEY(MODEL_NO) REFERENCES VEHICLE_STORE(MODEL_NO)
);
Thanks in advance...
Change FOREIGN_KEY(MODEL_NO) to FOREIGN KEY (MODEL_NO) (no underscore).
I want to create Interim table from main table for DBMS_Redefinition Process.
but the requirement is not to write entire create syntax because there are n number of tables and i cant take each value every time.
INTERIM TABLE = table_INTER
MAIN_TABLE = table_MAIN
for eg..
CREATE TABLE table_INTER (
ContactPartKey NUMBER(20) NOT NULL,
PartyKey NUMBER(10) NOT NULL,
ConParticipationRoleKey NUMBER(10) NOT NULL,
ChannelKey NUMBER(10) NOT NULL,
StateKey NUMBER(10) NOT NULL,
StateReasonKey NUMBER(10) NOT NULL,
NextStateKey NUMBER(10) NOT NULL,
PreviousStateKey NUMBER(10) NOT NULL,
QueueKey NUMBER(10) NOT NULL,
RtgPointKey NUMBER(10) NOT NULL,
ContactPartIndKey NUMBER(10) NOT NULL,
DeviceKey NUMBER(10) NOT NULL,
ContactID NUMBER(20) NOT NULL,
Parent1ContactID NUMBER(20) ,
StartDateKey NUMBER(10) NOT NULL,
EndDateKey NUMBER(10) NOT NULL,
StartTimeKey NUMBER(3) NOT NULL,
EndTimeKey NUMBER(3) NOT NULL,
StartDateTime DATE NOT NULL,
EndDateTime DATE NOT NULL,
StateDur NUMBER(10) NOT NULL,
ContactAllocatedCost decimal(14,4) ,
ContactPartSeqNum NUMBER(10) NOT NULL,
ContactInProcessInd NUMBER(3) NOT NULL,
FinalPartInd NUMBER(3) NOT NULL,
Counter NUMBER(10) NOT NULL,
SourceKey NUMBER(10) NOT NULL,
StreamKey NUMBER(10) NOT NULL,
ProcessKey NUMBER(10) ,
SelfServiceInd NUMBER(3) )
--PRIMARY KEY(ContactPartKey)
TABLESPACE AVAYAIQFACT1
STORAGE (INITIAL 2097152 NEXT 2097152)
PCTFREE 0
PARTITION BY RANGE (STARTDATETIME)
INTERVAL(NUMTOYMINTERVAL(1, 'MONTH'))
(PARTITION P1 VALUES LESS THAN (TO_DATE('01/09/2013', 'DD/MM/YYYY')) TABLESPACE T1,
PARTITION P2 VALUES LESS THAN (TO_DATE('01/10/2013', 'DD/MM/YYYY')) TABLESPACE T1);
In above syntax, column name value cant be given every time. So what i did was
create table table_INTER as (select * from table_MAIN);
But can anyone tell me how to introduce partition in this interim table (table_INTER).
Can you try this?
CREATE TABLE TABLE_INTER
PARTITION BY RANGE (STARTDATETIME)
INTERVAL ( NUMTOYMINTERVAL ( 1,
'MONTH' ) )
( PARTITION P1
VALUES LESS THAN
(TO_DATE ( '01/09/2013',
'DD/MM/YYYY' ))
TABLESPACE T1,
PARTITION P2
VALUES LESS THAN
(TO_DATE ( '01/10/2013',
'DD/MM/YYYY' ))
TABLESPACE T1 )
AS
( SELECT * FROM TABLE_MAIN );
I try to build this table
CREATE TABLE OFFICER
(
ID int(8) PRIMARY KEY,
FIRST_NAME varchar2(20) NOT NULL,
LAST_NAME varchar2(20) NOT NULL,
HIRE_DATE date NOT NULL,
UNHIRE_DATE date,
SALARY int(7),
PHONE_NUMBER int(10),
TYPE varchar2(15) NOT NULL
);
Do I have to use any constraint, reference? and What I lack for this code?
INT data type doesn't allow scale specification. Try either ID int primary key or Id NUMBER(8) primary key.
Try this,
CREATE TABLE OFFICER
(
ID NUMBER(8) PRIMARY KEY,
FIRST_NAME varchar2(20) NOT NULL,
LAST_NAME varchar2(20) NOT NULL,
HIRE_DATE date NOT NULL,
UNHIRE_DATE date,
SALARY NUMBER(7),
PHONE_NUMBER NUMBER(10),
TYPE varchar2(15) NOT NULL
);