PLS-00215: String length constraints must be in range in blob (3 Merged) [message #525045] |
Wed, 28 September 2011 09:40  |
sundarfaq
Messages: 235 Registered: October 2007 Location: Chennai
|
Senior Member |
|
|
Hi,
I want to read content from blob column and write into file using dbms_output.put_line. See below code. i am getting
PLS-00215: String length constraints must be in range (1 .. 32767) error.
set serveroutput on
DECLARE
l_file UTL_FILE.FILE_TYPE;
l_buffer RAW(32767);
l_amount BINARY_INTEGER :=32767;
l_pos INTEGER := 1;
l_blob BLOB;
l_blob_len INTEGER;
BEGIN
-- Get LOB locator
SELECT content
INTO l_blob
FROM vdl_file_content
where file_id='6280';
l_blob_len := DBMS_LOB.getlength(l_blob);
dbms_output.put_line(l_blob_len);
-- Open the destination file.
--l_file := UTL_FILE.fopen('BLOBS','MyImage.gif','w', 32767);
-- Read chunks of the BLOB and write them to the file
-- until complete.
WHILE l_pos < l_blob_len LOOP
DBMS_LOB.READ(l_blob, l_amount, l_pos, l_buffer);
DBMS_OUTPUT.PUT_LINE(l_buffer);
l_pos := l_pos + l_amount;
END LOOP;
-- Close the file.
-- UTL_FILE.fclose(l_file);
EXCEPTION
WHEN OTHERS THEN
RAISE;
END;
the length of the blob column is 1081656. so i have changed in raw(1081656) in above code. after the execution, i am getting the below error
PLS-00215: String length constraints must be in range (1 .. 32767).
Please help me..
thanks,
Michael
*Please learn proper syntax of <code-tags> *BlackSwan
[Updated on: Wed, 28 September 2011 09:55] by Moderator Report message to a moderator
|
|
|
|
|
Re: PLS-00215: String length constraints must be in range in blob [message #525051 is a reply to message #525045] |
Wed, 28 September 2011 10:01   |
flyboy
Messages: 1903 Registered: November 2006
|
Senior Member |
|
|
holdingbe wrote on Wed, 28 September 2011 16:46the length of the blob column is 1081656. so i have changed in raw(1081656) in above code. after the execution, i am getting the below error
PLS-00215: String length constraints must be in range (1 .. 32767).
Maybe before modifying any code snippet you get, you should really understand (with the help of documentation) what it does. DBMS_LOB package and its methods is described in PL/SQL Packages and Types Reference, which is available with other Oracle documentation books e.g. online on http://tahiti.oracle.com/ Please, read there about its READ method.
Your assumption is incorrect. Why do you think that there is a LOOP? The error message is self-explaining - that size of RAW variable is not supported.
By the way, what problem did you face with the original RAW size (32767)?
|
|
|
|
Re: PLS-00215: String length constraints must be in range in blob [message #525095 is a reply to message #525055] |
Thu, 29 September 2011 00:44  |
 |
Barbara Boehmer
Messages: 9106 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
SCOTT@orcl_11gR2> -- create table with blob column and insert test data:
SCOTT@orcl_11gR2> CREATE TABLE vdl_file_content
2 (file_id NUMBER,
3 content BLOB)
4 /
Table created.
SCOTT@orcl_11gR2> INSERT INTO vdl_file_content
2 SELECT 6280, UTL_RAW.CAST_TO_RAW ('testing')
3 FROM DUAL
4 /
1 row created.
SCOTT@orcl_11gR2> -- load blob into file:
SCOTT@orcl_11gR2> CREATE OR REPLACE DIRECTORY blobs AS 'c:\my_oracle_files'
2 /
Directory created.
SCOTT@orcl_11gR2> DECLARE
2 l_blob BLOB;
3 l_blob_len INTEGER;
4 l_file UTL_FILE.FILE_TYPE;
5 l_amount BINARY_INTEGER := 32767;
6 l_pos INTEGER := 1;
7 l_buffer RAW (32767);
8 BEGIN
9 -- Get LOB locator
10 SELECT content
11 INTO l_blob
12 FROM vdl_file_content
13 WHERE file_id = 6280;
14
15 l_blob_len := DBMS_LOB.GETLENGTH (l_blob);
16
17 -- Open the destination file.
18 l_file := UTL_FILE.FOPEN ('BLOBS', 'MyImage.gif', 'w', 32767);
19
20 -- Read chunks of the BLOB and write them to the file until complete.
21 WHILE l_pos < l_blob_len LOOP
22 DBMS_LOB.READ (l_blob, l_amount, l_pos, l_buffer);
23 UTL_FILE.PUT_RAW (l_file, l_buffer, TRUE);
24 l_pos := l_pos + l_amount;
25 END LOOP;
26
27 -- Close the file.
28 UTL_FILE.FCLOSE (l_file);
29 EXCEPTION
30 WHEN OTHERS THEN
31 IF UTL_FILE.IS_OPEN (l_file) THEN
32 UTL_FILE.FCLOSE (l_file);
33 END IF;
34 RAISE;
35 END;
36 /
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> -- check results:
SCOTT@orcl_11gR2> DECLARE
2 l_bfile BFILE;
3 l_blob BLOB;
4 BEGIN
5 l_bfile := BFILENAME ('BLOBS', 'MyImage.gif');
6 DBMS_LOB.FILEOPEN (l_bfile, DBMS_LOB.FILE_READONLY);
7 DBMS_LOB.CREATETEMPORARY (l_blob, TRUE);
8 DBMS_LOB.LOADFROMFILE (l_blob, l_bfile, DBMS_LOB.GETLENGTH (l_bfile));
9 DBMS_OUTPUT.PUT_LINE (UTL_RAW.CAST_TO_VARCHAR2 (l_blob));
10 DBMS_LOB.FILECLOSE (l_bfile);
11 END;
12 /
testing
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2>
|
|
|