ORA-00911: invalid character....why exactly is this error occuring? - sql

CREATE TABLE users (
username VARCHAR(45) NOT NULL ,
password VARCHAR(60) NOT NULL ,
enabled Number(3) DEFAULT 1 NOT NULL,
PRIMARY KEY (username));
INSERT INTO user_table(username,password,enabled)
VALUES ('test1','$2a$10$04TVADrR6/SPLBjsK0N30.Jf5fNjBugSACeGv1S69dZALR7lSov0y', true);
INSERT INTO users(username,password,enabled)
VALUES ('test2','$2a$10$04TVADrR6/SPLBjsK0N30.Jf5fNjBugSACeGv1S69dZALR7lSov0y', true);
Error Message :
ORA-00911: invalid character

Oracle does not support boolean type.
So, instead of [true] for enabled field, you probably should use 'true' or 1.
SQLFiddle

Related

How do I fix my my table so I don't get that the invalid datatype message?

I am trying to create a table in SQL and every time it I get the following error message:
ORA-00902: invalid datatype
SQL> create table BUSINESS (
2 B_IDINTEGER PRIMARY KEY,
3 B_CITYchar(20) not null,
4 B_NAMECHAR (20) NOT NULL,
5 B_CATEGORY(S) CHAR (25),
6 B_ACCTCHAR (25)
7 );
B_CITYchar(20) not null,
*
ERROR at line 3:
ORA-00902: invalid datatype
It is supposed to say table created but I don't know what is wrong with line 3.
You have several errors in your code. Try something like this:
create table BUSINESS (
B_ID INTEGER PRIMARY KEY,
B_CITY varchar2(20) not null,
B_NAME varchar2(20) NOT NULL,
B_CATEGORY varchar2(25),
B_ACCT varchar2(25)
);
Note that you should generally use variable length strings unless you know the value has a fixed length (which might be true of b_acct but is not true for b_city).

postgres syntax error at or near "ON"

I created this table:
CREATE TABLE IF NOT EXISTS config_activity_log
(
id serial primary key,
activity_name varchar(100) NOT NULL,
last_config_version varchar(50) NOT NULL,
activity_status varchar(100) NOT NULL DEFAULT 'Awaiting for cofman',
cofman_last_update bigint NOT NULL DEFAULT -1,
is_error boolean DEFAULT FALSE,
activity_timestamp timestamp DEFAULT current_timestamp
);
I try to run this postgres script:
INSERT INTO config_activity_log
(activity_name, last_config_version, activity_status)
VALUES
('test awating deployment','5837-2016-08-24_09-12-22', 'Awaiting for deployment')
ON CONFLICT (activity_name)
DO UPDATE SET
activity_status = EXCLUDED.activity_status
why do i get this syntax error?
psql:upsert_test_log.sql:7: ERROR: syntax error at or near "ON"
LINE 5: ON CONFLICT (activity_name)
Supported Version
Per #klin's comment above, ON CONFLICT is only supported from PostgreSQL 9.5 onwards.
If you're on an earlier version, there's some great info in this answer: https://stackoverflow.com/a/17267423/361842
Unique Constraint
Add a unique index on activity_name. At present there's no constraints on that column, so there's no possibility for a conflict on that column.
CREATE UNIQUE INDEX UK_config_activity_log__activity_name
ON config_activity_log (activity_name);
If, however, you don't want that column to be unique, what conflict are you envisaging / what's the issue you're hoping to resolve with the on conflict action?
See conflict_target in https://www.postgresql.org/docs/9.5/static/sql-insert.html#SQL-ON-CONFLICT
An alternative syntax is to modify your create statement to include the unique condition there; e.g.
CREATE TABLE IF NOT EXISTS config_activity_log
(
id serial primary key,
activity_name varchar(100) NOT NULL UNIQUE,
last_config_version varchar(50) NOT NULL,
activity_status varchar(100) NOT NULL DEFAULT 'Awaiting for cofman',
cofman_last_update bigint NOT NULL DEFAULT -1,
is_error boolean DEFAULT FALSE,
activity_timestamp timestamp DEFAULT current_timestamp
);
According to the error code, your version does not support ON CONFLICT.
On PostreSQL 9.6 the error message is -
[Code: 0, SQL State: 42P10] ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification

