问题描述
我有一张桌子,里面有大约800万行。它在名为Customer_Identifier的列上具有唯一性约束。这是一个varchar(10)字段,不是主键,而是唯一的。
我希望使用sql Developer从该表中检索一些客户行。我得到了一个文本文件,每个记录在第1-10列中包含一个搜索关键字值。此查询将需要使用不同的customer_identifier值重用几次。有时会给我一些customer_identifier值(其中
我仅具有数据库的读取权限,因此创建和管理新的物理表是不可能的:-(。
有没有一种方法可以将文本文件视为Oracle 12.1中的表,然后使用该文件将其连接到customer_identifier列上的客户表?
兄弟 克里斯
解决方法
是的,您可以将文本文件视为外部表。但是,如果您无权访问数据库中定义的目录,则可能需要DBA帮助来创建新目录。
**Create a directory object pointing to the location of the files.**
CREATE OR REPLACE DIRECTORY ext_tab_data AS '/data';
**Create the external table using the CREATE TABLE..ORGANIZATION EXTERNAL syntax. This defines the metadata for the table describing how it should appear and how the data is loaded.**
CREATE TABLE countries_ext (
country_code VARCHAR2(5),country_name VARCHAR2(50),country_language VARCHAR2(50)
)
ORGANIZATION EXTERNAL (
TYPE ORACLE_LOADER
DEFAULT DIRECTORY ext_tab_data
ACCESS PARAMETERS (
RECORDS DELIMITED BY NEWLINE
FIELDS TERMINATED BY ','
MISSING FIELD VALUES ARE NULL
(
country_code CHAR(5),country_name CHAR(50),country_language CHAR(50)
)
)
LOCATION ('Countries1.txt','Countries2.txt')
)
PARALLEL 5
REJECT LIMIT UNLIMITED;
**Once the external table created,it can be queried like a regular table.**
SQL> SELECT *
2 FROM countries_ext
3 ORDER BY country_name;
COUNT COUNTRY_NAME COUNTRY_LANGUAGE
----- ---------------------------- -----------------------------
ENG England English
FRA France French
GER Germany German
IRE Ireland English
SCO Scotland English
USA Unites States of America English
WAL Wales Welsh
7 rows selected.
SQL>