例如我从维基百科下载了这个文件
https://dumps.wikimedia.org/other/pageviews/2018/2018-04/pageviews-20180407-130000.gz
在donwload和unzip之后我试图使用外部表返回数据,但是没有返回数据。我意识到(或者我猜)文件中的分隔符是空格char('')。这是我的代码:
CREATE TABLE Funcionarios_Externa (
Campo1 VARCHAR2(4000)
,campo2 VARCHAR2(4000)
,campo3 VARCHAR2(4000)
,campo4 VARCHAR2(4000)
,campo5 VARCHAR2(4000)
) ORGANIZATION EXTERNAL (
TYPE ORACLE_LOADER
DEFAULT DIRECTORY DADOS_LOGISTICA
ACCESS PARAMETERS (
RECORDS DELIMITED BY newline
READSIZE 200048576
SKIP 1
FIELDS TERMINATED BY ' ' OPTIONALLY ENCLOSED BY '"'
MISSING FIELD VALUES ARE NULL
)
LOCATION ('pageviews-20170301-000000')
) REJECT LIMIT UNLIMITED;
我不确定我做错了什么。没有错误,只返回数据。
有人能帮助我吗?提前致谢
这是日志文件,没有生成坏文件(我在脚本中添加了坏文件子句
Field Definitions for table FUNCIONARIOS_EXTERNA
Record format DELIMITED BY NEWLINE
Data in file has same endianness as the platform
Rows with all null fields are accepted
Fields in Data Source:
CAMPO1 CHAR (4000)
Terminated by " "
Enclosed by """ and """
Trim whitespace same as SQL Loader
CAMPO2 CHAR (4000)
Terminated by " "
Enclosed by """ and """
Trim whitespace same as SQL Loader
CAMPO3 CHAR (4000)
Terminated by " "
Enclosed by """ and """
Trim whitespace same as SQL Loader
CAMPO4 CHAR (4000)
Terminated by " "
Enclosed by """ and """
Trim whitespace same as SQL Loader
CAMPO5 CHAR (4000)
Terminated by " "
Enclosed by """ and """
Trim whitespace same as SQL Loader
答案 0 :(得分:1)
根据要加载的示例文件的链接,我观察到文件没有逗号分隔..它有whitespacce分隔。为了以防万一,我将文件名更改为.txt。 然后可以使用sql * developer ..
创建如下的外部表语法SET DEFINE OFF
--CREATE OR REPLACE DIRECTORY Enter New Dir AS 'M:\extract';
--GRANT READ ON DIRECTORY Enter New Dir TO USER;
--GRANT WRITE ON DIRECTORY Enter New Dir TO USER;
--drop table vijay_ext3;
CREATE TABLE vijay_ext3
( c1 VARCHAR2(300),
c2 VARCHAR2(128),
c3 NUMBER(3),
c4 NUMBER(3))
ORGANIZATION EXTERNAL
( TYPE ORACLE_LOADER
DEFAULT DIRECTORY DB_DUMP_DIR
ACCESS PARAMETERS
(records delimited BY '\n'
DB_DUMP_DIR:'pageviews.bad'
DB_DUMP_DIR:'pageviews.discard'
DB_DUMP_DIR:'pageviews.log'
skip 1
fields terminated BY WHITESPACE
OPTIONALLY ENCLOSED BY '"' AND '"'
lrtrim
missing field VALUES are NULL
( c1 CHAR(4000),
c2 CHAR(4000),
c3 CHAR(4000),
c4 CHAR(4000)
)
)
LOCATION ('pageviews.txt')
)
REJECT LIMIT UNLIMITED;
select * from vijay_ext3 WHERE ROWNUM <= 100;
答案 1 :(得分:0)
如果外部表有时工作而不是其他工作,则可能是连接到RAC数据库.. - 为了确保连接到文件所在的实例,需要在tnsnames.ora中添加INSTANCE_NAME。 如果您使用的是easyconnect,那么您也可以添加实例名称。 例如。 connect vijay / oracle @ // 10.0.10.101:1521/vijay/vijay1
connect username / password @ // hostname:port / service_name / instance_name
如果这不是RAC实例,那么显然问题出在DIRECTORY信息中,因为您在选择或创建过程中存在错误文件或Oracle错误。