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

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';

Related

ORA-01722: invalid number - type issue in 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)

Oracle pushing me ORA-00902: invalid datatype

create table accountDetails(
accountNumber int unique,
customerId int unique,
balance int not null,
password varchar(255) not null,
type varchar(255) not null check(type in ('Savings','Current')),
primary key(accountNumber,customerId) )
create table statusDetails(
customerId int references accountDetails(customerId),
primarykey(customerId))
The last table resulted in an error
The last table resulted in an error
ORA-00902: invalid datatype error happens when we try to define a column using an invalid datatype. It's logical really.
Now, you think you haven't declared a column with an invalid datatype, because you think statusdetails table has only one column, customerid. But if you look at your actual statement you follow that column with this:
primarykey(customerId))
Because you mis-typed primary key Oracle treats that line as an attempt to create a second column. Hence the error, because (customerId) is an invalid datatype. So all you need do is pop in the missing space and Oracle will create the table for you.
create table statusDetails(
customerId int references accountDetails(customerId),
primary key(customerId))
You had a compilation error caused by a simple typo. A key skill for a developer is the ability to turn a cool eye on our own code. I urge you to work on acquiring that skill as soon as you can.
Your second table declaration is all wrong. Try this:
CREATE TABLE statusdetails (
customerid INT,
CONSTRAINT fk_cust FOREIGN KEY ( customerid )
REFERENCES accountdetails ( customerid )
)
Note: using "int" data type maps to a NUMBER(38), which may not be what you want. Use the proper oracle data type names.

create a table with additional null column in Oracle

I am trying to create a table and wrote following code
create table trial as(
SELECT l2_group AS Customer
, null AS Contact
FROM ACCT_MASKED_sep17_V1) ;
It's giving me an error when I run with create table where as select query runs.
How can I get the result
You need to specify a data type for that NULL column. For example:
create table t1 as
select 1 as c1
, cast(null as number) as c2
from dual
Table created.
If as a datatype for the NULL column you choose VARCHAR2(length) datatype, the length needs to be greater than 0.

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

Insert query showing an error

I created a table in oracle10g using following query......
CREATE TABLE "MOBILELOCATION"
("EMPLOYEEID" NUMBER NOT NULL ENABLE,
"PRESENTDATE" VARCHAR2(30) NOT NULL ENABLE,
"PRESENTTIME" VARCHAR2(30) NOT NULL ENABLE,
"LATITUDE" NUMBER(6,10) NOT NULL ENABLE,
"LONGITUDE" NUMBER(6,10) NOT NULL ENABLE)
Table was created successfully... but the problem is while iam trying to insert a row into the table it is showing the error
error ORA-01438: value larger than specified precision allowed for this column
The query i used is ,
insert into mobilelocation values(12303,'30-10-2011','09:30',16.9876,82.3426);
Where i voilated the constraints?? Please explain any one..
Your columns LATITUDE and LONGTITUDE are defined rather strangely - NUMBER(6,10) says 6 for precision (total number of digits) and 10 for scale (number of digits to the right of the decimal point).
You either change them to NUMBER(*) or to NUMBER (10, 6) or NUMBER(*,4) or similar... the correct declaration is hard to guess but all mentioned would work with the sample data you provided...
For reference see http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/datatype.htm#i16209

Resources