External table truncates trailing whitespace while reading from file

房东的猫 提交于 2020-01-16 05:35:34

问题


I'm trying to load the file contents to an external table. While doing this, trailing spaces are truncated.

'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'

For example, with B representing a blank space, my file has:

Line1sometextBBBBBBB

My external table reads that as just:

Line1sometext

I want the file to be loaded with blanks too. How can I stop it removing the trailing whitespace?

Current Problem is :

if file has:

"this is a test value with

"

 ^   this new line is also a part of the row_data.


回答1:


Add a trim_spec clause, specifically here NOTRIM, to change the default field trimming behaviour:

... FIELDS REJECT ROWS WITH ALL NULL FIELDS (ROW_DATA POSITION(1:4000) char NOTRIM)) LOCATION (...
                                                                            ^^^^^^

Quick demo:

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       >                                                          


来源:https://stackoverflow.com/questions/39013530/external-table-truncates-trailing-whitespace-while-reading-from-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!