Everyday I receive a big interface file and I'm loading all the rows, but I'm only using the most recent information, (much less rows). Can I filter by the .ctl file so as to insert only the newest rows?
This is my ctl file:
LOAD DATA
INSERT INTO TABLE SCHEMA.TBL_INTERFACE
(
"ID" POSITION(001:008), --varchar2(08),
"FIRSTNAME" POSITION(009:028), --varchar2(20),
"LASTNAME" POSITION(029:048), --varchar2(20),
"DATE" POSITION(049:058), --varchar2(10) FORMAT YYYYMMDD 20211029
)
This is a sample of the interface I load:
12345678JUAN CARLOS0 PEREZ0 20211029
23456789JUAN CARLOS1 PEREZ1 20201029
34567890JUAN CARLOS2 PEREZ2 20181029
45678901JUAN CARLOS3 PEREZ3 20171029
How about external tables feature? Its benefit is that you can write queries against it (and simply filter rows you're interested in). Drawback? You have to have access to database server; no problem - from my point of view, though; it's just that you can't run everything locally.
Here's a walkthrough:
As that feature requires access to directory (Oracle object that points to a filesystem directory), we'll have to create it first, connected as
SYS:Connect as
scott(use which will be working on that problem):Target table (I refuse to use reserved word -
DATE- for column name. That's a bad practice, I suggest you avoid it):Data is stored in
C:\TEMP\TEXT.TXTfile; note that I'm running Oracle on my laptop which - therefore - acts as if it was a database server. If your database server isn't on your PC, you'll have to talk to DBA.Just setting date format (you don't have to do that):
Let's, finally, create external table:
Is there anything there?
Yes, there is - all rows from
text.txt.As we're using SQL, no problem in applying any filter to data, such as the one you wanted - to get the most recent data (today's):
Obviously, now it is a simple matter of inserting desired values into the target table: