ORA-01722: invalid number - type issue in oracle - oracle

I have a problem with data type and relationship between two tables
let's assume I have two tables as shown in the image
First table: Attached _file. The ID coulmn is number
Second table: FN_Transaction. the ID coulmn is varchar(20)
The ID in FN_Transaction has four cases
ID is null which means there is no attached file
ID has text as 'No' cell which means there is no attached file
ID starts with 0, but it will be equaled ID in Attached _file table such as 01222 = 1222
ID in FN_Transaction equals ID in Attached _file without 0 such as 2344 = 2344
let's see the query
with docs as
(
SELECT
ID,
COUNT(type) fileNo,
MAX(Date) date
FROM
Attached_file
GROUP BY
ID
)
Select
InvoiceNo,
fileNo,
date,
Amount
from
FN_transaction x1
left join docs x2 on
(Trim(x1.ID) = x2.ID)
the error that I got
Error report -
SQL Error: ORA-12801: error signaled in parallel query server P034, (1)
ORA-01722: invalid number
12801. 00000 - "error signaled in parallel query server %s"
*Cause: A parallel query server reached an exception condition.
*Action: Check the following error message for the cause, and consult
your error manual for the appropriate action.
Do you have an idea about how to handle this type of column?
Please advise

You can use the default on conversion error clause in TO_NUMBER function (introduced in 12.2) as follows:
ON ( to_number(X1.ID default null on conversion error) = X2.ID )
Note that 01222 will be automatically converted to a number 1222. character NO will be converted to NULL because of default on conversion error and it will not match the join condition(which satisfies your requirement)

Related

ORA-01722: invalid number, olympics schema on oracle live

The SQL giving error in oracle live
select a.athlete_name
from olym.olym_athletes a,
olym.olym_athlete_games c
where a.id=c.athlete_id
and nation_id='MAS';
Error:-ORA-01722: invalid number
What I am trying to do here is display all the Malaysian Olympics athletes. I am using public schema from oracle live. I am not sure why I keep getting invalid number error here.
Details below:-
TABLE OLYM_ATHLETES
Column Null? Type
ID NOT NULL NUMBER
ATHLETE_NAME NOT NULL VARCHAR2(255)
ATHLETE_GENDER NOT NULL VARCHAR2(10)
TABLE OLYM_ATHLETE_GAMES
Column Null? Type
ID NOT NULL NUMBER
ATHLETE_ID NOT NULL NUMBER
GAME_ID NOT NULL NUMBER
NATION_ID NOT NULL NUMBER
your nation_id is a number hence you can use olym_nations table to get the nation_id
select a.athlete_name from olym.olym_athletes a,
olym.olym_nations b, olym.olym_athlete_games c where
a.id=c.athlete_id and c.nation_id=b.id and b.nation='MAS';

Sqlldr log shows wrong column name when facing ORA-01722

I have a simple table with three columns.
Table name DUMMY20210527
desc DUMMY20210527
PID NUMBER(10)
VDATE DATE
SID NUMBER(10)
Control File
LOAD DATA CHARACTERSET JA16SJIS
APPEND INTO TABLE "DUMMY20210527" fields terminated by '\t' trailing nullcols
(
pid ,
vdate date "YYYY/MM/DD",
sid
)
Data File
a b c
1 2019/01/10 X
When trying to load this file log is showing error in column vdate. however wrong value x is provided in column sid
Log
Record 1: Rejected - Error on table "DUMMY20210527", column VDATE.
ORA-01722: invalid number
Table "DUMMY20210527":
0 Rows successfully loaded.
1 Row not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null.
However if the following file is loaded then proper error message is shown
a b c
X 2019/01/10 1
Log
Record 1: Rejected - Error on table "DUMMY20210527", column PID.
ORA-01722: invalid number
Table "DUMMY20210527":
0 Rows successfully loaded.
1 Row not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null.
Oracle version used: Oracle 19c

How do I insert into a pre-existing rows from another table for a whole column Oracle SQL?

I am trying to insert postal codes from one table(insert into pre-existing rows) to another table of addresses that have null postal codes. The address_id in postalcodes corresponds to the address_id in address table.
The postal codes table has the address_id and postalcode.
Here is the postal codes table:
Here is the address table:
This is what I have tried.
INSERT INTO address ( postal_code )
SELECT
postalcodes.postalcode
FROM
postalcodes
WHERE
address.address_id = postalcodes.address_id;
But it gives me an error:
Error starting at line : 26 in command -
INSERT INTO address ( postal_code )
SELECT
postalcodes.postalcode
FROM
postalcodes
WHERE
address.address_id = postalcodes.address_id
Error at Command Line : 32 Column : 9
Error report -
SQL Error: ORA-00904: "ADDRESS"."ADDRESS_ID": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
You want an update, not an insert:
UPDATE address
SET postal_code = (SELECT p.postal_code
FROM postalcodes p
WHERE a.address_id = p.address_id
)
WHERE postal_code IS NULL;
You need to insert the rest of the values for address. You can't insert postal codes by themselves. Or are you trying to update the values of zipcodes for existing addresses?. Creating zip codes into address will give you NULL, NULL, NULL, ZIP_CODE, NULL, ECT. IF it doesnt give you an error based on some primary key constrain
Maybe trying selecting
FROM
postalcodes, Address
SQL hAs no ida what address is unless you select from it.

