Sql Loader error "Token longer than max allowable length of 258 chars" - sql-loader

I am getting the below error on loading the data to a table using SQL Loader.
SQL*Loader-350: Syntax error at line 21.
Token longer than max allowable length of 258 chars
')
^
The control file is as below:
OPTIONS (SKIP = 1)
LOAD DATA
APPEND
PRESERVE BLANKS
INTO TABLE "INTL"
FIELDS TERMINATED BY '|'
TRAILING NULLCOLS
(
CO_BDI_INTERLOCUTOR CHAR(15),
NU_DOCUMENTO CHAR(17),
CO_TRATAMIENTO CHAR(1) "NVL(:CO_TRATAMIENTO,' ')",
DS_NOMBRE CHAR(50),
DS_APELLIDO_1 CHAR(50),
DS_APELLIDO_2 CHAR(50),
CO_CARGO CHAR(2) "NVL(:CO_CARGO,' ')",
DS_COMENTARIO CHAR(255) "NVL(:DS_COMENTARIO,' ')",
DS_ARE_FUN_ITL_GRC CHAR(100),
FX_INI_VIGENCIA CHAR(10),
FX_FIN_VIGENCIA CHAR(10) "NVL(:FX_FIN_VIGENCIA,' ')",
CO_CUC_CLIENTE CHAR(8),
CO_CUC_CABECERA CHAR(8),
CO_HITO CHAR(8),
DS_SIS_ORIGEN CHAR(4),
CO_INTERLOCUTOR CHAR(15),
CO_TIPO_DOC CHAR(1),
CO_IDIOMA CHAR(3)
)
The problem seems to be with the field "DS_COMENTARIO" since I am replacing the data with spaces of length 255 if the field is NULL.
I have a similar problem with other table and Control file also.
Could you please help me with this?
Thanks,
Savitha

Try
DS_COMENTARIO CHAR(255) "NVL(:DS_COMENTARIO,LPAD(' ', 255, ' ')",
It basically pads a 1 Character string out to 255 characters.

Related

How to handle null from a text file in Mysql if the data type is Char(1)?

