Insert query showing an error - oracle

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

Related

Unusable partition Oracle / datastage

I am facing an issue with my datastage job. I have to fill a table ttperiodeas in Oracle from a .csv file. The SQL query in Oracle connector is shown in this screenshot:
Oracle connector
And here is the oracle script
CREATE TABLE TTPERIODEAS
(
CDPARTITION VARCHAR2(5 BYTE) NOT NULL ENABLE,
CDCOMPAGNIE NUMBER(4,0) NOT NULL ENABLE,
CDAPPLI NUMBER(4,0) NOT NULL ENABLE,
NUCONTRA CHAR(15 BYTE) NOT NULL ENABLE,
DTDEBAS NUMBER(8,0) NOT NULL ENABLE,
DTFINAS NUMBER(8,0) NOT NULL ENABLE,
TAUXAS NUMBER(8,5) NOT NULL ENABLE,
CONSTRAINT PK_TTPERIODEAS
PRIMARY KEY (CDPARTITION, CDCOMPAGNIE, CDAPPLI, NUCONTRA, DTDEBAS)
)
PARTITION BY LIST(CDPARTITION)
(PARTITION P_PERIODEAS_13Q VALUES ('13Q'));
When running the job, I get the following message error and the table is not filled.:
The index 'USINODSD0.SYS_C00249007' its partition is unusable
Please I need help thanks
The index is global (i.e. not partitioned) because there is no using index local at the end of the definition. This is also true for the PK index shown above. (I'm assuming they are two different things, because by default the DDL above would create an index named PK_TTPERIODEAS, so I'm not sure what SYS_C00249007 is.) If you can drop and rebuild them as local indexes (i.e. partitioned to match the table) then truncating or dropping a partition will no longer invalidate indexes.
For example, you could rebuild the primary key as:
alter table ttperiodeas
drop primary key;
alter table ttperiodeas
add constraint pk_ttperiodeas primary key (cdpartition,cdcompagnie,cdappli,nucontra,dtdebas)
using index local;
I don't know how SYS_C00249007 is defined, but you could use something similar.
The create table command might be something like:
create table ttperiodeas
( cdpartition varchar2(5 byte) not null
, cdcompagnie number(4,0) not null
, cdappli number(4,0) not null
, nucontra varchar2(15 byte) not null
, dtdebas number(8,0) not null
, dtfinas number(8,0) not null
, tauxas number(8,5) not null
, constraint pk_ttperiodeas
primary key (cdpartition,cdcompagnie,cdappli,nucontra,dtdebas)
using index local
)
partition by list(cdpartition)
( partition p_periodeas_13q values ('13Q') );
Alternatively, you could add the update global indexes clause when dropping the partition:
alter table demo_temp drop partition p_periodeas_14q update global indexes;
(By the way, NUCONTRA should probably be a standard VARCHAR2 and not CHAR, which is intended for cross-platform compatibility and ANSI completeness, and in practice just wastes space and creates bugs.)
the message says that the index for the given partition is unusable: so you could try to rebuild the correponding index partition by the use of
create index [index_name] rebuild partition [partition_name]
(with the fitting values for [index_name] and [partition_nme].
Before you do that you should check the status of the index partitions in user_indexes - since your error message looks not like Oracle error messages usually do.
But since the index is global as William Robertson pointed out, this is not applicable for the given situation.

Error converting varchar to numeric (but there's no number)

I have a table with several columns, like this:
CREATE TABLE CRM.INFO_ADICIONAL
(
ID_INFO_ADICIONAL NUMBER(10) NOT NULL,
NOMBRE VARCHAR2(100 BYTE) NOT NULL,
OBLIGATORIO NUMBER(1) NOT NULL,
TIPO_DATO VARCHAR2(2 BYTE) NOT NULL,
ACTIVO NUMBER(1) NOT NULL,
ID_TIPO_REQUERIMIENTO NUMBER(10) NOT NULL,
ID_USUARIO_AUDIT NUMBER(10) NOT NULL,
ORDEN NUMBER(3) DEFAULT 1,
RECHAZO_POR_NO NUMBER(1),
ID_TIPO_ARCHIVO_ADJUNTO NUMBER(10),
SOLICITAR_EN VARCHAR2(30 BYTE),
ID_CONSULTA NUMBER(10),
COMBO_ID VARCHAR2(40 BYTE),
APLICAR_COMO_VENC NUMBER(1),
MODIFICABLE NUMBER(1) DEFAULT 0,
ID_AREA_GESTION NUMBER(10),
ID_TAREA NUMBER(10)
)
The "COMBO_ID" column is the target. It is defined as VARCHAR, but when I'm trying to insert a row, TOAD displays
"ORA-06502: PL/SQL: error : error de conversión de carácter a número
numérico o de valor"
Or a 'numeric conversion error', in english.
This table have some pre-existing data, and I even found some rows including values at COMBO_ID column, all of them being VARCHAR, i.e.:
NACION (Nation), SEXO (Sex), etc
I tried a few simple SELECT statements
SELECT
ID_INFO_ADICIONAL,
NOMBRE,
OBLIGATORIO,
TIPO_DATO,
ACTIVO,
ID_TIPO_REQUERIMIENTO,
ID_USUARIO_AUDIT,
ORDEN,
RECHAZO_POR_NO,
ID_TIPO_ARCHIVO_ADJUNTO,
SOLICITAR_EN,
COMBO_ID,
APLICAR_COMO_VENC,
ID_CONSULTA,
MODIFICABLE,
ID_AREA_GESTION,
ID_TAREA
INTO
pRegistro
FROM
crm.info_adicional
where pRegistro is declared as
pRegistro INFO_ADICIONAL%ROWTYPE;
Again, I'm still getting this 'numeric conversion error'.
But, wait, if I hardcode the SELECT value in COMBO_ID column with a NUMBER:
SELECT
--other columns
123456 COMBO_ID,
--other columns
INTO
pRegistro
FROM
crm.info_adicional
It works, what the heck, it's defined as VARCHAR.
If I do the same but harcoding a string, it fails to execute again
Already tried in my DEV environment, and it's working fine.
I'm not a pro in Oracle, but I feel pretty lost.
Could it be that tables get "confused"?
Any clues?
That error can also be raised if you try to push a character string that is longer than your VARCHAR2's capacity (40 in your case).
Try to check if all the data you are trying to insert is correct :
SELECT
COMBO_ID
FROM
crm.info_adicional
ORDER BY length(COMBO_ID) desc;
That would also explain why it works fine on your DEV environment which, I suppose, has different data.
Okay, I already found the answer.
Quoting Oracle Documentation:
The %ROWTYPE attribute provides a record type that represents a row in a table or view. Columns in a row and corresponding fields in a record have the same names and datatypes.
So, basically, the SELECT statement needed to be in the same order as the table columns definition.
In my case, I had a few columns (including COMBO_ID) in a different order.
Tried, re-ordering, and works like a charm.
Thank you all for the support.

Oracle index maximum key length exceeded

I get error ORA-01450: maximum key length (6398) exceeded as I try creating below index
CREATE INDEX FORENAME_SURNAME ON CARD_HOLDER( REGEXP_REPLACE (UPPER( FORENAME ),'\\s|-|_|\\.|\\:|\\,',''), REGEXP_REPLACE (UPPER( SURNAME ),'\\s|-|_|\\.|\\:|\\,','') );
Error code is fair clear but my columns are 100Bytes each so how is possible index exceed the max??
And db_block_size = 8192 not 6398.
Below columns definition
CREATE TABLE CARD_HOLDER
( "CARD_HOLDER_ID" NUMBER NOT NULL ENABLE,
"TITLE" VARCHAR2(10 BYTE),
"FORENAME" VARCHAR2(100 BYTE),
"SURNAME" VARCHAR2(100 BYTE) NOT NULL ENABLE,
)
You can try using this with concatenation instead of two different columns. However this is only a workaround and might not be useful unless you are using the query as such with concatenation.
CREATE INDEX forename_surname ON
card_holder ( regexp_replace(upper(forename),'\\s|-|_|\\.|\\:|\\,','')
|| regexp_replace(upper(surname),'\\s|-|_|\\.|\\:|\\,','') );
The length of 6398 is the maximal length of the index key in a 8KB block size tablespace as the block must contain the key plus some overhead.
Why are you getting the error for your 100 byte columns can be easily demonstrated.
Let's define a view with your additional columns
create view ch2 as
select c.*, REGEXP_REPLACE (UPPER( FORENAME ),'\\s|-|_|\\.|\\:|\\,','') for2,
REGEXP_REPLACE (UPPER( SURNAME ),'\\s|-|_|\\.|\\:|\\,','') sur2
from CARD_HOLDER c
If you check the data types of the new columns you see
select COLUMN_NAME, DATA_TYPE, DATA_LENGTH
from user_tab_columns where table_name = 'CH2' and column_name in ('FOR2','SUR2');
COLUMN_NAME, DATA_TYPE, DATA_LENGTH
FOR2 VARCHAR2 4000
SUR2 VARCHAR2 4000
Oracle expects the result of the regexp_replace could have the maximal length of 4000, which end in total of 8000.
So what to do?
Ask Tom has a nice overview of workarounding the problem with key length.
Among others solution you could define a tablespace with a larger block size for your index.
You may also step back and use TRANSLATE (or REPLACE) to remove the unwanted characters such as
TRANSLATE(upper(FORENAME),'x'||CHR(9)||CHR(10)||CHR(11)||CHR(12)||CHR(13)||' -_.:,','x')
Here Oracle asumes the result will be only 400 charater long so there will be no problem with the index key.

Why do I get an ORA-00922 when trying to create a partitioned table in Oracle?

I'm trying to create partitioned on oracle table but getting ORA-00922 error.
Error starting at line : 1 in command -
CREATE TABLE "RATE_REQUEST_BKP_PARIATIONED"
(
"RATE_REQUEST_ID" NUMBER(10,0),
"PRODUCT_CUSTOMER_ID" NUMBER(10,0),
"DESTINATION_ID" NUMBER(10,0),
"CREATED_DT" DATE,
"CREATED_BY" NUMBER(10,0),
"MODIFIED_DT" DATE,
"MODIFIED_BY" NUMBER(10,0),
"RATE_STATUS_ID" NUMBER(10,0)
)
PARTITION BY RANGE
(
CREATED_DT
)
INTERVAL
(
NUMTOYMINTERVAL(1, 'MONTH')
)
(
PARTITION p0 VALUES LESS THAN (TO_DATE('1-3-2017', 'DD-MM-YYYY')),
PARTITION p1 VALUES LESS THAN (TO_DATE('1-4-2017', 'DD-MM-YYYY')),
PARTITION p2 VALUES LESS THAN (TO_DATE('1-5-2017', 'DD-MM-YYYY'))
)
Error report -
SQL Error: ORA-00922: missing or invalid option
00922. 00000 - "missing or invalid option"
*Cause:
*Action:
Table "RATE_REQUEST_BKP_PARIATIONED" dropped.
Commit complete.
Please help me finding out the issue with query.
May this Help you
If an invalid option is specified while defining a storage clause or column, ORA-00922 will be thrown. ORA-00922 mentions that to specify that the column is not able to contain any NULL values, the valid option while specifying a column is NOT NULL, and solely constraints can follow the datatype.
Also notable to ORA-00922, which can also cause this error to be thrown, is that specifying a maximum length on LOG or DATE datatype.
Correcting ORA-00992 consists of correcting the syntax in your specifications, minding to take out the erroneous option or length specification from the storage of column specification
Answer got from this link
http://www.dba-oracle.com/t_ora_00922_missing_or_invalid_option.htm

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

Resources