Oracle pushing me ORA-00902: invalid datatype - oracle

create table accountDetails(
accountNumber int unique,
customerId int unique,
balance int not null,
password varchar(255) not null,
type varchar(255) not null check(type in ('Savings','Current')),
primary key(accountNumber,customerId) )
create table statusDetails(
customerId int references accountDetails(customerId),
primarykey(customerId))
The last table resulted in an error

The last table resulted in an error
ORA-00902: invalid datatype error happens when we try to define a column using an invalid datatype. It's logical really.
Now, you think you haven't declared a column with an invalid datatype, because you think statusdetails table has only one column, customerid. But if you look at your actual statement you follow that column with this:
primarykey(customerId))
Because you mis-typed primary key Oracle treats that line as an attempt to create a second column. Hence the error, because (customerId) is an invalid datatype. So all you need do is pop in the missing space and Oracle will create the table for you.
create table statusDetails(
customerId int references accountDetails(customerId),
primary key(customerId))
You had a compilation error caused by a simple typo. A key skill for a developer is the ability to turn a cool eye on our own code. I urge you to work on acquiring that skill as soon as you can.

Your second table declaration is all wrong. Try this:
CREATE TABLE statusdetails (
customerid INT,
CONSTRAINT fk_cust FOREIGN KEY ( customerid )
REFERENCES accountdetails ( customerid )
)
Note: using "int" data type maps to a NUMBER(38), which may not be what you want. Use the proper oracle data type names.

Related

Error creating a Oracle NoSQL table with ENUM fields

I have the following error when trying to create this table :
IllegalArgumentException: Error: at (1, 88) Missing closing ')', at line 1:88
Create table TEST (
id String,
fileType ENUM (DOCUMENT,VIDEO),
status ENUM (IN_PROGRESS,PARTIAL_SUCCESS,SUCCEEDED,FAILED,NULL),
primary key (id)
)
I've spent a little time to understand what I was doing wrong, the error message is not clear.
Literal "null" is a reserved word in the query language so it is not supported in that location.
status ENUM (IN_PROGRESS,PARTIAL_SUCCESS,SUCCEEDED,FAILED,NULL),
By the way, We can insert data with null values for the ENUM fields.So, I just create the same table but without including the value NULL
Create table TEST (
id String,
fileType ENUM (DOCUMENT,VIDEO),
status ENUM (IN_PROGRESS,PARTIAL_SUCCESS,SUCCEEDED,FAILED),
primary key (id)
)

Insert records into collection type Oracle

I want to inserted into my collection some SQL records, but I can not. I'm a beginner. Can you help me ?
This is my tables :
CREATE TYPE article_type AS OBJECT (idA CHAR(10), nomA CHAR(10), prixA CHAR(10) )
CREATE TYPE facture_type AS OBJECT (idF CHAR(10), dateFact DATE)
CREATE TYPE ens_collection_fact AS OBJECT (refFact facture_type, refArticle article_type)
CREATE TYPE collection_fact AS TABLE OF ens_collection_fact
CREATE TYPE client_type AS OBJECT (idC NUMBER, nomC CHAR(10),adresse CHAR(10), Compose collection_fact )
CREATE TABLE Article OF article_type
CREATE TABLE Facture OF facture_type
CREATE TABLE Client OF client_type (PRIMARY KEY(idC)) NESTED TABLE Compose STORE AS temp
This is my query that I want to insert, but I have an error from the Oracle : ORA-02315
INSERT INTO ECOLER.CLIENT VALUES
(100, 'Jules Verne', '1', Collection_fact(Ens_collection_fact(reffact('A','2002-12-10'), ens_collection_fact(refarticle('D','E','F'))) ))
Thank in advance
reffact and refarticle are identifiers for objects within other objects, not types; you need to refer to the actual types. You also need to supply both values for each Ens_collection_fact attribute for the default constructor; you can pass null if you only want one or the other:
INSERT INTO CLIENT VALUES
(100, 'Jules Verne', '1',
Collection_fact(
Ens_collection_fact(facture_type('A',date '2002-12-10'), null),
Ens_collection_fact(null, article_type('D','E','F'))
)
)
Also notice that I've added the date keyword so it's providing an actual date literal rather than a string, which would be converted - if you're lucky - with your session NLS settings.
This will still error because 'Jules Verne' is 11 characters and you've defined the name attribute as 10 characters/bytes, but it will work with a shorter string literal.
db<>fiddle

