varbinary(max) error in SQL - sql

I want to use a column that contains images in it. I've tried this code
create table books
(
book_id number(4),
title varchar2 (50),
ISBN varchar2(20),
author varchar2(40),
publisher varchar2(20),
released number(4),
image varbinary(max),
constraint booksPK primary key (book_id),
constraint booksFK foreign key (subject_id) references subject(subject_id)
);
and I got this error:
Error at Command Line:29 Column:16
Error report:
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
please help me with this...

varbinary isn't an Oracle data type. You should be using a binary large object (BLOB). A comment suggested long raw, but BLOBs have fewer restrictions and should be used instead.

Related

ORA-00906:"missing left parenthesis" in sql developer

When I tried to create this table, this error appeared me and I don't know why
CREATE TABLE Empregado(
cod_empregado INTEGER,
cod_supervisor INTEGER,
cod_armazem INTEGER,
nome VARCHAR(40) NOT NULL,
morada VARCHAR(40) NOT NULL,
salario_semanal NUMERIC(*,2) NOT NULL,
formacao VARCHAR(40) NOT NULL,
CONSTRAINT pk_Empregado_cod_empregado PRIMARY KEY,
CONSTRAINT fk_Empregado_cod_supervisor FOREIGN KEY(cod_supervisor)
REFERENCES Empregado(cod_supervisor),
CONSTRAINT fk_Empregado_cod_armazem FOREIGN KEY(cod_armazem) REFERENCES
Armazem(cod_armazem)
);
And this is the output
Error report -
ORA-00906: missing left parenthesis
00906. 00000 - "missing left parenthesis"
*Cause:
*Action:
The issue that throws out the error you are seeing is caused by the PRIMARY KEY constraint: you didn't state WHICH column is the primary key. The PK column must be in parentheses; the opening parenthesis is missing (along with the rest), and that is the first syntax violation Oracle sees.
After you fix that, you will get another error, on the first foreign key, because you are referencing the wrong table (or if it should reference the same table you are creating, you are referencing the wrong COLUMN).

SQL error missing right parentheses

I am new to SQL and I am doing an assignment for class. I do not understand what is wrong with the statement below.
CREATE TABLE APP_DEGREE
(DEGREE_ID varchar (6) NOT NULL,
TITLE varchar (3O),
INSTITUTION varchar (30),
App_ID varchar (6) NOT NULL,
CONSTRAINT constr_degree_pk PRIMARY KEY (DEGREE_ID),
CONSTRAINT constr_degree_fk FOREIGN KEY (App_ID) REFERENCES APPLICANT (App_ID)
);
When I run the script I receive this error:
Error report -
ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Thank you for your help!
Typo: TITLE varchar (30) and not TITLE varchar(3O)
CREATE TABLE APP_DEGREE(
DEGREE_ID varchar(6) NOT NULL,
TITLE varchar(30),
INSTITUTION varchar(30),
App_ID varchar(6) NOT NULL,
CONSTRAINT constr_degree_pk PRIMARY KEY(DEGREE_ID),
CONSTRAINT constr_degree_fk FOREIGN KEY(App_ID) REFERENCES APPLICANT(App_ID)
);
Edit: The "O" instead "0". Use an IDE, you will see this kind of errors instantly. Also the "`" string delimiter to have not to deal with reserved sql keywords like "order" as field name.

SQL Error: ORA-00907: missing right parenthesis 00907. 00000 - "missing right parenthesis"

I don't know what is wrong with this syntax.
create table table3 (
id number,
id_table1 number,
id_table2 number,
area varchar2(130) not null,
status varchar2(20),
additional_info varchar2(100),
data date default sysdate,
responsable varchar2(60) not null,
constraint ck_status_contract check(status in('value1','value2','value3')),
constraint fk_id_table1 references table1 on delete set null,
constraint fk_id_table2 references table2 on delete set null,
constraint pk_id_contract primary key(id)
);
The result is:
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
I use OracleXE112_Win64.
On your FK you need to specify the columns affected on both ends
CONSTRAINT fk_column
FOREIGN KEY (column1, column2, ... column_n)
REFERENCES parent_table (column1,..)
You have missed to add foreign key references properly.
To specify foreign key constraint, you should either use inline
CONSTRAINT [constraint_name] FOREIGN KEY(customer_id) REFERENCES [master_table_name]([master_column_name])
See more example from this tutorial: What is foreign key?
Resource Link:
SQL Error: ORA-00907: missing right parenthesis

