How To Load CLOB Data from a File into a CLOB column using PL/SQL
2016-12-29 10:14
656 查看
主题: | How To Load CLOB Data from a File into a CLOB column using PL/SQL | |||
文档 ID: | 437432.1 | 类型: | HOWTO | |
Modified Date: | 02-OCT-2007 | 状态: | MODERATED |
Goal
Solution[align=center][/align][align=center]
This document is being delivered to you via Oracle Support's Rapid Visibility (RaV) process, and therefore has not been subject to an independent technical review. |
Information in this document applies to any platform.GoalThe following code demonstates how to load CLOB data (greater than 32 KBytes) from a file into a CLOB column. The package DBMS_LOB is used to access a file stored on the operating system and load that data into a CLOB column. The DBMS_LOB.LOADCLOBFROMFILE() procedure loads the contents of the BFILE into the CLOB column using DBMS_LOB.LOBMAXSIZE which loads until the end of the BFILE is reached. This method allows the data to be loaded up to the maximum size that the CLOB column can hold. Passing DBMS_LOB.LOBMAXSIZE causes the procedure to read the entire BFILE. This is a useful technique for reading the entire LOB without introspecting the size of the LOB.Solution CREATE OR REPLACE DIRECTORY workdir as '/tmp/laura'; -- Change the directoryDROP TABLE test_clob;CREATE TABLE test_clob (id NUMBER, col_clob CLOB);INSERT INTO test_clob VALUES(1, EMPTY_CLOB());CREATE OR REPLACE PROCEDURE file_to_clob IS
b_fil bfile := BFILENAME('WORKDIR', 'f.txt'); -- Ensure f.txtexists
v_clob CLOB;
dest_offset NUMBER := 1;
source_offset NUMBER := 1;
src_csid NUMBER := NLS_CHARSET_ID('UTF8');
lang_ctx INTEGER := DBMS_LOB.DEFAULT_LANG_CTX;
warn INTEGER;
BEGIN
-- Retrieve the lob locator
SELECT col_clobINTO v_clob FROM test_clob WHERE id = 1 FOR UPDATE;
-- Open the target CLOB and the source BFILE
DBMS_LOB.OPEN(v_clob, DBMS_LOB.LOB_READWRITE);
DBMS_LOB.OPEN(b_fil, DBMS_LOB.FILE_READONLY); -- Load the contents of the bfile into the CLOB column
DBMS_LOB.LOADCLOBFROMFILE(v_clob, b_fil,
DBMS_LOB.LOBMAXSIZE,
dest_offset,
source_offset,
src_csid,
lang_ctx, warn); -- Check for the warning
IF warn = DBMS_LOB.WARN_INCONVERTIBLE_CHAR THEN
DBMS_OUTPUT.PUT_LINE('SomeCharacters couldn''t be converted');
END IF;
-- Close the LOBs
DBMS_LOB.CLOSE(v_clob);
DBMS_LOB.CLOSE(b_fil);END;
/
To test:
SQL> EXEC file_to_clob;
PL/SQL procedure successfully completed.
SQL> SELECT DBMS_LOB.GETLENGTH(col_clob) FROM test_clob;
DBMS_LOB.GETLENGTH(COL_CLOB)
----------------------------
121094
相关文章推荐
- How to copy a datafile from ASM to a file system not using RMAN
- using sqlbulkcopy to quick load data from your client to sqlserver
- How do I load text or csv file data into SQL Server?
- BW--ABAP code using BAPI's to load data into Cube from SpreadSheets
- How to copy a datafile from ASM to a file system not using RMAN (Doc ID 428893.1)
- How to load data into SAP HANA database
- How to run workflow using PL/SQL
- ODP.NET与复杂的PL/SQL数据类型(Using ODP.NET To Deal With Complex PLSQL Data Types)
- Here is How to Unpersist Your Persistent PL/SQL Package Data
- 如何从EXCEL文件加载Hierarchy到BW (How to Load Hierarchy From Flat File)
- How to recover deleted data from SQL Server 暴强
- Use sql loader to load data into database.
- How to get trace file from getbfno.sql gettrcname.sql
- How to move a datafile from a file system to ASM
- a universal class to complete import data from an excel file into a database
- Export data out to file from sql server
- How to recover deleted data from SQL Server
- SQL SERVER - Import CSV File Into SQL Server Using Bulk Insert - Load Comma Delimited File Into SQL Server
- ORACLE HANDBOOK系列之六:ODP.NET与复杂的PL/SQL数据类型(Using ODP.NET To Deal With Complex PLSQL Data Types)
- How to Recover from a Lost or Deleted Datafile with Different Scenarios [ID 198640.1]