How do I create a H2 database with the date data type

I am trying to create a database in H2 (version 1.4.199), I need to include the date data type which is causing me issues when creating the database. I get a 50004 unknown data type error.
Can anyone advise where I am going wrong?
CREATE TABLE IF NOT EXISTS chapter (
CHAPTER_ID long,
STUDENT_ID long,
DATE - FORMAT yyyy-mm-dd,
UNIQUE (DATE),
PRIMARY KEY (CHAPTER_ID)
);
Your table definition is not valid, it should be
CREATE TABLE IF NOT EXISTS chapter (
CHAPTER_ID BIGINT,
STUDENT_ID BIGINT,
DATE DATE,
UNIQUE (DATE),
PRIMARY KEY (CHAPTER_ID)
);
or something like it.

ORA-00909 error when Insert object in object table

I am getting an error ORA-00909 in when inserting an object of a superType in an object table. These are the definitions for the objects:
CREATE OR REPLACE TYPE address AS OBJECT (
street VARCHAR(20),
country VARCHAR(20),
province VARCHAR(20),
city VARCHAR2(20),
zipcode VARCHAR(10)
) FINAL;
CREATE OR REPLACE TYPE company AS OBJECT (
CIF VARCHAR2(9),
code VARCHAR2(10),
name VARCHAR2(20),
signUpDate DATE,
email VARCHAR2(20),
adminAddress address
) NOT FINAL;
CREATE OR REPLACE TYPE inCourseCompany UNDER company (
postalAddress address,
numEmployees NUMBER
) FINAL;
And the object table:
CREATE TABLE companies_objtab OF company (PRIMARY KEY CIF) OBJECT IDENTIFIER IS PRIMARY KEY;
I try to insert an object with the following statement:
INSERT INTO companies_objtab VALUES (
company('J12345678','000001','Test Company',TO_DATE(sysdate, 'dd/mm/yyyy hh24:mi:ss'),'',address('','','','',''))
);
and I get error Error
SQL: ORA-00909: invalid number of arguments
00909. 00000 - "invalid number of arguments"
However, when I insert an object of the subtype inCourseCompany it is inserted correctly:
INSERT INTO companies_objtab VALUES (
inCourseCompany('G11111111','','',TO_DATE(sysdate, 'dd/mm/yyyy hh24:mi:ss'),'',address('','','','',''), address('','','','',''), 100)
);
Any hint about what causes the error?
I am using Oracle SQL Developer 4.0.2.15.21 and Oracle Database Express Edition 11g Release 2.
Thank you in advance.
i tried all your statements right as you posted them (copy-paste). Both on 12c and 11gR2. Everything worked, both inserts. The only thing I noticed is that your create table is a bit incorrect. This is the correct one (but this does not explain the error you get). HTH KR
CREATE TABLE companies_objtab OF company (CIF PRIMARY KEY) OBJECT IDENTIFIER IS PRIMARY KEY;
Maybe try dropping the table and creating it again.

mysql 1064 error on execution

I´ve got this table:
mysql> CREATE TABLE favorite food
-> (person_id SMALLINT UNSIGNED,
->food VARCHAR(20),
->CONSTRAINT pk_favorite_food PRIMARY KEY (person_id, food),
->CONSTRAINT fk_fav_food_person_id FOREIGN KEY (person_id)
->REFERENCES person (person_id)
->);
After execution i get the error 1064. Anybod any ideas what could be wrong?
MySQL Server 6.0
Table name should not have a whitespace in it. Make it something like favorite_food
By searching some possible response on Google, I found this thread on SO... The original table (which is the same as your, but with a nicer formatting) is:
CREATE TABLE favorite_food(
person_id SMALLINT UNSIGNED,
food VARCHAR(20),
CONSTRAINT pk_favorite_food PRIMARY KEY(person_id,food),
CONSTRAINT fk_fav_food_person_id FOREIGN KEY (person_id) REFERENCES person(person_id)
);
You probably don't have the person table, so the foreign key can't be created. (see the last line)
You have remove the _ in the table name (favorite food instead of favorite_food) which is not allowed.

Resources