Multiple errors dropping and creating tables

I'm not good at writing create scripts. And the SQL Developer error messages don't help me. I'm looking for someone to help me figure out what's wrong because I can't do this alone.
Here is my code:
/*Drops */
DROP TABLE Accountsite CASCADE CONSTRAINTS;
DROP TABLE Player CASCADE CONSTRAINTS;
DROP TABLE Stream CASCADE CONSTRAINTS;
DROP TABLE Server CASCADE CONSTRAINTS;
DROP TABLE Activegame CASCADE CONSTRAINTS;
DROP TABLE Livegame CASCADE CONSTRAINTS;
DROP TABLE Toplist CASCADE CONSTRAINTS;
DROP TABLE Champion CASCADE CONSTRAINTS;
DROP TABLE Skin CASCADE CONSTRAINTS;
DROP TABLE Sale CASCADE CONSTRAINTS;
DROP TABLE PlayerServer CASCADE CONSTRAINTS;
DROP TABLE ActiveServer CASCADE CONSTRAINTS;
/*Creates */
CREATE TABLE Accountsite(
AccountID NUMBER PRIMARY KEY NOT NULL,
PasswordAcc VARCHAR(20) NULL,
Email VARCHAR(20) NULL,
Playername VARCHAR(20) NULL,
FOREIGN KEY(Playername) REFERENCES Player (Playername));
CREATE TABLE Player(
PlayerID NUMBER PRIMARY KEY,
Mostplayed VARCHAR(20) NOT NULL,
RankID NUMBER(10) NOT NULL,
Playername VARCHAR(20) NOT NULL);
CREATE TABLE Stream(
StreamID NUMBER PRIMARY KEY,
StreamAdress VARCHAR(20) NOT NULL,
Playername VARCHAR(20) NOT NULL,
FOREIGN KEY(Playername) REFERENCES Player (Playername));
CREATE TABLE Server(
ServerID NUMBER PRIMARY KEY,
Servername VARCHAR(20));
CREATE TABLE Activegame(
GameID NUMBER PRIMARY KEY);
CREATE TABLE Livegame(
SpectateID NUMBER PRIMARY KEY);
CREATE TABLE Toplist(
ToplistID NUMBER PRIMARY KEY,
ToplistFunction VARCHAR(20) NOT NULL,
Playername VARCHAR(20) NOT NULL,
Championname VARCHAR(20) NOT NULL,
FOREIGN KEY(Playername) REFERENCES Player (Playername),
FOREIGN KEY(Champion) REFERENCES Champion (Champion));
CREATE TABLE Champion(
ChampionID NUMBER PRIMARY KEY,
Championname VARCHAR(20) NOT NULL,
Championskill1 VARCHAR(20) NOT NULL,
Championskill2 VARCHAR(20) NOT NULL,
Championskill3 VARCHAR(20) NOT NULL,
Championskill4 VARCHAR(20) NOT NULL,
Championcost NUMBER(10) DEFAULT(6300),
SkinID NUMBER(10) NOT NULL,
SaleID NUMBER(10) NOT NULL,
FOREIGN KEY(SkinID) REFERENCES Skin (SkinID),
FOREIGN KEY(SaleID) REFERENCES Sale (SaleID));
CREATE TABLE Skin(
SkinID NUMBER PRIMARY KEY,
Skinname VARCHAR(20) NOT NULL,
Skincost NUMBER(10) NOT NULL);
CREATE TABLE Sale(
SaleID NUMBER PRIMARY KEY);
CREATE TABLE PlayerServer(
Playername VARCHAR(20) NOT NULL,
ServerIDPlayer NUMBER NOT NULL,
FOREIGN KEY(Playername) REFERENCES Player (Playername),
FOREIGN KEY(ServerIDPlayer) REFERENCES Server (ServerID),
Constraint PlayerserverID PRIMARY KEY (Playername, ServerIDPlayer));
CREATE TABLE ActiveServer(
GameIDServer NUMBER NOT NULL,
ServerIDGame NUMBER NOT NULL,
FOREIGN KEY(GameIDServer) REFERENCES Acrivegame (GameID),
FOREIGN KEY(ServerIDGame) REFERENCES Server (ServerID),
Constraint ActiveserverID PRIMARY KEY (GameIDServer, ServerIDGame));
commit;
And the errors are as follows:
Error starting at line : 2 in command -
DROP TABLE Accountsite CASCADE CONSTRAINTS
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Table PLAYER dropped.
Error starting at line : 4 in command -
DROP TABLE Stream CASCADE CONSTRAINTS
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Table SERVER dropped.
Table ACTIVEGAME dropped.
Table LIVEGAME dropped.
Error starting at line : 8 in command -
DROP TABLE Toplist CASCADE CONSTRAINTS
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Error starting at line : 9 in command -
DROP TABLE Champion CASCADE CONSTRAINTS
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Table SKIN dropped.
Table SALE dropped.
Error starting at line : 12 in command -
DROP TABLE PlayerServer CASCADE CONSTRAINTS
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Error starting at line : 13 in command -
DROP TABLE ActiveServer CASCADE CONSTRAINTS
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Error starting at line : 16 in command -
CREATE TABLE Accountsite(
AccountID NUMBER PRIMARY KEY NOT NULL,
PasswordAcc VARCHAR(20) NULL,
Email VARCHAR(20) NULL,
Playername VARCHAR(20) NULL,
FOREIGN KEY(Playername) REFERENCES Player (Playername))
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Table PLAYER created.
Error starting at line : 29 in command -
CREATE TABLE Stream(
StreamID NUMBER PRIMARY KEY,
StreamAdress VARCHAR(20) NOT NULL,
Playername VARCHAR(20) NOT NULL,
FOREIGN KEY(Playername) REFERENCES Player (Playername))
Error report -
SQL Error: ORA-02270: Geen overeenkomende unieke of primaire sleutel voor deze kolomlijst.
02270. 00000 - "no matching unique or primary key for this column-list"
*Cause: A REFERENCES clause in a CREATE/ALTER TABLE statement
gives a column-list for which there is no matching unique or primary
key constraint in the referenced table.
*Action: Find the correct column names using the ALL_CONS_COLUMNS
catalog view
Table SERVER created.
Table ACTIVEGAME created.
Table LIVEGAME created.
Error starting at line : 45 in command -
CREATE TABLE Toplist(
ToplistID NUMBER PRIMARY KEY,
ToplistFunction VARCHAR(20) NOT NULL,
Playername VARCHAR(20) NOT NULL,
Championname VARCHAR(20) NOT NULL,
FOREIGN KEY(Playername) REFERENCES Player (Playername),
FOREIGN KEY(Champion) REFERENCES Champion (Champion))
Error report -
SQL Error: ORA-00904: "CHAMPION": ongeldige ID
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error starting at line : 53 in command -
CREATE TABLE Champion(
ChampionID NUMBER PRIMARY KEY,
Championname VARCHAR(20) NOT NULL,
Championskill1 VARCHAR(20) NOT NULL,
Championskill2 VARCHAR(20) NOT NULL,
Championskill3 VARCHAR(20) NOT NULL,
Championskill4 VARCHAR(20) NOT NULL,
Championcost NUMBER(10) DEFAULT(6300),
SkinID NUMBER(10) NOT NULL,
SaleID NUMBER(10) NOT NULL,
FOREIGN KEY(SkinID) REFERENCES Skin (SkinID),
FOREIGN KEY(SaleID) REFERENCES Sale (SaleID))
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Table SKIN created.
Table SALE created.
Error starting at line : 74 in command -
CREATE TABLE PlayerServer(
Playername VARCHAR(20) NOT NULL,
ServerIDPlayer NUMBER NOT NULL,
FOREIGN KEY(Playername) REFERENCES Player (Playername),
FOREIGN KEY(ServerIDPlayer) REFERENCES Server (ServerID),
Constraint PlayerserverID PRIMARY KEY (Playername, ServerIDPlayer))
Error report -
SQL Error: ORA-02270: Geen overeenkomende unieke of primaire sleutel voor deze kolomlijst.
02270. 00000 - "no matching unique or primary key for this column-list"
*Cause: A REFERENCES clause in a CREATE/ALTER TABLE statement
gives a column-list for which there is no matching unique or primary
key constraint in the referenced table.
*Action: Find the correct column names using the ALL_CONS_COLUMNS
catalog view
Error starting at line : 81 in command -
CREATE TABLE ActiveServer(
GameIDServer NUMBER NOT NULL,
ServerIDGame NUMBER NOT NULL,
FOREIGN KEY(GameIDServer) REFERENCES Acrivegame (GameID),
FOREIGN KEY(ServerIDGame) REFERENCES Server (ServerID),
Constraint ActiveserverID PRIMARY KEY (GameIDServer, ServerIDGame))
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Commit complete.
What am I doing wrong?
There are several issues with your script. Basically when you include foreign key constraints, they have to be pointing to a unique column which is in a table that already exists (has to be created before the referencing table).
Errors on trying to drop a table
You basically get an ORA-00942 because your table does not exist, thus it cannot be dropped. As a workaround you could catch that exception. It has been described in this answer.
Errors on trying to create a table
You have several issues in this topic. First one is when you execute the create statement of table Accountsite. You also get an ORA-00942 here, because table Player which you are trying to reference in foreign key constraint does not exist. You need to create it before Accountsite, so that it can reference something that exists.
Next error occurs while creating a table Stream. It's the ORA-02270. You cannot reference a column from another table which is not unique. You need to make Playername column unique in table Player. Note that when you fix the first error with Accountsite table, you would have the same error for this table as for Stream, since you are trying to reference a column which is not unique in both create table statements (so you also need to fix the second error and it will go without errors).
Now the Toplist table. There is no Champion column in your Champion table. You probably mean Championname. In this case also Champion table needs to be created before the Toplist table, since you cannot create a foreign key constraint to a non-existing table. You also need to declare your Championname column in Champion table unique (the very same like you do with Playername in table Player).
In Champion you reference a Sale and Skin table - they both need to be created before Champion table (see explanation above).
As for PlayerServer the error will solve itself when you create a unique constraint on Player(Playername).
In ActiveServer you have a typo in referencing "Acrivegame" which I believe should be Activegame.

Oracle create table with foreign key error - Invalid Identifier

I'm getting an error saying invalid identifier when I try to add this table. Its been bugging me for too long now so I thought I'd ask.
CREATE TABLE HORSE
(
horse_id numeric PRIMARY KEY,
horse_name character(30) not null,
horse_gender character(1) not null,
horse_height decimal not null,
horse_image character(40),
CONSTRAINT horse_breed FOREIGN KEY (breed_id) REFERENCES breed(breed_id)
);
The error message is;
Error at Command Line:34 Column:37
Error report:
SQL Error: ORA-00904: "BREED_ID": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Thanks and sorry for asking what is probably a really dumb question.
You need breed_id in HORSE table
CREATE TABLE HORSE
(
horse_id numeric PRIMARY KEY,
horse_name character(30) not null,
horse_gender character(1) not null,
horse_height decimal not null,
horse_image character(40),
breed_id numeric null
CONSTRAINT horse_breed FOREIGN KEY (breed_id) REFERENCES breed(breed_id)
);