用sqlplus,我不记得从哪来的资料,有兴趣的自己动动手吧。
The following is the only method available to read the contents of a binary
file into a database BLOB using PL/SQL:
1. Create a database directory object to point to the operating system
directory which contains the file (or files) that you wish to read
into a database blob.
SQL> create or replace directory carldir as '/tmp';
Directory created.
2. Create a table that contains a blob column (If one does not already
exist).
SQL> insert into blobtab(index_col, blob_col)
values(1, utl_raw.cast_to_raw('this is only a test'));
1 row created.
or
SQL> insert into blobtab(index_col, blob_col)
values(1, empty_blob());
1 row created.
SQL> select count(*) from blobtab
;
COUNT(*)
----------
1
4. Run the program. The program is described below.
SQL> @rbfile
Size of input file: 154240
After loadfromfile
Size of blob: 154240
PL/SQL procedure successfully completed.
------
rbfile.sql:
--
-- A program that demonstrates that an operating system file containing
-- raw data may be read into a database BLOB column.
--
declare
ablob blob;
abfile bfile := bfilename('CARLDIR', 'cc'); -- Get a pointer to the file.
amount integer;
asize integer;
begin
--
-- Note: Above, the blobtab table was initialized with one entry. This
-- is needed because the PL/SQL BLOB locator (ablob) must point to a
-- specific EXISTING NON-NULL database BLOB. Also, the select statement
-- may only return one entry. If more than one row is returned
-- (more than one row with index_col set equal to 1), then the script
-- will fail.
--
select blob_col into ablob from blobtab where index_col = 1;
dbms_lob.fileopen(abfile);
asize := dbms_lob.getlength(abfile);
dbms_output.put_line('Size of input file: ' || asize);
dbms_lob.loadfromfile(ablob, abfile, asize);
dbms_output.put_line('After loadfromfile');
asize := dbms_lob.getlength(ablob);
dbms_output.put_line('Size of blob: ' || asize);
exception
when others then
dbms_output.put_line('An exception occurred');
dbms_output.put_line(sqlcode || sqlerrm);
end;
/
DECLARE
stud_hist CLOB;
BEGIN
--Fetch the LOB locator
SELECT student_history INTO stud_hist
FROM student
WHERE student_id = 1003
FOR UPDATE;
--The LOB is empty to start with. Append 10 characters
--onto the end.
DBMS_LOB.WRITEAPPEND (stud_hist, 10, ‘1234567890’);
--Do the same thing twice more, giving
--us a total of 30 characters.
DBMS_LOB.WRITEAPPEND (stud_hist, 10, ‘1234567890’);
DBMS_LOB.WRITEAPPEND (stud_hist, 10, ‘1234567890’);
END;