ORA-001722 Invalid Number when insert in Oracle SQL

CREATE TABLE the_user( Name VARCHAR(40) not null,
Address VARCHAR(255) not null,
Delivery_address VARCHAR(255),
Email VARCHAR(25) not null,
Phone INTEGER not null,
Status INTEGER not null,
Password VARCHAR(25) not null,
DOB DATE not null,
PRIMARY KEY (Email),
FOREIGN KEY (Status) REFERENCES User_Status (Status_Id),
CONSTRAINT check_Password CHECK (Password > 4)
);
INSERT INTO the_user VALUES (
'Pergrin Took',
'12 Bag end, hobbiton, The Shire, Eriador',
'The address, Dublin',
'ptook#lotr.com',
'8679046',
'001',
'treebeard',
TO_DATE('2013/11/04 14:11:34', 'yyyy/mm/dd hh24:mi:ss')
);
I have the above database in Oracle but when I try to run the insert command I get an ORA-1722 error, Invalid Number. There is a entry in the user_status table which corresponds to the 1 in the insert.
I have been stuck on this for days.
Quotes are not a problem - it will be converted implicitly to numbers as far as they are valid.
Check your constraints:
CONSTRAINT check_Password CHECK (Password > 4)
Here you try to compare string and number -> in this comparison Oracle always tries to cast both as numbers -> password fails and you see an error.
Try to use instead of password e.g. '55' and you will see the row is inserted.
Perhaps you wanted to do this?
CONSTRAINT check_Password CHECK (length(Password) > 4)

JavaDB throws error when boolean is used. why?

This is the table I try to create in JavaDB.
CREATE TABLE USER(
userid INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
displayName VARCHAR(20) not null,
username VARCHAR(15) not null unique,
password VARCHAR(15) not null,
adminrole boolean default false,
lastlogin timestamp default CURRENT TIMESTAMP
);
I get Error code -1, SQL state 42X01: Syntax error: BOOLEAN.
Line 3, column 1
You have to use JavaDB Version 10.7 or later and also upgrade your database to new version too.

ORA-00907 when trying to create a CHECK constraint

I need your help with this error:
ORA-00907 on Check CONSTRAINT
Query:
CREATE TABLE S_NEWS.T_UTILISATEUR_USR (
USR_ID INTEGER NOT NULL PRIMARY KEY,
USR_MAIL VARCHAR(256) NOT NULL,
USR_TITRE CHAR(6) NULL DEFAULT 'M.'CHECK (USR_TITRE IN ('M.' , 'Mlle.','Mme.' )),
USR_NOM CHAR(32) NOT NULL,
USR_PRENOM VARCHAR(32) NULL,
USR_ORGANISATION VARCHAR(128) NULL
);
The error message is
ORA-00907: missing right parenthesis
It almost always points to a syntax error rather than a missing bracket. In this case the parser is objecting to the order of the elements in your column definition. Specifically, the DEFAULT clause must come before the CONSTRAINT clause, which includes the NULL/NOT NULL declaration. So try
USR_TITRE CHAR(6) DEFAULT 'M.'CHECK (USR_TITRE IN ('M.' , 'Mlle.','Mme.' )) NULL
Incidentally, you're going to a problem with that constraint. A CHAR datatype is always padded to the declared length. Thus if you enter 'M.' into the column it will pad out to 'M. ', which value will cause the constraint to hurl an exception. I suggest you use VARCHAR2(6) instead.
CHAR declarations are almost always a mistake, just a bug waiting to happen.