Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: long raw to Blob
Bulletin - Convert LONG data into LOB data using PL/SQL.
Steps to convert a LONG to a LOB --------------------------------1. You can leave the long column in the old table and add a new LOB
column using the ALTER TABLE command. The ALTER TABLE command is not
able to change the type of a LONG column to a LOB column. LONG and
LOB
columns are 2 distinct datatypes so it is not possible to assign a
LONG column to a LOB column.
2. Write the data in the LONG or LONG RAW to a flat file.
3. Use a variety of ways to get flat file data into a LOB.
(flat file) was written.
b. Using either OCI8 or PL/SQL to copy the data from the server
side flat file into the LOB: 1. The OCI8 command OCILobLoadFromFile or the PL/SQL command DBMS_LOB.LOADFROMFILE() are the fastest ways to copy from a server side operating system flat file to a lob. 2. The OCI8 command OCILobWrite from a server side external procedure. The flat file will be on the server side even if the program which calls the server side external procedure is run from the client. This is the second fastest way to transfer from a server side operation system flat file to a lob. 3. The OCI8 OCILobWrite command. This method is used in the bull_lob program listed below. This may not be the fastest way to convert a long to a lob. If the program is run on a client machine then the long data on the server will be written to a client machine flat file and then the client flat file will be written back to the server lob column. This involves 2 trips across the network if it is run as a client program.4. The user will need to do their own character set conversions for CLOBS
update multimedia set audio_clip =
(select audio_clip from multimedia where id = 1) where audio_clip is null; end; /select id, audio_clip from multimedia; 3. The output should resemble:
SQL> grant all on dbms_lob to scott; Grant succeeded. SQL> grant create any directory to scott; Grant succeeded. SQL> connect scott/tiger; Connected. SQL> drop directorysome_dir_alias;
SQL> /* CREATE THE TABLE */ SQL> SQL> create table multimedia 2 (
3 id number, 4 video_clip clob default
empty_clob(),
5 audio_clip clob default null, 6 some_file bfile
default null
7 ) ; Table created. SQL> SQL> SQL> /* LOAD DATA INTO THE TABLE
*/
SQL> /* Insert 10 rows into the table which defaults to initializing
DOC> * the video_clip to empty and the audio_clip and some_file to
null.
DOC> */ SQL> SQL> /* The fast way to do this is to use array inserts
with oci
DOC> * (see OCIBindArrayOfStruct)
DOC> * The not so fast way is to use a loop in plsql as follows. DOC>
*/ SQL>
SQL> declare 2 loop_count integer; 3 begin 4
loop_count := 1;
5 while loop_count <= 10 loop 6 insert into multimedia (id) values (loop_count); 7 loop_count := loop_count + 1; 8 end loop; 9 end;10 /
15 dbms_lob.loadfromfile(ac, a_file, amount);
16 dbms_lob.fileclose(a_file); 17 commit; 18
18 /* update all rows in the table to the audio clip we just
loaded. */
19 update multimedia set audio_clip =
20 (select audio_clip from multimedia where id = 1) 21 where audio_clip is null; 22 end; 23 /PL/SQL procedure successfully completed. SQL> SQL> select id, audio_clip from multimedia;
ID
AUDIO_CLIP
1
abcdefghijklmnopqrstuvwxyz
2
abcdefghijklmnopqrstuvwxyz
3
abcdefghijklmnopqrstuvwxyz
ID
AUDIO_CLIP
4
abcdefghijklmnopqrstuvwxyz
5
abcdefghijklmnopqrstuvwxyz
6
abcdefghijklmnopqrstuvwxyz
ID
AUDIO_CLIP
7
abcdefghijklmnopqrstuvwxyz
8
abcdefghijklmnopqrstuvwxyz
9
abcdefghijklmnopqrstuvwxyz
ID
AUDIO_CLIP
abcdefghijklmnopqrstuvwxyz
10 rows selected. SQL> SQL> quit Received on Thu Apr 16 1998 - 11:45:19 CDT
![]() |
![]() |