External Table zum Einlesen von Dateien
1) Verzeichnis erzeugen:
DROP DIRECTORY data_dir;
CREATE DIRECTORY data_dir AS 'D:\oraclexe\ext_file'; -- Windows
CREATE DIRECTORY data_dir AS '/oraclexe/ext_file'; -- Unix
2) Rechte vergeben
GRANT READ, WRITE ON DIRECTORY data_dir TO usr;
3) Ext. Tabelle erstellen:
(Es werden nur die Metadaten angelegt!)CREATE TABLE kvdt_ext (
dateiname VARCHAR2 (1000 CHAR)
, zeile NUMBER
, feldlaenge NUMBER (3)
, feldkennung NUMBER (4)
, feldinhalt VARCHAR2 (1000 CHAR)
)
ORGANIZATION EXTERNAL
(
TYPE oracle_loader
DEFAULT DIRECTORY data_dir
ACCESS PARAMETERS (
RECORDS DELIMITED BY NEWLINE
FIELDS (
zeile RECNUM, --> Zeilen zählen
feldlaenge CHAR(3),
feldkennung CHAR(4),
feldinhalt CHAR(1000))
COLUMN transforms (
dateiname from constant 'Hallo' --> Konstanten definieren
)
)
location ('Dateiname.Endung')
)
reject LIMIT unlimited;
4) Test, ob's auch klappt:
SELECT *
FROM kvdt_ext
WHERE ROWNUM < 11;
=> erst hier treten Fehler auf!
Weitere Möglichkeiten:
- Name der einzulesenden Datei ändern:
ALTER TABLE admin_ext_employees LOCATION ('empxt3.txt','empxt4.txt');
Quellen:
- Oracle Doku
- http://jiri.wordpress.com/2010/03/29/oracle-external-tables-by-examples-part-4-column_transforms-clause-load-clob-blob-or-any-constant-using-external-tables/
Good post however I was wondering if you could write a
AntwortenLöschenlitte more on this subject? I'd be very thankful if you could elaborate a little bit more. Many thanks!
Feel free to surf to my site; An X-RayTechnician
Wow that was stгange. I just wrote an ѵery long сomment but after I clicked submit mу comment didn't show up. Grrrr... well I'm not wгiting all that oveг agaіn.
AntwortenLöschenAnyωays, јust wаnted to sаy grеаt blog!
My webраge how To become a ultrasound tech