SQL Error: ORA-01722: invalid number - oracle

Here is my table.
CREATE TABLE SCHEDULE (
SCHEDULE_ID INT NOT NULL
,ARRV_TIME INT NOT NULL
,DEP_TIME INT NOT NULL
,BUS_TRANSFERS VARCHAR2(40) NOT NULL
,BUS_ID NUMERIC NOT NULL
,TRAVEL_DIRECTION VARCHAR(10) NOT NULL
,WEEK_DAY INTEGER NOT NULL
);
I run this insert statement
INSERT INTO SCHEDULE (SCHEDULE_ID, ARRV_TIME, DEP_TIME, BUS_TRANSFERS, BUS_ID, TRAVEL_DIRECTION, WEEK_DAY)
VALUES (SEQ_SCHEDULE.NEXTVAL,'10', '11', 'White Oak', '2', 'North', '4');
and I get this error message:
Error starting at line : 1 in command - INSERT INTO SCHEDULE
(SCHEDULE_ID, ARRV_TIME, DEP_TIME, BUS_TRANSFERS, BUS_ID,
TRAVEL_DIRECTION, WEEK_DAY) VALUES (SEQ_SCHEDULE.NEXTVAL,'10', '11',
'White Oak', '2', 'North', '4')
Error report - SQL Error: ORA-01722: invalid number
01722. 00000 - "invalid number"
*Cause: The specified number was invalid.
*Action: Specify a valid number.

Try This :-
CREATE TABLE SCHEDULE(
SCHEDULE_ID INTEGER NOT NULL ,
ARRV_TIME INTEGER NOT NULL ,
DEP_TIME INTEGER NOT NULL ,
BUS_TRANSFERS VARCHAR2(40) NOT NULL ,
BUS_ID INTEGER NOT NULL ,
TRAVEL_DIRECTION VARCHAR2(10) NOT NULL ,
WEEK_DAY INTEGER NOT NULL );
INSERT INTO SCHEDULE(SCHEDULE_ID, ARRV_TIME, DEP_TIME,BUS_TRANSFERS,BUS_ID, TRAVEL_DIRECTION, WEEK_DAY)
VALUES(SEQ_SCHEDULE.NEXTVAL,10,11, 'White Oak',2,'North',4);

This error is because you have declared arrived_time as int and you are trying to insert '10' value for that. Which is a string please remove the quotes for non string data types

Related

Informix - Insert a boolean attribute

I have this table definition :
CREATE TABLE Usuarios
(
CI INT PRIMARY KEY,
primer_nombre varchar(25) NOT NULL CHECK (primer_nombre MATCHES '^[a-zA-Z]$' ),
segundo_nombre varchar(25),
primer_apellido varchar(25) NOT NULL,
segundo_apellido varchar(25),
grado INT CHECK ( grado > 0 AND grado < 8),
fecha_nacimiento DATE NOT NULL,
nota INT CHECK ( nota > 0 AND nota < 13),
email varchar(80),
hace_proyecto boolean,
tipo varchar(20) CHECK (tipo IN ('Admin', 'Docente', 'Alumno')),
encriptacion_hash varchar(250),
encriptacion_sal varchar(250),
baja boolean
);
And this insert statement :
INSERT INTO Usuarios (CI, primer_nombre,segundo_nombre,primer_apellido,segundo_apellido,grado,fecha_nacimiento,nota,email,hace_proyecto,tipo,encriptacion_hash,encriptacion_sal,baja)
VALUES (
999999,
"Gabriel"
"Matias",
"Barrios",
"Cabrera",
NULL,
"10/28/1986",
1,
"myemail#gmail.com"
true,
"Alumno",
NULL,
NULL,
false
);
No matter what I do, I always get :
Connected.
201: A syntax error has occurred.
Error in line 17
Near character position 8
Disconnected.
I think it is related to my boolean fields. Is this true? How can I insert a boolean into my table ?
You are missing a ',' after "Gabriel" and then again after "myemail#gmail.com", and lastly the booleans are inserted as 't' or 'f' I believe.
Once I made those changes I just get an error about one of the check constraint's failing.

SQL Error: ORA-00906: missing left parenthesis

