Home » SQL & PL/SQL » SQL & PL/SQL » Need help in updating blob column
Need help in updating blob column [message #191922] |
Fri, 08 September 2006 12:26  |
grk28
Messages: 38 Registered: June 2006
|
Member |
|
|
Hi friends,
I have gone through some forums and wrote a procedure to update a blod column and the procedure is as follows
SQL> CREATE OR REPLACE DIRECTORY MY_FILES AS 'C:\MY_DATA';
Directory created.
I have placed the pdf in C:\MY_DATA.
SQL> CREATE OR REPLACE PROCEDURE read_file IS
2 src_file BFILE := bfilename('MY_FILES', 'scheduler.pdf');
3 dst_file BLOB;
4 lgh_file BINARY_INTEGER;
5 BEGIN
6
7
8
9 -- lock record
10 SELECT resume
11 INTO dst_file
12 FROM sam_emp
13 FOR update;
14
15 -- open the file
16 dbms_lob.fileopen(src_file, dbms_lob.file_readonly);
17
18 -- determine length
19 lgh_file := dbms_lob.getlength(src_file);
20
21 -- read the file
22 dbms_lob.loadfromfile(dst_file, src_file, lgh_file);
23
24 -- update the blob field
25 UPDATE sam_emp
26 SET resume = dst_file ;
27 COMMIT;
28
29 -- close file
30 dbms_lob.fileclose(src_file);
31
32
33 END read_file;
34 /
Procedure created.
Elapsed: 00:00:00.68
SQL> exec read_file
PL/SQL procedure successfully completed.
I am able to view the file if it is img/word document ,but if it is .pdf it is saying that the document is corrupted.What could be the reason ??
Also when i m running the same procedure in linux machine i am getting the following error.
SQL> CREATE OR REPLACE DIRECTORY MY_FILES AS /u01/app/oracle';
Directory created.
I have placed these files in above location
SQL> CREATE OR REPLACE PROCEDURE read_file IS
2 src_file BFILE := bfilename('MY_FILES', 'scheduler.pdf');
3 dst_file BLOB;
4 lgh_file BINARY_INTEGER;
5 BEGIN
6
7
8
9 -- lock record
10 SELECT resume
11 INTO dst_file
12 FROM sam_emp
13 FOR update;
14
15 -- open the file
16 dbms_lob.fileopen(src_file, dbms_lob.file_readonly);
17
18 -- determine length
19 lgh_file := dbms_lob.getlength(src_file);
20
21 -- read the file
22 dbms_lob.loadfromfile(dst_file, src_file, lgh_file);
23
24 -- update the blob field
25 UPDATE sam_emp
26 SET resume = dst_file ;
27 COMMIT;
28
29 -- close file
30 dbms_lob.fileclose(src_file);
31
32
33 END read_file;
34 /
Procedure created.
When i am executing my procedure in linux machine it is giving me following error.
SQL> exec read_file;
BEGIN read_file; END;
*
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: invalid LOB locator specified: ORA-22275
ORA-06512: at "SYS.DBMS_LOB", line 637
ORA-06512: at "SCOTT.READ_FILE", line 22
ORA-06512: at line 1
Can any one of you please help me out.
Regards,
R
|
|
|
|
Re: Need help in updating blob column [message #192004 is a reply to message #191922] |
Sat, 09 September 2006 14:14   |
oigor
Messages: 8 Registered: September 2006 Location: Athens, GREECE
|
Junior Member |
|
|
Hi,
Just remove these lines from your program:
25 UPDATE sam_emp
26 SET resume = dst_file ;
Leave COMMIT (this is to save the changes and to release the lock on "FOR UPDATE")
That should be all, and your program should run properly.
DBMS_LOB.LOADFROMFILE procedure already copies the data drom file to BLOB, there's no need for UPDATE statement.
Don't forget to grant read permissions on the folder to all the users that will use it.
I don't see thet your SELECT statement has WHERE part! Be careful, and specify WHERE clause to select only ONE record at the time, otherwise you will get an exception.
----
Igor Obradovic
|
|
|
|
Re: Need help in updating blob column [message #192019 is a reply to message #191922] |
Sat, 09 September 2006 15:22   |
grk28
Messages: 38 Registered: June 2006
|
Member |
|
|
Hi Igor,
Thanks for your response.It seems to be working .
But i just wonder how it is gonna update that column without update clause ?? Can you please explain that to me as well ?
One more thing is ,i am able to upload .jpg , .xls ,.doc files into that column but not .pdf ,i able to execute the proc successfully but whn i try to view the .pdf file it is saying file is damaged .What could be the reason ? Is this the problem with the adobe version that i am using or something else ?
Please help me out in this as well.
Regards,
K
|
|
|
Re: Need help in updating blob column [message #192021 is a reply to message #191922] |
Sat, 09 September 2006 16:13   |
oigor
Messages: 8 Registered: September 2006 Location: Athens, GREECE
|
Junior Member |
|
|
DBMS_LOB.LOADFROMFILE procedure is doing the update for you.
Why is so!? Well, it has to do with BLOB type itself.
Many things are different with BLOBs comparing to scalar types, and that's because it's an object.
So, this is how it works... You do not use UPDATE, you must use locators, empty_blob() function, DBMS_LOB package, etc etc... If you code an application, you will have to use streams to deal with BLOBs, while with VARCHAR2 you won't.
Concerning the PDF, I'm not sure what's wrong there.. But if your program works fine with JPG, GIF, Word, MP3, AVI, etc, then it cannot be your program that is corrupted. Neither can be that your program corrupts the PDF file.
Is everything OK with your extracting procedure from the DB?
How do you extract back from the column to the file?
Try to save the content of the column to the file using TOAD or similar tool. Then try to open the PDF with various PDF viewers.
Also, try with different PDF files, e.g. with some files that can open on your computer for sure...
Ciao,
Igor
|
|
|
Re: Need help in updating blob column [message #192061 is a reply to message #191922] |
Sun, 10 September 2006 14:40  |
grk28
Messages: 38 Registered: June 2006
|
Member |
|
|
Hi Igor,
Thanks for explaining the concepts behind BLOB .
Well, i am executing procedure through sql prompt and viewing the file using TOAD.It opens JPG,GIF ,word documents perfectly,but when it comes to PDF it says that the file is damaged.
Do you think is there any problem with my TOAD or with my Adobe acrobat reader ??.
Anyways let me try using another version of Adobe.
Please let me know if you get some thought on this.
Thanks in Advance.
Raghukalyan.G
|
|
|
Goto Forum:
Current Time: Fri Apr 18 20:26:15 CDT 2025
|