Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

External table -> fetch location ?

Sven W.May 26 2011 — edited Jun 1 2011
Using Oracle 10.2.0.5

An external table is a construct that gives me SQL access to a file.

Is it possible to know the name of the file somehow inside the select? Like Add a column with the file name?

pseudo example
CREATE TABLE EXT_DUMMY
(
    "RECORDTYPE" VARCHAR2(100 BYTE), 
    "COL1" VARCHAR2(100 BYTE), 
    "COL2" VARCHAR2(100 BYTE), 
    "FILE" VARCHAR2(100 BYTE) 
)
ORGANIZATION EXTERNAL
(
    TYPE ORACLE_LOADER DEFAULT DIRECTORY "IMPORT_BAD_FILE" 
    ACCESS PARAMETERS ( 
             records delimited BY newline 
             FIELDS TERMINATED BY ';' 
             MISSING FIELD VALUES ARE NULL 
               ( RECORDTYPE CHAR
               , COL1 CHAR 
               , COL2 CHAR 
               , FILE CHAR FILLER
               ) 
               ) 
    LOCATION ( 'Testfile1.txt, Testfile2.txt' )
)
    reject limit 10
;
The result could look like this:
RECORDTYPE   COL1       COL2      FILE
SAMPLE           DUMMY    DUMMY Testfile1.txt
SAMPLE           DUMMY1   DUMMY Testfile1.txt
SAMPLE           DUMMY2   DUMMY Testfile1.txt
SAMPLE           DUMMY3   DUMMY Testfile1.txt
SAMPLE           DUMMY1   DUMMY1 Testfile2.txt
SAMPLE           DUMMY1   DUMMY2 Testfile2.txt
SAMPLE           DUMMY2   DUMMY1 Testfile2.txt
I would like to know from which file a certain row is read. Maybe I missed an option in the documentation. In this example I have two different files as the source for the external table.

Another use case could be this:
If I enable a user to switch the external table to a different file
alter table EXT_DUMMY location ('Testfile3.txt' )
. How can we know which file is read during the select on the table? When userA does the select, maybe userB just altered the location before the select was started. Therefore userA would read in a different file then expected.

Edited by: Sven W. on May 26, 2011 4:48 PM

Edited by: Sven W. on May 26, 2011 4:51 PM

Edited by: Sven W. on May 26, 2011 5:11 PM
This post has been answered by odie_63 on May 28 2011
Jump to Answer

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jun 29 2011
Added on May 26 2011
13 comments
4,487 views