oracle loadtable,How to load XML files into Oracle table?

I am new at this so bear with me. Thanks.

I have a directory in my C drive. Like so, C:/Temp. it contains XML files that I would like to load into an Oracle table called xml_tab.

CREATE TABLE "OMBIL"."XML_TAB"

("ID" NUMBER(10,0),

"FILENAME" VARCHAR2(100 BYTE),

"XML" "XMLTYPE",

CONSTRAINT "XML_TAB_PK" PRIMARY KEY ("ID")

)

My XML files have the same structure and look like the following

XXXXXXXX

YTYYYYYYYY

Something off grid

open grid

closed grid

I would like to write a PL/SQL procedure to look inside my C:Temp directory and load the xml files into xml_tab oracle table. Do you guys have examples that I can follow to get this done.

I do have the following code, but its not working properly, also I would like the code to loop through all the xml files in the C:Temp directory, how can I do that???

create or replace PROCEDURE load_xml (p_dir IN VARCHAR2,

p_filename IN VARCHAR2) AS

l_bfile BFILE := BFILENAME(p_dir, p_filename);

l_clob CLOB;

l_dest_offset INTEGER := 1;

l_src_offset INTEGER := 1;

l_bfile_csid NUMBER := 0;

l_lang_context INTEGER := 0;

l_warning INTEGER := 0;

BEGIN

DBMS_LOB.createtemporary (l_clob, TRUE);

DBMS_LOB.fileopen(l_bfile, DBMS_LOB.file_readonly);

-- loadfromfile deprecated.

-- DBMS_LOB.loadfromfile(l_clob, l_bfile, DBMS_LOB.getlength(l_bfile));

DBMS_LOB.loadclobfromfile (

dest_lob => l_clob,

src_bfile => l_bfile,

amount => DBMS_LOB.lobmaxsize,

dest_offset => l_dest_offset,

src_offset => l_src_offset,

bfile_csid => l_bfile_csid ,

lang_context => l_lang_context,

warning => l_warning);

DBMS_LOB.fileclose(l_bfile);

INSERT INTO xml_tab (

id,

filename,

xml

)

VALUES (

xml_tab_seq.NEXTVAL,

p_filename,

XMLTYPE.createXML(l_clob)

);

COMMIT;

DBMS_LOB.freetemporary (l_clob);

END load_xml;

Getting the following error:

BEGIN load_xml(p_dir => 'XML_DIR', p_filename => 'test.xml'); END;

Error report -

ORA-22288: file or LOB operation FILEOPEN failed

No such file or directory

ORA-06512: at "SYS.DBMS_LOB", line 805

ORA-06512: at "OMBIL.LOAD_XML", line 14

ORA-06512: at line 1

22288. 00000 - "file or LOB operation %s failedn%s"

*Cause: The operation attempted on the file or LOB failed.

*Action: See the next error message in the error stack for more detailed

information. Also, verify that the file or LOB exists and that

the necessary privileges are set for the specified operation. If

the error still persists, report the error to the DBA.

I did grant all on XML_DIR to public.

Thank you.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值