SQL Loader - Invalid Number - sql

I'm trying to load data via SQLoader, but it gives me error at the numeric field of Invalid Number
My Data File:
00163604~12002~S~N~N~Panasonic Juicer 1.5l Steel Color~ss~E~A~12/15/2014 3:33:57 PM~N~N~N~Y~294~SA
Control File:
LOAD DATA
INFILE "/home/dmf/ITEMLOC.txt"
APPEND
INTO TABLE DMF.MIG_ITEM_LC
FIELDS TERMINATED BY "~"
TRAILING NULLCOLS
(
ITEM "SUBSTRB(:ITEM,1,25)",
LOC "TO_NUMBER(:LOC)",
LOC_TYPE "SUBSTRB(:LOC_TYPE,1,1)",
CLEAR_IND "SUBSTRB(:CLEAR_IND,1,1)",
TAXABLE_IND "SUBSTRB(:TAXABLE_IND,1,1)",
LOCAL_ITEM_DESC "SUBSTRB(:LOCAL_ITEM_DESC,1,250)",
LOCAL_SHORT_DESC "SUBSTRB(:LOCAL_SHORT_DESC,1,120)",
STORE_ORD_MULT "SUBSTRB(:STORE_ORD_MULT,1,1)",
STATUS_UPDATE_DATE sysdate,
STATUS "SUBSTRB(:STATUS,1,1)",
STORE_PRICE_IND "SUBSTRB(:STORE_PRICE_IND,1,1)",
RPM_IND "SUBSTRB(:RPM_IND,1,1)",
EXT_UIN_IND "SUBSTRB(:EXT_UIN_IND,1,1)",
RANGED_IND "SUBSTRB(:RANGED_IND,1,1)",
PRIMARY_SUPP "TO_NUMBER(:PRIMARY_SUPP)", -- The Error is coming here
PRIMARY_CNTRY "SUBSTRB(:PRIMARY_CNTRY,1,3)"
)
Rejected - Error on table DMF.MIG_ITEM_LC, column PRIMARY_SUPP.
ORA-01722: invalid number
If i write give constant to it, it loads successfully.
What could be the issue?

Your data as posted loads fine for me.
SQL> select version from v$instance;
VERSION
-----------------
11.2.0.2.0
Here's the create table statement I used:
create table test1
(
item varchar2(25),
loc number,
loc_type char(1),
clear_ind char(1),
taxable_ind char(1),
local_item_desc varchar2(250),
local_short_desc varchar2(120),
store_ord_mult char(1),
status char(1),
store_price_ind char(1),
rpm_ind char(1),
ext_uin_ind char(1),
ranged_ind char(1),
primary_supp number,
primary_cntry varchar2(3)
);
If you get this error while trying to load only the one record that you posted, then I would suspect an unprintable character, like #Gary_W suggested. View the data with a hex viewer to check.
A character set difference between the file and your NLS_LANG setting could be at fault, but I doubt it in this case, since your data looks to be all ASCII values.

Related

Why am I getting this error while trying to insert data ORA-00904 "PBIRTHDATE"

Can somebody correct me if I'm doing any syntax mistake while inserting into a table with complex data type?
This is my code:
CREATE TYPE ADDR AS OBJECT (
street VARCHAR2(32),
city VARCHAR2(32),
zip NUMBER(32)
);
CREATE TYPE NAMES AS OBJECT(
firstname VARCHAR2(64),
lastname VARCHAR2(64)
);
CREATE TABLE PERSON(
pid NUMBER(10),
pname NAMES,
paddr ADDR,
pbirthdate DATE
);
INSERT INTO PERSON
VALUES (1, pname('John','Doe'), paddr('None','Test',51050), TO_DATE('33445555', 'MMDDYYY'));
When you initialize an instance of an object type, you need to specify the type name, not the column name. You should also always specify the target columns in an INSERT statement.
INSERT INTO PERSON
(pid, pname, paddr, pbirthdate)
VALUES
(1, names('John','Doe'), addr('None','Test',51050), TO_DATE('33445555', 'MMDDYYY'));
^ ^
| here | here
Additionally, 33445555 is an invalid date given the format mask MMDDYYY'
The error message clearly points to this:
TO_DATE('33445555', 'MMDDYYY')
When I try to use this in a query while testing locally, I get this error message:
ORA-01843: not a valid month
The date you specified is not valid, because there is no 33rd month. Try using a valid date, and the error should go away:
TO_DATE('06242019', 'MMDDYYYY')
There is issue in TYPE usage and date:
INSERT INTO PERSON
VALUES (1, NAMES('John','Doe'), ADDR('None','Test',51050), TO_DATE('06242019', 'MMDDYYYY'));
Db Fiddle Demo
Cheers!!

