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 last published in September 2003

Dig Deeper on Oracle database design and architecture

PRO+

Content

Find more PRO+ content and other member only offers, here.

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.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close