ORA-00907: missing right parenthesis when creating tables - oracle11g

I am trying to create 3 tables but I am getting this error:
CREATE TABLE dj_abonent
(
dj_klientID INT NOT NULL PRIMARY KEY,
emer_klienti varchar2(10),
mbiemer_klienti VARCHAR2(10),
sasia_cel INT
);
CREATE TABLE dj_phones
(
phone_number varchar2(12),
activated number(1) default 0,
activation_date date default null,
CONSTRAINT dj_phone_number_check
CHECK (substr(phone_number,1,5) in( '35566','35567','35568','35569') ),
CONSTRAINT dj_activated_check
CHECK (activated in(1,0) )
dj_KlientID int FOREIGN KEY REFERENCES dj_Abonenti(dj_KlientID)
);
CREATE TABLE dj_telef
(
start_time date,
end_time date,
abonent_1 varchar2(10),
abonent_2 varchar2(10)
);
Error at Command Line : 26 Column : 17
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:

The line number is from your SQL Developer script window, which isn't entirely helpful as it doesn't seem to align with the issue. There may be other things too but you're missing a comma after your check constraint (just like a previous question). But you should put the constraints at the end of the command:
CREATE TABLE dj_phones
(
phone_number varchar2(12),
activated number(1) default 0,
activation_date date default null,
dj_KlientID int FOREIGN KEY REFERENCES dj_Abonenti(dj_KlientID)
CONSTRAINT dj_phone_number_check
CHECK (substr(phone_number,1,5) in( '35566','35567','35568','35569') ),
CONSTRAINT dj_activated_check
CHECK (activated in(1,0) )
);
You might find it easier to debug these issues if you ran one statement at a time, either with the run statement command (control-enter), or by highlighting the text one one command and using run script (F5).

Related

UNIQUE constraint failed sqlite

Before I alter a table I want to make a backup of it, so I use this code :
CREATE TABLE states_BACKUP (
state_id INTEGER NOT NULL,
domain VARCHAR(64),
entity_id VARCHAR(255),
state VARCHAR(255),
attributes TEXT,
event_id INTEGER,
last_changed DATETIME,
last_updated DATETIME,
created DATETIME,
context_id VARCHAR(36),
context_user_id VARCHAR(36), old_state_id INTEGER,
PRIMARY KEY (state_id),
FOREIGN KEY(event_id) REFERENCES events (event_id)
);
INSERT into states_BACKUP
Select *
FROM STATES;
However when the insert part is executed an error message says :
Execution finished with errors.
Result: UNIQUE constraint failed: states_BACKUP.state_id
At line 18:
INSERT into states_BACKUP
Select *
FROM STATES;
when I change the code to
Select distinct *
FROM STATES;
I get the same eror.
Trying to find an answer on the web how to solve this problem, I find this error has to do with duplicate id's. I wonder how this can happen when I just copy a table.
Anyone has a solution for this ?

SQL Error: ORA-00904: : invalid identifier in line 4

I was working in sql command line and got this error ORA-00904 when i queried to create a table
I tried various inputs and got the same error in line 4.
Help me out.
If you create a table
Then this would work :
CREATE TABLE DATA
(
ID INT NOT NULL,
NAME VARCHAR2(10) NOT NULL
);
But this would raise an ORA-00904 :
CREATE TABLE DATA
(
ID INT NOT NULL,
NAME VARCHAR2(10) NOT NULL,
);
The difference?
After that last comma, something more is expected.
Yet, all it finds is a round bracket.
Hence, the error.

sqlite integer primary key not null constraint failed

According to the SQLite documentation / FAQ a column declared INTEGER PRIMARY KEY will automatically get a value of +1 the highest of the column if omitted.
Using SQLite version 3.22.0 2018-01-22 18:45:57
Creating a table as follows:
CREATE TABLE test (
demo_id INTEGER PRIMARY KEY NOT NULL,
ttt VARCHAR(40) NOT NULL,
basic VARCHAR(25) NOT NULL,
name VARCHAR(255) NOT NULL,
UNIQUE(ttt, basic) ON CONFLICT ROLLBACK
) WITHOUT ROWID;
Then inserting like this:
INSERT INTO test (ttt, basic, name) VALUES ('foo', 'bar', 'This is
a test');
gives:
Error: NOT NULL constraint failed: test.demo_id
sqlite>
When it is expected to create a record with a demo_id value of 1. Even if the table already contains values, it'll fail inserting the row without explicitly specifying the id with the same error.
What am I doing wrong?
The documentation says that you get autoincrementing values for the rowid. But you specified WITHOUT ROWID.

Mroonga on Mariadb Primary Key Insert error

I keep on getting duplicate primary key error when trying to insert into my Mroonga table on MariaDB 10.0.19. Does anyone know what might be the cause?
SQL:
insert into tbl_mroonga select pk_id, keyword from tbl_inno;
Create table:
create table tbl_mroonga (
'PK_ID' int(11) not null default 0,
'Keyword' varchar(191) null default null,
primary key (`pk_id`),
fulltext index ('keyword')) Engine=MROONGA;
create table tbl_inno (
'PK_ID' int(11) not null default 0,
'Keyword' varchar(191) null default null,
primary key (`pk_id`),
fulltext index ('keyword')) Engine=INNODB;
I'm inserting about 3.5million rows from tbl_inno to tbl_mroonga and it fails at around 400K rows. I've tried it with "select distinct" and "group by pk_id" and still it fails.
Any help would be greatly appreciated!
Thank you.
Write a loop that copies over 10K rows at a time. Use something like (example of the 13th chunk):
INSERT INTO tbl_mroonga
SELECT pk_id, keyword
FROM tbl_inno
WHERE pk_id > 120000
AND pk_id <= 130000
and COMMIT after each chunk.

SQL Error: No more data to read from socket while inserting data in table

I have created a table in oracle xe
create table tbl_unit_mst
(
id number(10,0) constraint id_pk primary key,
unit_code char(2) not null constraint unit_code_uk unique,
unit_name varchar2(30) not null constraint unit_name_uk unique,
crtd_date date default sysdate,
is_active number(1,0) default 1 constraint is_active_ck check(is_active in (0,1)),
crtd_by varchar2(6)
);
and then created a squence
create sequence seq_tbl_unit
start with 1
increment by 1
nocache
nocycle;
then I created a Trigger
create trigger trig_id_increment
before insert
on tbl_unit_mst for each row
begin
select seq_tbl_unit.nextval into : new.id from dual;
end;
Now when I am trying to run an insert statement
insert into tbl_unit_mst ( unit_code, unit_name) values('01','Ajbapur');
it gives an error SQL Error: No more data to read from socket
If I disable Trigger then it is working fine.
can anyone help me to find out where I am making mistakes

Resources