This is driving me insane, can anyone help me understand why the following statements all return the following error?
create table JMS_PENDING_MESSAGE (id number primary key, queuex nvarchar2(200), messagex nclob(1000));
create table JMS_PENDING_MESSAGE (id number primary key, queuex nvarchar2(200), messagex nclob(10000));
create table JMS_PENDING_MESSAGE (id integer primary key, queuex nvarchar2(200), messagex nclob(10000));
And the error message:
ORA-00907: missing right parenthesis
Im running over JDBC using ojdbc5.jar if it makes a difference! Any help much appreciated, Im going insane
A CLOB is a CLOB (and, as o.k.w. points out, a NCLOB is an NCLOB). You don't need to give it a size:
create table JMS_PENDING_MESSAGE
(id integer primary key, queuex nvarchar2(200), messagex nclob);
Related
I have a PostgreSQL database hosted on Heroku which is throwing me this error that I can't wrap my head around.
CREATE TABLE people (id INTEGER PRIMARY KEY AUTOINCREMENT, age SMALLINT, right_handed BOOLEAN)
SELECT 1 id FROM people WHERE age IN (1) AND right_handed IN (1)
It gives me the error:
Error in query: ERROR: syntax error at or near "IN"
Don't know how to proceed, any help would be greatly appreciated.
AUTOINCREMENT is not a valid option for CREATE TABLE in Postgres
You can use SERIAL or BIGSERIAL:
ALTER TABLE myTable ADD COLUMN myColumn BIGSERIAL PRIMARY KEY;
I'm new to learning SQL. When I create this table, it has an Asterix (*) under the first parenthesis of the "(dbClassID)" and says "missing right parenthesis"
Does anyone know why it does that and how I can fix it?
CREATE TABLE vod_classification (
dbClassId CHAR(4) NOT NULL,
dbDescription VARCHAR2(100)
CONSTRAINT vod_classification_PK PRIMARY KEY (dbClassId)
);
CONSTRAINT is part of table creation and need to be comma delimited as other column:
CREATE TABLE zz_classification (
dbClassId CHAR(4) NOT NULL,
dbDescription VARCHAR2(100),
CONSTRAINT vod_classification_PK PRIMARY KEY( dbClassId)
);
Tables contain columns and constraints
you are missing , here try this VARCHAR2(100),
For a single-column constraint, it's neater to define it inline as part of the column:
create table vod_classification
( dbclassid varchar2(4) not null constraint vod_classification_pk primary key
, dbdescription varchar2(100) not null constraint vod_classification_uk unique
);
I have corrected the CHAR column to the standard string type which is VARCHAR2 in Oracle.
(PK columns will be not null automatically, but I've left it in for completeness and in case you later create table as select.)
When using the "Create" code, you must use a comma in the line where you define each column of the table. Except the last column. You can read the oracle sql syntax link as follows: https://docs.oracle.com/cd/E11882_01/server.112/e41085/sqlqr01001.htm#SQLQR110
I have this code, and cannot work out why I am getting issues. Can anyone help? It executes the generate sequence command, but not the create tables one, so I therefore cannot see it on the object browser.
If this helps:
QuizID is to be generated by a sequence.
QuizTitle, is at most 15 characters, and is not null.
Category is to default to Music with Sports and Geography as the only other available options.
SQL code:
CREATE TABLE Quiz_NLB_2
(
QuizID NUMBER,
QuizTitle VARCHAR2(15) NOT NULL,
Category VARCHAR2(9) DEFAULT 'Music',
CONSTRAINT pk_QuizID PRIMARY KEY (QuizID),
CONSTRAINT chk_Category CHECK (Category='Music', 'Sports', 'Geography')
);
CREATE SEQUENCE QuizID_Sequence_Gen START WITH 100;
The check constraint should look like this:
CONSTRAINT chk_Category
CHECK (Category IN ('Music', 'Sports', 'Geography'))
I am trying to create table having different indexes with single query but H2 gives Error for example:
create table tbl_Cust
(
id int primary key auto_increment not null,
fid int,
c_name varchar(50),
INDEX (fid)
);
but this gives error as
Unknown data type: "("; SQL statement:
[Error Code: 50004]
[SQL State: HY004]
Due to this I have to run 2 different queries to create table with Index. First query to create table and then second query to add index with
create INDEX c_fid on tbl_Cust(fid);
Is there something wrong in my query or H2 simply does not support this creation of table with index in single query?
Interesting question. The solution is even more interesting, as it involves MySQL compatibility mode.
It's actually possible to perform the exact same command you wrote without any modification, provided you just add to your jdbc url the MySQL mode.
Example URL like this: jdbc:h2:mem:;mode=mysql
SQL remains:
create table tbl_Cust
(
id int primary key auto_increment not null,
fid int,
c_name varchar(50),
INDEX (fid)
);
Update count: 0
(15 ms)
Too bad I did not see this question earlier... Hopefully the solution might become handy one day to someone :-)
I could resolve the problem. According to
http://www.h2database.com/html/grammar.html#create_index
I modified the query. It works fine with my H2 server.
CREATE TABLE subscription_validator (
application_id int(11) NOT NULL,
api_id int(11) NOT NULL,
validator_id int(11) NOT NULL,
PRIMARY KEY (application_id,api_id),
CONSTRAINT subscription_validator_ibfk_1 FOREIGN KEY (validator_id) REFERENCES validator (id) ON UPDATE CASCADE
);
CREATE INDEX validator_id ON subscription_validator(validator_id);
CREATE TABLE dbo.PhotoLibrary (
PhotoLibraryID INT IDENTITY (1, 1) PRIMARY KEY,
ImageName VARCHAR(100),
Photo VARBINARY(MAX)
)
While using the above code in SQL I am getting the error help me
You are passing in SQL Server code to Oracle. Big problem.
CREATE TABLE PhotoLibrary (
PhotoLibraryID INT PRIMARY KEY,
ImageName VARCHAR2(100),
Photo VARBINARY(MAX)
);
Oracle doesn't understand identity. If you want an auto-incrementing column, then you need to use a sequence. Here is an example.