Oracle 11g _ ORA-00904 error message with Insert statement - oracle

I created a simple table:
CREATE TABLE "ADVUPGRD"."GL_CAMPUSEMAILS"
("Campus" VARCHAR2(2 CHAR), "SEND_TO" VARCHAR2(60 CHAR), "SEND_CC"
VARCHAR2(250 CHAR), "SEND_BCC" VARCHAR2(60 CHAR))
The table got created, I can do select * from gl_campusemails and it gets me a blank row since I have not populated this table yet.
When I'm populating the table I'm using this:
INSERT INTO GL_CAMPUSEMAILS (Campus, Send_To, Send_CC, Send_BCC)
VALUES('CP', 'as#gmail.com', 'test#yahoo.com', 'test2#gmail.com');
but I got this error message:
Error starting at line : 8 in command -
INSERT INTO GL_CAMPUSEMAILS (Campus, Send_To, Send_CC, Send_BCC)
VALUES('CP', 'as#gmail.com', 'test#yahoo.com', 'test2#gmail.com')
Error at Command Line : 8 Column : 56
Error report -
SQL Error: ORA-00904: "SEND_BCC": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
I googled and found a lot of posting but they're mostly related to the use of reserved words in the select statement.
I don't think the columns I used in here belong to any reserved words.What did I do wrong in here

If you use double quotes while creating the table, the column names are created exactly as you typed, case sensitive; thus, you insert should be:
INSERT INTO GL_CAMPUSEMAILS(
"Campus",
"SEND_TO",
"SEND_CC",
"SEND_BCC"
)
VALUES (
'CP',
'as#gmail.com',
'test#yahoo.com',
'test2#gmail.com'
);
If you create the table with no quotes, this will work fine
CREATE TABLE GL_CAMPUSEMAILS
(
Campus VARCHAR2(2 CHAR),
SEND_TO VARCHAR2(60 CHAR),
SEND_CC VARCHAR2(250 CHAR),
SEND_BCC VARCHAR2(60 CHAR)
);
INSERT INTO GL_CAMPUSEMAILS(
Campus,
SEND_TO,
SEND_CC,
SEND_BCC
)
VALUES (
'CP',
'as#gmail.com',
'test#yahoo.com',
'test2#gmail.com'
);
Notice that not using double quotes, Oracle will consider all the objects with upper case names; so, for example, "CAMPUS", campus, CaMpUs will work, while "campus" will not

Related

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 database 11: select * from table fails

I have a weird issue. In one of the production DB servers we are trying to run
select * from SCHEMA_NAME.TABLE_NAME
When we run the query we are getting invalid identifier error. But when we select a particular column and run the same select query on the same table , we are able to get the output.
Please help me to understand the root cause.
Type created:
create or replace
TYPE "TEST_TYPE" is object
(
MULTIROW_ID VARCHAR2(100 CHAR),
LOSS_ENTRY_TYPE VARCHAR2(1000 CHAR),
SUB_CATEGORY VARCHAR2(1000 CHAR),
LOSS_AMOUNT NUMBER,
LOSS_ENTRY_CURR VARCHAR2(100 CHAR)
);
Type 2 created:
create or replace
TYPE "TEST_TYPE1" AS TABLE OF TEST_TYPE;
Main create table query using above table type columns:
CREATE TABLE "MS_TEST_DATA"
( "REGION" VARCHAR2(4000 CHAR),
"Entries" "TEST_TYPE1" ,
"ILE_DET_FUNCTION_OF_DISC_COM" VARCHAR2(4000 CHAR)
)
NESTED TABLE "Entries" STORE AS "TEST_TYPE3";
If I run this locally, I am able to access the table with select * query.
but in server I don't have all the accesses. There I have read-only access to tables. I can only run select * queries.
Avoid using double quotes in DDL scripts. If it is system generated, write a script to eliminate double quotes wherever possible.

oracle cannot insert values into a nested table field

I have the sample CUSTOMERS table.
I exported the values from table as INSERT script.
I took one row, modified the value from PK and re-executed the insert.
Insert into oe.customers (CUSTOMER_ID,
CUST_FIRST_NAME,
CUST_LAST_NAME,
CUST_ADDRESS,
PHONE_NUMBERS,
NLS_LANGUAGE,
NLS_TERRITORY,
CREDIT_LIMIT,
CUST_EMAIL,
ACCOUNT_MGR_ID,
CUST_GEO_LOCATION,
DATE_OF_BIRTH,
MARITAL_STATUS,
GENDER,
INCOME_LEVEL,
CREDIT_CARDS)
values ( oe.customer_seq.nextval,
'Donald',
'Hunter',
OE.CUST_ADDRESS_TYP('5122 Sinclair Ln','21206','Baltimore','MD','US'),
OE.PHONE_LIST_TYP('+1 410 123 4795'),
'us',
'AMERICA',
2600,
'Donald.Hunter#CHACHALACA.EXAMPLE.COM',
145,
MDSYS.SDO_GEOMETRY(2001,8307,MDSYS.SDO_POINT_TYPE(-76.545732,39.322775,NULL),NULL,NULL),
to_date('20-JAN-60','DD-MON-RR'),
'married',
'M',
'G: 130,000 - 149,999',
OE.TYP_CR_CARD_NST(OE.TYP_CR_CARD('Visa',100000000000011)));
and I have the following error message:
Error at Command Line : 32 Column : 29 Error report - SQL Error:
ORA-00904: : invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
which refers to line:
OE.TYP_CR_CARD_NST(OE.TYP_CR_CARD('Visa',100000000000011)));
The definition of types are:
create or replace type typ_cr_card as object
( card_type VARCHAR2(25)
, card_num NUMBER);
create or replace type typ_cr_card_nst as table of typ_cr_card;
Can someone tell me, please, what is wrong with this insert line as it is the one provided by SQL DEVELOPER?
NOTE: Also, I tried to use a procedure which inserts values in this table and the error refers to TYP_CR_CARD_NST datatype.