CREATE TABLE Customer_TBL
(CustomerID INTEGER NOT NULL PRIMARY KEY,
CustomerName VARCHAR NOT NULL,
JobPosition VARCHAR,
CompanyName VARCHAR NOT NULL,
USState VARCHAR NOT NULL,
ContactNo BIGINTEGER NOT NULL);
Error starting at line : 1 in command -
Error report - SQL Error: ORA-00906: missing left parenthesis
00906. 00000 - "missing left parenthesis"
*Cause:
*Action:
Biginteger is not supported in Oracle, use number instead. And you need to use varchar2(number of char/bytes) or varchar(number of char/bytes).
Why the error missing left parenthesis?
Because Oracle was expecting ( after VARHCHAR but it was not there.
CREATE TABLE Customer_TBL (CustomerID INTEGER NOT NULL PRIMARY KEY,
CustomerName VARCHAR2(20) NOT NULL,
JobPosition VARCHAR2(20),
CompanyName VARCHAR2(20) NOT NULL,
USState VARCHAR2(20) NOT NULL,
ContactNo NUMBER NOT NULL);
You need to specify a maximum size for VARCHAR fields, e.g: field_name VARCHAR(40),

"Error at Command Line : 1 Column : 698 Error report - SQL Error: ORA-00984: column not allowed here

INSERT INTO
FLAG ("OPT_FLAG_KEY","H_KEY","FIRST_NAME","LAST_NAME",
"MIDDLE_NAME","TITLE","CREDENTIALS","ADDRESS_LINE_1",
"ADDRESS_LINE_2","ADDRESS_LINE_3","CITY","STATE",
"POSTAL_CODE","PHONE_NUMBER","BUSIN_PHONE","DECEASED",
"OPT_FLAG","OPT_FLAG_DATE","SOU_KEY","SOU_FILE_ID",
"SOU_FILE_ID_TEXT","BAT_ID","PHONE_NUMBER_SOURCE","BIRTH_DATE")
VALUES(37009326,4,'Daniel','Boyle',NULL,NULL,NULL,'368 Road',
NULL,NULL,'Doylown','BVBV',1801,NULL,NULL,'NO','OUT',
TO_CHAR('10-AUG-16','DD/MM/YYYY'),201,
TO_DATE(SUBSTR('vhic_pavir_20160810.txt',12,8),YYYYMMDD),
'2016-08-10',598441,NULL,TO_DATE('03-FEB-1952',DD-MM-YYYY));
I have run this query in my DB am getting some error like below
Error at Command Line : 1 Column : 698
Error report
SQL Error: ORA-00984: column not allowed here
00984. 00000 - "column not allowed here"
*Cause:
*Action:"
Edit: this is my desc of my table:
Name Null Type
------------------- ---- -------------
OPT_FLAG_KEY NUMBER(14)
H_KEY NUMBER(14)
FIRST_NAME VARCHAR2(50)
LAST_NAME VARCHAR2(50)
MIDDLE_NAME VARCHAR2(50)
TITLE VARCHAR2(50)
CREDENTIALS VARCHAR2(50)
ADDRESS_LINE_1 VARCHAR2(100)
ADDRESS_LINE_2 VARCHAR2(100)
ADDRESS_LINE_3 VARCHAR2(100)
CITY VARCHAR2(50)
STATE VARCHAR2(20)
POSTAL_CODE VARCHAR2(20)
PHONE_NUMBER VARCHAR2(100)
BUSIN_PHONE VARCHAR2(100)
DECEASED VARCHAR2(5)
OPT_FLAG VARCHAR2(10)
OPT_FLAG_DATE DATE
SOU_KEY NUMBER(14)
SOU_FILE_ID DATE
SOU_FILE_ID_TEXT VARCHAR2(20)
BATCH_ID NUMBER(14)
PHONE_NUMBER_SOURCE VARCHAR2(100)
BIRTH_DATE DATE
There are several issue with your statement. First, double-quotes are not required on column names (unless you have mixed cases or space), remove them.
TO_CHAR('10-AUG-16','DD/MM/YYYY') -> 10-AUG-16 is a string, not a date. Thus it does not make any sense to convert a string to a string
TO_DATE(SUBSTR('vhic_pavir_20160810.txt',12,8),YYYYMMDD) -> Format must be in single-quotes, i.e. TO_DATE(SUBSTR('vhic_pavir_20160810.txt',12,8),'YYYYMMDD')
'2016-08-10' -> do you like to insert a DATE value or a string? You provided a string, not a date.
TO_DATE('03-FEB-1952',DD-MM-YYYY)) -> Format must be in single-quotes, see above. MM means the month number, not the month name.

