0

I am trying to load values into a table who's one of the columns is BFILE using SQL Loader.

My table looks like this:

create table documents 
    ( id number primary key
    , text bfile)

Here are my CTL adn DAT files:

loader.ctl

load data
infile d':\test\loader.dat'
into table documents
replace
fields terminated by ';'
    ( id integer
    , text bfilename('MY_DIRECTORY', 'my_file.txt') terminated by eof)

loader.dat

3;my_file.txt

When I execute sqlldr command with paramters above, I received the error message:

SQL*Loader-350: Suntax error at line 7.

Expecting "," or ")", found "bfilename".

    , text bfilename('MY_DIRECTORY', 'my_file.txt') terminated by eof)

    ^

Am I doing something wrong or SQL Loader do not accept BFILEs?

Thank you,

mikcutu
  • 1,013
  • 2
  • 17
  • 34

1 Answers1

1

The documentation has a section on loading BFILE columns.

You need to have a filler column that will represent the filename field in your data file, and then refer to that filler field name in the bfile() - and not bfilename() - field definition:

load data
infile d:\test\loader.dat
into table documents
replace
fields terminated by ';'
    ( id
    , filename filler
    , text bfile(constant 'MY_DIRECTORY', filename) )

You don't want your ID field to be declared as integer; this is a full-word binary integer, and you probably won't get the value you expect in your table column.

If you want to explicitly convert to a number you can do:

...
fields terminated by ';'
    ( id "to_number(:id)"
    , filename filler
    , text bfile(constant 'MY_DIRECTORY', filename) )

but implicit conversion will usually be OK too.

Alex Poole
  • 183,384
  • 11
  • 179
  • 318
  • the solution is loading rows into the table but ... they do not seem to be linked to the physical location from the hard disk. When I browse the table and try to save one of the files, it gave me an error. "java.lang.NullPointerException at oracle.dbtools.raptor.extendedtype.BFILEType.saveToDisk(BFILEType.java:106) at oracle.dbtools.raptor.controls.celleditor.ExtendedTypeEditPanel.saveToDisk(ExtendedTypeEditPanel.java:398) at oracle.dbtools.raptor.controls.celleditor.BFileEditPanel.processExtendedType(BFileEditPanel.java:192)" – mikcutu Mar 09 '17 at 12:35
  • " at oracle.dbtools.raptor.controls.celleditor.ResultSetCellEditor.showExtendedTypeEdit(ResultSetCellEditor.java:299) at oracle.dbtools.raptor.controls.celleditor.ResultSetCellEditor.access$200(ResultSetCellEditor.java:52) at oracle.dbtools.raptor.controls.celleditor.ResultSetCellEditor$1.actionPerformed(ResultSetCellEditor.java:140) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)" – mikcutu Mar 09 '17 at 12:36
  • " at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236) at java.awt.Component.processMouseEvent(Component.java:5517) at javax.swing.JComponent.processMouseEvent(JComponent.java:3135) at java.awt.Component.processEvent(Component.java:5282) at java.awt.Container.processEvent(Container.java:1966) at java.awt.Component.dispatchEventImpl(Component.java:3984)" – mikcutu Mar 09 '17 at 12:37
  • " at java.awt.Container.dispatchEventImpl(Container.java:2024) at java.awt.Component.dispatchEvent(Component.java:3819) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822) at java.awt.Container.dispatchEventImpl(Container.java:2010) at java.awt.Window.dispatchEventImpl(Window.java:1791) at java.awt.Component.dispatchEvent(Component.java:3819) at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)" – mikcutu Mar 09 '17 at 12:37
  • " at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149) at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)" – mikcutu Mar 09 '17 at 12:38
  • That's a completely separate issue, so ask a new question that includes the Java code you're using. Or if your client is throwing that error, which client it is and exactly what you are doing. – Alex Poole Mar 09 '17 at 12:46