SQL 00904. 00000 - "%s: invalid identifier" When creating a table

When I create a table like this:
CREATE TABLE "Movie_list" (
"Movie_id" NUMBER(8) NOT NULL,
"Company" VARCHAR2(30) NOT NULL,
"Rating" DECIMAL(5,1) NOT NULL,
"Storyline" VARCHAR2(255) NOT NULL,
"Award_id" VARCHAR2(255) NOT NULL,
"Cast_and_Crew_id" VARCHAR2(255) NOT NULL,
CONSTRAINT Movie_pk PRIMARY KEY (Movie_id),
);
An Error report is producded -
SQL Error: ORA-00904: : invalid identifier
00904. 00000 - "%s: invalid identifier"
I don't see any problem, please help.
Errors:
Table and column names enclosed in quotes
NUMBER and VARCHAR2 are not a valid mysql type
A , is at the end of the constraint specification which is invalid
The main problem is in your primary key specification, which reads
CONSTRAINT Movie_pk PRIMARY KEY (Movie_id),
However, in the table definition you've quoted the name of this field, i.e.
"Movie_id" NUMBER(8) NOT NULL,
Because the name of this field (and in fact every field in the table, and the name of the table itself) is quoted the names are stored by the database as the specified mixed-case name, and because Oracle converts all unquoted identifiers to UPPER_CASE it means that EVERY TIME YOU REFER TO THIS TABLE AND ITS FIELDS, YOU MUST QUOTE THEM. So your constraint should be
CONSTRAINT Movie_pk PRIMARY KEY ("Movie_id")
My recommendation is that you dispense with the quoted "Mixed_case" names. Get rid of the quotes and Oracle will store the names in UPPER_CASE internally. You can still refer to them using Mixed_Case if you want to but you won't have to "Quote_Them_Every_Time_You_Use_Them", which gets really old and reads very badly. I suggest you change you table definition to
CREATE TABLE Movie_list (
Movie_id NUMBER(8) NOT NULL,
Company VARCHAR2(30) NOT NULL,
Rating DECIMAL(5,1) NOT NULL,
Storyline VARCHAR2(255) NOT NULL,
Award_id VARCHAR2(255) NOT NULL,
Cast_and_Crew_id VARCHAR2(255) NOT NULL,
CONSTRAINT Movie_pk PRIMARY KEY (Movie_id)
);
Best of luck.
This also happened to me when I was trying to use some sort of keyword as a column name.
I tried to create a table with a column name of "uid" (without "" evidently), and i was getting this error:
ORA-00904: : invalid identifier
00904. 00000 - "%s: invalid identifier"
Changing the column's name solved the error.

error while trying to select from external table

I am getting the below error while trying to select * from ext_poc
ORA-29913: error in executing ODCIEXTTABLEOPEN callout
ORA-29400: data cartridge error
KUP-00554: error encountered while parsing access parameters
KUP-01005: syntax error: found "identifier": expecting one of: "binary_double, binary_float, comma, char, date, defaultif, decimal, double, float, integer, (, no, nullif, oracle_date, oracle_number, position, raw, recnum, ), unsigned, varrawc, varchar, varraw, varcharc, zoned"
KUP-01008: the bad identifier was: varchar2
KUP-01007: at line 4 column 10
29913. 00000 - "error in executing %s callout"
*Cause: The execution of the specified callout caused an error.
*Action: Examine the error messages take appropriate action.
Below is the ddl for the table:
CREATE TABLE "JDASTG"."EXT_POC"
( "ID" varchar2(100),
"NAME" varchar2(100),
"DOB" varchar2(100)
)
ORGANIZATION EXTERNAL
( TYPE ORACLE_LOADER
DEFAULT DIRECTORY "SCPO_EXT_DATA"
ACCESS PARAMETERS
( RECORDS DELIMITED BY NEWLINE
FIELDS TERMINATED BY ','
MISSING FIELD VALUES ARE NULL
(id varchar2(100),
name varchar2(100),
dob varchar2(100)
)
)
LOCATION
( 'xyz_aldrin.csv'
)
);
PS:
This error however doesn't occur if the varchar2(100) is changed to char(100):
MISSING FIELD VALUES ARE NULL
(id char(100),
name char(100),
dob char(100)
)
It is important to distinguish between oracle internal data types specified on the table, and the external data types specified in the access parameters for the external table (control file for sqlldr). Read the manual again with that in mind. It should become clear. CHAR is allowed in SQL loader whereas VARCHAR2 is not

Resources