我正在尝试将文件内容加载到外部表。执行此操作时,尾随空格将被截断。
'CREATE TABLE ' || rec.ext_table_name || ' (ROW_DATA VARCHAR2(4000)) ORGANIZATION EXTERNAL ' ||
'(TYPE ORACLE_LOADER DEFAULT DIRECTORY ' || rec.dir_name || ' ACCESS ' || 'PARAMETERS (RECORDS ' ||
'DELIMITED by NEWLINE NOBADFILE NODISCARDFILE ' ||
'FIELDS REJECT ROWS WITH ALL NULL FIELDS (ROW_DATA POSITION(1:4000) char)) LOCATION (' || l_quote ||
'temp.txt' || l_quote || ')) REJECT LIMIT UNLIMITED'
例如,B
表示空格,我的文件有:
Line1sometextBBBBBBB
我的外部表格只读:
Line1sometext
我希望文件也加载空白。如何阻止它删除尾随空格?
目前的问题是:
如果文件有:
“这是
的测试值“
^ this new line is also a part of the row_data.
答案 0 :(得分:2)
添加a trim_spec
clause,特别是NOTRIM
,以更改默认的字段修剪行为:
... FIELDS REJECT ROWS WITH ALL NULL FIELDS (ROW_DATA POSITION(1:4000) char NOTRIM)) LOCATION (...
^^^^^^
快速演示:
create table t42_ext (
row_data varchar2(4000)
)
organization external
(
type oracle_loader default directory mydir access parameters
(
records delimited by newline nobadfile nodiscardfile
fields reject rows with all null fields
(
row_data position(1:4000) char notrim
)
)
location ('temp.txt')
)
reject limit unlimited;
Table T42_EXT created.
select '<'|| row_data ||'>' from t42_ext;
'<'||ROW_DATA||'>'
--------------------------------------------------------------------------------
<Line1sometext >