I would like to make sure that every BFILE in my database really exists on the file system it is related to. I have the following error :
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: invalid
LOB locator specified: ORA-22275 ORA-06512: at line 59
with the following PL/SQL :
1 declare
2 sSQL varchar2(32767);
3 TYPE refcursor is REF CURSOR;
4 outCursor refcursor;
5 v_1 bfile;
6 dir_alias varchar2(500);
7 name varchar2(500);
8 bfile_exists BOOLEAN := FALSE;
9 --
10 -- DECLARATION DES CURSEURS
11 --
12 cursor find_bfile is
13 SELECT owner, table_name, column_name from dba_tab_columns where data_type='BFILE' order by 1,2,3;
14 begin
15 -- curseur principal sur dba_tab_columns
16 for boucle_find_bfile in find_bfile loop
17 dbms_output.put_line('Owner : ' || boucle_find_bfile.owner || 'Table : ' || boucle_find_bfile.table_name|| boucle_find_bfile.column_name );
18 sSQL := 'select ' || boucle_find_bfile.column_name || ' from ' || boucle_find_bfile.owner || '.' || boucle_find_bfile.table_name;
19 dbms_output.put_line('sSQL : ' || sSQL);
20 OPEN outCursor FOR sSQL;
21 LOOP
22 -- lecture initiale
23 FETCH outCursor INTO v_1;
24 dbms_output.put_line('Avant bfile_exists');
25 begin
26 bfile_exists := DBMS_LOB.FILEEXISTS( v_1 ) = 1;
27 EXCEPTION
28 WHEN DBMS_LOB.NOEXIST_DIRECTORY THEN
29 dbms_output.put_line('>>>>> Directory does not exist !');
30 WHEN DBMS_LOB.NOPRIV_DIRECTORY THEN
31 dbms_output.put_line('>>>>> Directory with privs pb !');
32 WHEN DBMS_LOB.INVALID_DIRECTORY THEN
33 dbms_output.put_line('>>>>> Invalid Directory !');
34 WHEN OTHERS THEN
35 dbms_output.put_line('Milieu : Erreur inattendue : ' || SQLERRM);
36 RAISE;
37 end;
38 dbms_output.put_line('Apres bfile_exists');
39 IF bfile_exists
40 THEN
41 dbms_lob.filegetname(v_1, dir_alias, name);
42 dbms_output.put_line('Table : ' || boucle_find_bfile.table_name || ' / dir_alias : ' || dir_alias || ' / name : ' || name );
43 END IF;
44 EXIT WHEN outCursor%NOTFOUND;
45 -- lecture suivante
46 EXIT WHEN outCursor%NOTFOUND;
47 END LOOP;
48 CLOSE outCursor;
49 end loop; -- fin curseur find_bfile
50 EXCEPTION
51 WHEN DBMS_LOB.NOEXIST_DIRECTORY THEN
52 dbms_output.put_line('>>>>> Directory does not exist !');
53 WHEN DBMS_LOB.NOPRIV_DIRECTORY THEN
54 dbms_output.put_line('>>>>> Directory with privs pb !');
55 WHEN DBMS_LOB.INVALID_DIRECTORY THEN
56 dbms_output.put_line('>>>>> Invalid Directory !');
57 WHEN OTHERS THEN
58 dbms_output.put_line('Fin ; Erreur inattendue : ' || SQLERRM);
59 RAISE;
60* end;
A hint : I have many "bfilename(NULL)" in my LOB type column. I know I do not use the DBMS_LOB.FILEEXISTS function correctly.
How can I do ?
Thanks in advance
Jean-michel A., Nemours, FRANCE
RDBMS : Oracle 11G on Linux with ASM
First you must fix command
because it should be located right below
to finish loop correctly and avoid one invalid iteration:
About invalid LOB locator: When BFILE columns value are
null
thenDBMS_LOB.FILEEXISTS
will throw exceptionORA-22275: invalid LOB locator specified
. A way to solve the problem is catching this into an exception/when block by ora-code. You can init/declare an exception via pragma as below and catch it later:Althought, if BFILE column is not null but file does not exists anymore in filesystem then
DBMS_LOB.FILEEXISTS
will returnfalse
and everything will flow as planned :)