Solved

Oracle Sql Loader / PLSQL Data Validation

Posted on 2014-03-26
6
1,496 Views
Last Modified: 2014-03-26
I receive a pipe delimited file that I load using SQL Loader. I have been asked to verify the pipe count in the file as a means to validate that all columns are accounted for.

Example: The file should be
col1|col2|col3|col4|col5

If I get a file like this
col1|col2|col3
it should not accept the file.

The pipe count should be five not two for each row.

My questions is two fold:

1. Will SQL Loader bomb on a file that does not have all of the columns defined, I'm receiving a variable length file.

2. Is there a way to do this with a stored procedure and can you give me ideas? I'm thinking of using UTL_File or should I load file in one big column and count the | in each row. Usually these files are large and I'm not sure about an approach.

Thanks.
0
Comment
Question by:SharonBernal
6 Comments
 
LVL 32

Expert Comment

by:awking00
ID: 39956285
On what kind of file system do these files reside (e.g. Windows, Unix, etc.)?
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 39956310
on a windows server use this scripts
and providing the records are 1 line based

findstr /V /N ".*|.*|.*|.*|.*" c:\data\your_input_file.txt > incorrect_lines.txt

Open in new window


it should give a list of the incorrect lines preceded by a line number
doing a line count on the file gives the count
0
 

Author Comment

by:SharonBernal
ID: 39956317
It's a Unix system.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 39956329
don't have unix but i'm guessing grep can do that
0
 
LVL 34

Accepted Solution

by:
johnsone earned 500 total points
ID: 39956652
What behavior are you looking for?  Should SQL*Loader ignore the records that are missing columns, or should the whole file be ignored?

If you are looking to just ignore the records that are missing columns, then as long as you do not specify TRAILING NULLCOLS in the control file, you should be OK.  See the documentation here -> http://docs.oracle.com/cd/E16655_01/server.121/e17639/ldr_control_file.htm#SUTIL1121

If you want to ignore the whole file, then you be sure that you do not set TRAILING NULLCOLS and make sure that you also set ERRORS=0.  That should cause the load to terminate on the first error.
0
 

Author Closing Comment

by:SharonBernal
ID: 39956743
Or business rule would be to ignore the entire file. This is what I needed to know. Thank you.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question