ORA-29913: error in executing ODCIEXTTABLEOPEN callout

I am creating external table using hr schema but i get errors
"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 "missing": expecting one of:
"column, (" KUP-01007: at line 4 column 3
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."
----------------My Code-------------------
create directory ex_tab as 'C:\My Works\External Table';
create table strecords (
st_id number(4),
st_name varchar(10),
schl_name varchar(5),
st_city varchar(15),
st_year number(4)
)
ORGANIZATION EXTERNAL
(TYPE oracle_loader
DEFAULT DIRECTORY ex_tab
ACCESS PARAMETERS
(
RECORDS DELIMITED BY newline
FIELDS TERMINATED BY ','
REJECT ROWS WITH ALL NULL FIELDS
MISSING FIELDS VALUES ARE NULL
(
st_id number(4),
st_name char(10),
schl_name char(5),
st_city char(15),
st_year number(4)
)
)
LOCATION ('strecords.txt')
);
desc strecords;
select * from strecords;
This is my code, please check it and review it.
You have several issues here. The immediate one causing your problem is that you have the clauses in the wrong order, but you also have MISSING FIELDS instead of MISSING FIELD:
...
ACCESS PARAMETERS
(
RECORDS DELIMITED BY newline
FIELDS TERMINATED BY ','
MISSING FIELD VALUES ARE NULL
REJECT ROWS WITH ALL NULL FIELDS
(
...
Then your field list contents have invalid data types for that part of the statement; you can just omit that entirely in this case as those match the table column definition.
If no field list is specified, then the fields in the data file are assumed to be in the same order as the fields in the external table.
So you can simplify it to:
create table strecords (
st_id number(4),
st_name varchar(10),
schl_name varchar(5),
st_city varchar(15),
st_year number(4)
)
ORGANIZATION EXTERNAL
(TYPE oracle_loader
DEFAULT DIRECTORY ex_tab
ACCESS PARAMETERS
(
RECORDS DELIMITED BY newline
FIELDS TERMINATED BY ','
MISSING FIELD VALUES ARE NULL
REJECT ROWS WITH ALL NULL FIELDS
)
LOCATION ('strecords.txt')
);
Some operations needed against an Oracle Bug called
Select From External Table Returns Errors ORA-29913 ORA-29400 KUP-554 KUP-1005 (Doc ID 302672.1)
When creating an external table, the access parameters should be specified in the following order:
Comments
Record Format Info
Field definitions
Specify Comments, Record Format Info and Field definitions in the correct order. Even inside the Record format Info, 'Records delimited by ...' clause should come before any other clause.
For more information, refer to the access_parameters clause.

Bulk inserting data gives error

Attempting to bulk insert into a table and I am getting the error:
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 31, column 4 (Birthday).
Below is the code I am trying to use to insert the data:
Bulk Insert Dzt.dbo.Player
From 'A:\New Folder\Seed_Files\Player.csv'
With
(
FieldTerminator=',',
RowTerminator='\n',
FirstRow=2
)
Here is the code I used when making the table:
Use Dzt
Create Table Player
(
Player_ID int,
FirstName varchar(255),
LastName varchar(255),
Birthday date,
Email varchar(255),
L_Flag varchar(255)
);
This is my first attempt at making a table and inserting data so I am thinking it is likely a datatype error for the Birthday field but I have been unable to find anything online that I am able to grasp my head on at this time. I have also tried use the datatype datetime instead of date but I received the same error.
I am using SSMS 2012 to create and insert the data onto a 2012 SQL Server.
Let me know if there is anything else I can provide that might help.
As you suspect it could be a date format error, I would suggest importing the csv into a table with Birthday column set to varchar type. Then use this query to filter the erroneous records.
select birthday from temptable where isdate(birthday) = 0
You could then correct those records and then insert them into your old table.

import csv file to oracle database

I am trying to import data from txt file to table. The TXT file is having 5 records.
'ext.txt' is my file .'IMPORT' is a directory.
Records are
7499,ALLEN,SALESMAN,30
7521,WARD,SALESMAN,30
7566,JONES,MANAGER,20
7654,MARTIN,SALESMAN,30
I tried below query but its only inserts 3rd record to the external table.
Can anyone provide me the reason for this ans solution for insert all rows.
create table ext_tab (
empno CHAR(4),
ename CHAR(20),
job1 CHAR(20),
deptno CHAR(2)
)
ORGANIZATION EXTERNAL (
TYPE ORACLE_LOADER
DEFAULT DIRECTORY IMPORT
ACCESS PARAMETERS (
RECORDS DELIMITED BY NEWLINE
BADFILE IMPORT:'test.bad'
LOGFILE IMPORT:'test.log'
FIELDS TERMINATED BY ',' (
empno char(4) ,
ename char(4),
job1 CHAR(20),
deptno CHAR(2)
)
)
LOCATION (import:'ext.txt')
)
PARALLEL 5
REJECT LIMIT UNLIMITED;
This will work for your given test data
CREATE TABLE ext_tab (
empno VARCHAR(4),
ename VARCHAR(20),
job1 VARCHAR(20),
deptno VARCHAR(2)
)
ORGANIZATION EXTERNAL (
DEFAULT DIRECTORY import
ACCESS PARAMETERS (
RECORDS DELIMITED BY NEWLINE
FIELDS TERMINATED BY ','
)
LOCATION ('ext.txt')
);
providing that you have set up the import directory correctly.
Tested on 11.2.0.4
As for the reason it was given in the comments above. Always check the .bad and .log files first (created in the directory you put the file in). These are very helpful at telling you why rows are rejected.
I expect you have errors like this in the log:-
KUP-04021: field formatting error for field ENAME
KUP-04026: field too long for datatype
KUP-04101: record 1 rejected in file /import_dir/ext.txt
KUP-04021: field formatting error for field ENAME
KUP-04026: field too long for datatype
KUP-04101: record 3 rejected in file /import_dir/ext.txt
KUP-04021: field formatting error for field ENAME
KUP-04026: field too long for datatype
KUP-04101: record 4 rejected in file /import_dir/ext.txt
and that only WARD was imported because only his name fits into CHAR(4).

Commit point reached

Hi I'm trying to load some data in to an Oracle Table I created
Here's the table I created in Vivek schema
Desc STAR
Name NULL TYPE
-----------------------------------------------------
STAR_ID Not Null Number(4)
FIRST_NAME Varchar2(30)
LAST_NAME Varchar2(30)
DOB Date
SEX Char(1)
Nationality Varchar2(40)
Alive Char(1)
Following is the data in the STAR5.CSV file I am trying to upload using SQL Loader
10,NASEERUDDIN,SHAH,M,INDIAN,Y
11,DIMPLE,KAPADIA,F,INDIAN,Y
The control file is as follows
load data
infile '/home/oracle/host/Vivek12/STAR_DATA5.csv'
append
into table vivek.STAR
fields terminated by ","
( STAR_ID,FIRST_NAME,LAST_NAME,SEX,NATIONALITY,ALIVE )
When I run the SQL Loader with the following command
$ sqlldr vivek/password
control = /home/oracle/sqlldr_add_new.ct1
I get the message:
Commit point reached - logical record count 2
However the data is not loaded and the are put in the file STAR5.bad
Any idea why the data isn't getting loaded?
You most likely have either an "invisible" character at the end of your line. Perhaps you're executing this on Linux and the file was created on Windows so you've got an extra carriage return - Linux only uses line-feed as the line terminator.
Change your ctl file to remove terminating whitespace:
load data
infile '/home/oracle/host/Vivek12/STAR_DATA5.csv'
append
into table vivek.STAR
fields terminated by ","
( STAR_ID
, FIRST_NAME
, LAST_NAME
, SEX
, NATIONALITY
, ALIVE terminated by whitespace
)
If this doesn't work, then you're going to need to work out what characters are there and replace them.