Search notes:

Oracle: SQL Loader example: explicitly declare a column's width in the control file in order to prevent the *Field in data file exceeds maximum length* error message

This example explicity declares a column's width in the control file in order to prevent the Field in data file exceeds maximum length error message.

Create table statement

create table tq84_sql_loader_6 (
   id    number not null,
   tx    varchar2(4000)
);

create table tq84_sql_loader_6_ok (
   id    number not null,
   tx    varchar2(4000)
);
Github repository Oracle-Patterns, path: /SQLLoader/ex_06/create_table.sql

Control file without explicit declaration of field with

This control file will produce an error message
load data
into table tq84_sql_loader_6
fields terminated by "|"
(
  id,
  tx
)
Github repository Oracle-Patterns, path: /SQLLoader/ex_06/load_6.ctl

»Correct« control file

This control file declares the width of a column and thus prevents the error message.
load data
into table tq84_sql_loader_6_ok
fields terminated by "|"
(
  id,
  tx char(4000)
)
Github repository Oracle-Patterns, path: /SQLLoader/ex_06/load_6_ok.ctl

The data file

1|This line should be fine
2|This line contains more than 255 characters and will cause an "Field in data file exceeds maximum length" error message. Of course, I need some more text here in order to reach this 255 character limit. For example, by adding some city names: New York, Los Angeles, Berlin, Berne, Lucerne, Winterthur, Basle, Paris, Tokyo, Cape Town etc.
3|This line should be fine, too
Github repository Oracle-Patterns, path: /SQLLoader/ex_06/load_6.dat

Running it all

start create_table

host  sqlldr control=load_6.ctl    data=load_6.dat userid=rene
host  sqlldr control=load_6_ok.ctl data=load_6.dat userid=rene

select id, substrb(tx,1, 50) from tq84_sql_loader_6;

prompt
prompt  Note: Second record not loaded
prompt

drop table tq84_sql_loader_6    purge;

select id, substrb(tx,1, 50) from tq84_sql_loader_6_ok;
prompt
prompt  Note: Second record was loaded
prompt

drop table tq84_sql_loader_6_ok purge;
Github repository Oracle-Patterns, path: /SQLLoader/ex_06/all.sql

See also

Other SQL Loader examples
SQL*Loader

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758207107, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/Oracle/tools/sql-loader/example-06(120): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78