ORA-01722: invalid number with to_char timestamp

First, the table I'm trying to insert into is this table:
CREATE TABLE Message
(
MessageID varchar2(80) NOT NULL,
Message varchar2(500),
SendDate date NOT NULL,
SendID varchar2(50) NOT NULL,
Request_ID varchar2(50) NOT NULL,
PRIMARY KEY (MessageID)
);
and my insert query is this(Spring, mybatis):
INSERT INTO message (
messageid
, message
, senddate
, sendId
, request_Id
)VALUES(
#{sendidjbuser} + TO_CHAR(systimestamp, 'yyyymmddhh24missff3')
, #{message}
, sysdate
, #{sendidjbuser}
, #{requestIdjbuser}
)
I tried this on cmd and this part of the above query was the problem:
INSERT INTO message (messageId) VALUES('sendId' + TO_CHAR(systimestamp, 'yyyymmddmissff3'))
I'm on Oracle 11. I just tried inserting only TO_CHAR(systimestamp, 'yyyymmddmissff3') without adding that to a string and it worked. But I do need that part to work. Is there a right way to do that?
In Oracle, please use || or CONCAT() function to concatenate strings. You are using '+', hence getting the error.

ORA-00904: "DWH_ITEM_SEQ"."NEXTAVL": invalid identifier

Can anyone explain to me why I get a 00904 error when I run the following
I need to insert into tabel a 100 rows and I dont no why the error
drop table DWH_ITEM_DIM;
CREATE TABLE DWH_ITEM_DIM(
ITEM_ID NUMBER NOT NULL,
ITEM_NAME VARCHAR2(5) NOT NULL,
ITEM_TYPE VARCHAR2(1) NOT NULL,
ITEM_COST NUMBER(10,2) NOT NULL,
ITEM_PRICE NUMBER(10,2) NOT NULL,
ITEM_FOR_SALE VARCHAR2(1) NOT NULL,
CONSTRAINT ITEM_ID_PK PRIMARY KEY (ITEM_ID));
DROP SEQUENCE DWH_ITE_SEQ;
CREATE SEQUENCE DWH_ITE_SEQ
START WITH 1
INCREMENT BY 1
NOCACHE
NOCYCLE;
TRUNCATE TABLE DWH_ITEM_DIM;
INSERT INTO DWH_ITEM_DIM
SELECT DWH_ITE_SEQ.NEXTAVL AS ITEM_ID,
DBMS_RANDOM.STRING('U',5) AS ITEM_NAME,
DBMS_RANDOM.STRING('U',1) AS ITEM_TYPE,
ROUND(dbms_random.value(LOW =>25,HIGH =>300),2) AS ITEM_COST,
ROUND(dbms_random.value(LOW =>25,HIGH =>300),2) AS ITEM_PRICE,
DBMS_RANDOM.STRING('U',1) AS ITEM_FOR_SALE
FROM DUAL
CONNECT BY LEVEL <= 100;
COMMIT;
When I run this the 'script Output' is:
table DWH_ITEM_DIM dropped.
table DWH_ITEM_DIM created.
sequence DWH_ITE_SEQ dropped.
sequence DWH_ITE_SEQ created.
table DM.DWH_ITEM_DIM truncated.
Error starting at line 19 in command:
INSERT INTO DM.DWH_ITEM_DIM
SELECT DWH_ITE_SEQ.NEXTAVL AS ITEM_ID,
DBMS_RANDOM.STRING('U',5) AS ITEM_NAME,
DBMS_RANDOM.STRING('U',1) AS ITEM_TYPE,
ROUND(dbms_random.value(LOW =>25,HIGH =>300),2) AS ITEM_COST,
ROUND(dbms_random.value(LOW =>25,HIGH =>300),2) AS ITEM_PRICE,
DBMS_RANDOM.STRING('U',1) AS ITEM_FOR_SALE
FROM DUAL
CONNECT BY LEVEL <= 100
Error at Command Line:20 Column:8
Error report:
SQL Error: ORA-00904: "DWH_ITE_SEQ"."NEXTAVL": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
commited.
I don't no why? please help me I'm new in oracle
It's a typo, change NEXTAVL TO NEXTVAL.
Try NEXTVAL instead of NEXTAVL.

Resources