SQL Error: ORA-01722: invalid number

I have enclosed the table and the insert statement I am working on.
CREATE TABLE EMP (
DRIVER_ID INTEGER NOT NULL
, FNAME VARCHAR(30) NOT NULL
, LNAME VARCHAR(30) NOT NULL
, ADDRESS VARCHAR(50) NOT NULL
, SALARY VARCHAR(50) NOT NULL
, DOB DATE NOT NULL
, SHIFTS VARCHAR2(20) NOT NULL
, SSN CHAR(11) NOT NULL
, PHONE INTEGER NOT NULL
, HIRING_DATE DATE NOT NULL
, EMAIL VARCHAR2(50) NOT NULL
);
When I run this insert statement:
INSERT INTO EMP (DRIVER_ID, FNAME, LNAME, ADDRESS, SALARY, DOB, SHIFTS, SSN, PHONE, HIRING_DATE, EMAIL)
VALUES (SEQ_EMP.NEXTVAL,'Emma', 'Johnson', '123 Main Street', 'DIRECT DEPOSIT', '31 JANUARY,1988', 'MORNING', '579-45-6666', '410-555-1112', '16 DECEMBER,2013', 'ejohnson#fakemail.com');
I get this error message
SQL Error: ORA-01722: invalid number
01722. 00000 - "invalid number"
*Cause: The specified number was invalid.
*Action: Specify a valid number.
Lets look at this logically. The error message is saying "invalid number". Oracle is saying to you "I am expecting a number, but you gave me something that isn't a number".
Looking at the table SQL, you can see that the table has two columns whose type is a number type (actually INTEGER). These are DRIVER_ID and PHONE. (The other columns don't matter now ... because they won't expect a number as the value.)
Now look at the insert SQL, and the values corresponding to those columns.
The value inserted into the DRIVER_ID column comes from SEQ_EMP.NEXTVAL ... which I would assume has type INTEGER. That means, you won't get an error from there.
The value inserted into the PHONE column is '410-555-1112'. But, hey, that isn't a number. Its a string! And besides a (mathematical) number doesn't have hyphen characters embedded in it!
In short, if you are going to store phone numbers with - (or + or space) characters embedded in them, you can't use INTEGER as the column type.
In your table DDL change
PHONE INTEGER NOT NULL
to
PHONE CHAR(12) NOT NULL
as previously mentioned by user Stephen C using CHAR instead of INTEGER.
Also, those DATE fields will have to be converted to CHAR datatypes as well or you'll have to format your INSERT to handle the date format properly. Those fields are:
, DOB DATE NOT NULL
, HIRING_DATE DATE NOT NULL
If you chose to keep the columns as DATEs, then in your insert use (for the above-mentioned columns) the following...
,to_date('31-JANUARY-1988','DD-MONTH-YYYY')
,to_date('16-DECEMBER-2013','DD-MONTH-YYYY')
The above won't give you exactly what you are looking for -- e.g. 16 DECEMBER,2013 -- but it will work and format the date with hyphens -- e.g. 16-DECEMBER-2013. If you need further information on the to_date() function for Oracle for formatting and for other sundry information, please refer to the Oracle docs or search on "Oracle TO_DATE" via your favorite browser.
HTH

Problem with Oracle Sql Loader control file

I'm trying to load some data using sql loader. Here is the top of my control/data file:
LOAD DATA
INFILE *
APPEND INTO TABLE economic_indicators
FIELDS TERMINATED BY ','
(ASOF_DATE DATE 'DD-MON-YY',
VALUE FLOAT EXTERNAL,
STATE,
SERIES_ID INTEGER EXTERNAL,
CREATE_DATE DATE 'DD-MON-YYYY')
BEGINDATA
01-Jan-79,AL,67.39940538,1,23-Jun-2009
... lots of other data lines.
The problem is that sql loader won't recognize the data types I'm specifying. This is the log file:
Table ECONOMIC_INDICATORS, loaded from every logical record.
Insert option in effect for this table: APPEND
Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
ASOF_DATE FIRST * , DATE DD-MON-YY
VALUE NEXT * , CHARACTER
STATE NEXT * , CHARACTER
SERIES_ID NEXT * , CHARACTER
CREATE_DATE NEXT * , DATE DD-MON-YYYY
value used for ROWS parameter changed from 10000 to 198
Record 1: Rejected - Error on table ECONOMIC_INDICATORS, column VALUE.
ORA-01722: invalid number
... lots of similiar errors, expected if trying to insert char data into a numeric column.
I've tried no datatype spec, all other numeric specs, and always the same issue. Any ideas?
Also, any ideas on why it's changing the Rows parameter?
From your example, SQL*Loader will try to evaluate the string "AL" to a number value, which will result in the error message you gave. The sample data has something looking like it could be a decimal number at third position, not second as specified int he column list.

Resources