Q

Picking the first 25 characters in SQL

The column in database is a varchar(25). But sometimes my datafile has data for this column exceeding 25. I want

the SQLloader to take the first 25 characters and load them into the database. I am using a control file, variable-length delimited by |, so I can not mention positions for all the fields, this field represents 40th column in database (total 50 columns). Is there any way to specify to pick the first 25 characters? Yes. You can do this. The way to accomplish this task is to apply an SQL operator to your field. To use just the first 25 characters, you will want to use the SUBSTR function on the input data. Something similar to the following can help:


LOAD DATA 
INFILE * 
APPEND INTO TABLE XXX 
( LAST    position(1:7)     char   "UPPER(:LAST)" 
  FIRST   position(8:45)    char  
"SUBSTR(:FIRST,1,25)" 
) 

The above is just a portion of what you control file might look like. I've foced the data that will go into the LAST column to be all upper case and I've forced the data to be placed into the FIRST column to be just the first 25 characters of the data.

This was first published in September 2003

Dig deeper on Oracle database design and architecture

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close