You Asked
Hi, Tom,
I've been using your p procedure very happily. It cuts a long
string into pieces, unlike dbms_output.put_line:
procedure p(p_str in varchar2)
as
l_str long default p_str;
begin
loop
exit when l_str is null;
dbms_output.put_line( substr( l_str, 1, 250 ) );
l_str := substr( l_str, 251 );
end loop;
end;
Now I want to combine this with your
select utl_raw.cast_to_varchar2(dbms_lob.substr(blob_col,2000,1))
from blobtable;
That is, I want to show *all* content of a BLOB column on
screen, in spite of its garbage-looking nature. Note I
want to see *all* not just the first 2000 characters.
(BTW, you said we can substr the first 4000. On my 8.1.5
database, I can only substr 2000, not 2001 or beyond.)
In fact, if there's a way to extract BLOB content into a file
in the file system, preferably using UTL_FILE, that would be
even better. Less importantly, is there any way to load a
binary file into BLOB using SQL*Loader? The Oracle manual for
SQL*Loader gives an example of loading CLOB which won't work
on BLOB for me. It's the example 5-13 at
</code>
http://download-east.oracle.com/docs/cd/A81042_01/DOC/server.816/a76955/ch05.htm <code>
I like to use LOBFILE but I don't think I can use TERMINATED
BY EOF.
Thank you very much.
Yong Huang
yhuang@indigopool.com
and Tom said...
do this to get the first 4000:
ps$tkyte@8i> create or replace function blobtochar( p_blob in blob ) return varchar2
2 as
3 begin
4 return utl_raw.cast_to_varchar2(dbms_lob.substr(p_blob,4000,1));
5 end;
6 /
Function created.
ops$tkyte@8i> select blobtochar(resume) from emp;
beyond 4000, cannot do it -- best we could do is write a stored procedure to dump some blobs but only upto 1,000,000 bytes of them. Beyond that -- no go. SQL won't let you go >4,000.
so, in sqlplus the ability to see the entire blob is not available.
As for writing the file to the OS, not using UTL_FILE. UTL_FILE will not do a binary file.
Do you have a C compiler? what is your OS? Do you have Pro*C Use Ask Tom to ask this if you want to persue it please... I can post an example of getting a lob to a file using an extproc. Java would work as well.
An example of using sqlldr to load a binary file is as follows. You do use the terminated by EOF since you want to load the entire file (load until EOF). EOF is not a ^D or ^Z -- its "the end of file".
I wrote a small C program:
void main()
{
int i;
for( i = 0; i < 1000; i++ )
printf( "%c", i%256 );
}
and ran it into allbytes.dat:
$ ./test > allbytes.dat
Then, I altered EMP to have a column "resume" of type blob and using the following CTL file:
LOAD DATA
INFILE *
INTO TABLE EMP
REPLACE
FIELDS TERMINATED BY ','
( EMPNO INTEGER EXTERNAL,
ENAME CHAR,
JOB CHAR,
MGR INTEGER EXTERNAL,
SAL DECIMAL EXTERNAL,
COMM DECIMAL EXTERNAL,
DEPTNO INTEGER EXTERNAL,
RES_FILE FILLER CHAR,
"RESUME" LOBFILE (RES_FILE) terminated by eof NULLIF RES_FILE = 'NONE'
)
BEGINDATA
7782,CLARK,MANAGER,7839,2572.50,,10,allbytes.dat
loaded the data. Now, in sqlplus I can see:
ops$tkyte@8i> select dbms_lob.getlength(resume) from emp;
DBMS_LOB.GETLENGTH(RESUME)
--------------------------
1000
it loaded all 1,000 bytes (and we know that it did not stop at ^D or ^Z since I put every ascii character in there). Using DUMP I can see that the data was input correctly:
1* select dump( utl_raw.cast_to_varchar2(dbms_lob.substr(resume,300,1)) ) from emp
ops$tkyte@8i> /
DUMP(UTL_RAW.CAST_TO_VARCHAR2(DBMS_LOB.SUBSTR(RESUME,300,1))
------------------------------------------------------------
Typ=1 Len=300: 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,1
8,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,3
8,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,5
8,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,7
8,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,9
8,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113
,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128
,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143
,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158
,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173
,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188
,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203
,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218
,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233
,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248
,249,250,251,252,253,254,255,0,1,2,3,4,5,6,7,8,9,10,11,12,13
,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33
,34,35,36,37,38,39,40,41,42,43
All of the ascii codes are sequential from 0 on up -- as I expected. I get out what I put in.
Rating
(14 ratings)
Is this answer out of date? If it is, please let us know via a Comment