This is my first time trying Mysql. I created a table using the following command.
CREATE TABLE IF NOT EXISTS `COMPANY`.`EMPLOYEE` (
`Fname` VARCHAR(15) NOT NULL,
`Minit` CHAR NULL,
`Lname` VARCHAR(15) NOT NULL,
`Ssn` CHAR(9) NOT NULL,
`Bdate` DATE NULL,
`Address` VARCHAR(30) NULL,
`Sex` CHAR NULL,
`Salary` DECIMAL(10,2),
`Super_ssn` CHAR(9) NULL,
`Dno` INT NOT NULL,
PRIMARY KEY (`Ssn`));
And I was trying to fill the table using the command below:
LOAD DATA
INFILE 'C:\\ProgramData\\MySQL\\MySQL Server 8.0\\Uploads\\EMPLOYEE.txt'
INTO TABLE employee
FIELDS TERMINATED BY ', '
OPTIONALLY ENCLOSED BY ''''
LINES TERMINATED BY '\n'
(Fname,Minit,Lname,Ssn,#var2,Address,Sex,Salary,Super_ssn,Dno)
SET Bdate=str_to_date(#var2,'%d-%b-%Y');
And this is my text file
'James', 'E', 'Borg', '888665555', '10-NOV-1927', '450 Stone,Houston,TX', 'M', 55000, null, 1
'Franklin',null, 'Wong', '333445555', '08-DEC-1945', '638 Voss,Houston,TX', 'M', 40000, '888665555', 5
I am getting an error saying:
Error Code: 1406. Data too long for column 'Minit' at row 2
How do I solve this?
The problem is that you used optionally in the enclosed by setting. If the enclosing character is required, it will treat null with no quotes around it as a NULL value. Otherwise, it interprets it as the literal string "null", and requires you to use \N to specify a null value.
You could use an intermediate variable to translate it yourself.
LOAD DATA
INFILE 'C:\\ProgramData\\MySQL\\MySQL Server 8.0\\Uploads\\EMPLOYEE.txt'
INTO TABLE employee
FIELDS TERMINATED BY ', '
OPTIONALLY ENCLOSED BY ''''
LINES TERMINATED BY '\n'
(Fname,#Minit,Lname,Ssn,#var2,Address,Sex,Salary,Super_ssn,Dno)
SET Bdate=str_to_date(#var2,'%d-%b-%Y'), Minit = NULLIF(#Minit, 'null')

mysql ERROR 1064 (42000) at line 3: you have an error in your SQL syntax

I keep getting the following error.
ERROR 1064 (42000) at line 3: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the
right syntax to use near '
Species_ID int,
Genus varchar,
Species varchar,
Common_Name varchar,
Indiv' at line 9
hbm248#i6[datasets]$
Here is the full SQL script:
DROP TABLE IF EXISTS paplants;
CREATE TABLE paplants (
ID int NOT NULL AUTO_INCREMENT,
Observation_ID int NOT NULL,
Update_Datetime int NOT NULL,
Site_ID int NOT NULL,
Latitude decimal NOT NULL,
Longitude decimal NOT NULL,
Elevation_in_Meters int,
`State` varchar,
Species_ID int,
Genus varchar,
Species varchar,
Common_Name varchar,
Individual_ID int,
Phenophase_ID int,
Phenophase_Description varchar,
Observation_Date date,
Day_of_Year int,
Phenophase_Status int,
PRIMARY KEY(ID)
);
LOAD DATA LOCAL INFILE "observation_data.csv"
INTO TABLE paplants
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
(ID, Observation_ID, Update_Datetime, Site_ID, Latitude, Longitude, Elevation_in_Meters, `State`, Species_ID, Genus, Species, Common_Name, Individual_ID, Phenophase_ID, Phenophase_Description, Observation_Date, Day_of_Year, Phenophase_Status);
Any help would be really appreciated!
You need to specify a length to your varchar fields. ie: varchar(10) for a varchar field of maximum length 10.

What is difference between char and varchar

CREATE TABLE IF NOT EXISTS `test` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`country` varchar(5) NOT NULL,
`state` char(5) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
I tried following query to insert data
INSERT INTO `test`.`test` (`id` ,`country` ,`state`)
VALUES (NULL , 'south-india', 'Gujarat');
When I execute above query It will shows following warning
Warning: #1265 Data truncated for column 'country' at row 1
Warning: #1265 Data truncated for column 'state' at row 1
I found Reference that VARCHAR is variable-length.CHAR is fixed length.
Then what you mean by
VARCHAR is variable-length.
CHAR is fixed length.
VARCHAR(5) will use at most 5 characters of storage, while CHAR(5) will always use exactly 5.
For a field holding a person's name, for example, you'd want to use a VARCHAR, because while on average someone's name is usually short, you still want to cope with the few people with very long names, without having to have that space wasted for the majority of your database rows.
As you said varchar is variable-length and char is fixed. But the main difference is the byte it uses.
Example.
column: username
type: char(10)
if you have data on column username which is 'test', it will use 10 bytes. and it will have space.
'test______'
Hence the varchar column will only uses the byte you use. for 'test' it will only use 4 bytes. and your data will be
'test'
THanks.
As you mentioned VARCHAR is variable-length. CHAR is fixed length.
when you say
Varchar(5) and if the data you store in it is of length 1, The
remaining 4 byte memory space will be used by others. example: "t"
on the other hand
Char(5) and if the data you store in it is of length 1, The remaining
4 byte memory space cant be used. The 4 byte will end up not used by
any other data. example: "t____" here ____ is the unused space.

error 10064 mysql 4200 while trying to create table

CREATE TABLE DIAMOND(
RAPNETSELLERCODE VARCHAR(30) ,
SHAPE VARCHAR(15) ,
WEIGHT INT(5) ,
COLOR VARCHAR(3) ,
CLARITY VARCHAR(6) ,
CUTGRADE VARCHAR(10),
POLISH VARCHAR(13),
SYMMENTRY VARCHAR(10),
FLUORESCE VARCHAR(10),
MEASUREMENTS INT(100),
MEASLENGTH INT(30),
MEASWIDTH INT(30),
MEASDEPTH INT(30),
RATIO INT(12),
LAB VARCHAR(10),
ID INT(15),
STOCK# VARCHAR(14),
RAPNETPRICE INT(15),
RAPNETDISCOUNTPRICE INT(15),
RAPTOTALPRICE INT(16),
DEPTH % INT(12),
TABLE % INT(10),
GIRDLE VARCHAR(10),
CULET VARCHAR(10),
CERTIFICATEURL VARCHAR(300),
RAPNETLOT # INT(38);
ERROR:ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near ')
CREATE TABLE DIAMOND(
RAPNETSELLERCODE VARCHAR(30) ,
SHAPE VARCHAR(15) ,' at line 1
Evidently there is more to the query than what you are showing us. Seems like you have something like
CREATE TABLE PLATINUM (
/* fields */
)
CREATE TABLE DIAMOND (
You need a semicolon after the ) before CREATE TABLE DIAMOND.
You have other errors in this CREATE TABLE statement as well.
STOCK # -- invalid syntax
`STOCK #` -- desired syntax
Same is true of DEPTH %, TABLE %, and RAPNETLOT #
Finally, you are missing the closing paren for the entire CREATE TABLE statement.
Several things I can see: you have a % symbol in 2 lines of code, you have a # symbol in 2 lines of code, you have DEPTH and TABLE as column names although they are keywords, and you never closed your parenthesis inside the semicolon. At least one of these things is causing the error message. Start with the ) you are missing.

How to give the long name as a field of the table?

How can I give the long text as a table field name in mysql?
Here is what I tried:
CREATE TABLE IF NOT EXISTS surveyForm_8(
surveyForm_8_id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(surveyForm_8_id),
survey_form_id VARCHAR(255),
submitted_by VARCHAR(15),
submitted_on TIMESTAMP,
'How_to_change_the_way_of_road?' VARCHAR(255)
)
But I got this error:
#1059 error
Try this one, you should use the ` symbol for column names
CREATE TABLE IF NOT EXISTS surveyForm_8(surveyForm_8_id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(surveyForm_8_id), survey_form_id varchar(255) ,submitted_by varchar(15),
submitted_on timestamp, `How_to_change_the_way_of_road?` varchar(255));
Please see http://dev.mysql.com/doc/refman/5.5/en/identifiers.html for valid table and field names.
Basically, double quotes only work in ANSI_QUOTES mode. The default is to use `backticks` to quote. Also, the maximum length of table / field names is 64 characters.