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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| create or replace
Package Body Ppn As
-- private procedure to check a table against a pattern
Procedure Fulltext_Search_Onetable( Pattern In Varchar2, Table_Name In Varchar2, Condition In Varchar2 )
iS
statement Varchar2(2080);
cursor_Id Integer;
Row_Found Integer;
Begin
-- open cursor
Cursor_Id := Dbms_Sql.Open_Cursor;
-- create cursor's query
statement:= 'SELECT 1 found FROM DUAL WHERE EXISTS( SELECT * FROM '||table_name||' WHERE '||condition||' 1=0 )';
--dbms_output.put_line (statement);
-- parse cursor
dbms_sql.parse(cursor_id, statement, dbms_sql.native);
-- supply binds, this is the only way i found to bind multiple binds with just one value.
dbms_sql.bind_variable(cursor_id, ':pattern', pattern);
-- execute cursor and get result
-- there is a trick, no result records => not found !!!
row_found:=dbms_sql.execute_and_fetch(cursor_id, false );
If Row_Found > 0 Then
Dbms_Output.Put_Line (table_name);
--Else
-- dbms_output.put_line (' not ok');
END IF;
-- correctly close cursor
Dbms_Sql.Close_Cursor(Cursor_Id);
End Fulltext_Search_Onetable;
Procedure Fulltext_Search( pattern IN Varchar2, SM_SHEMA_OWNER In Varchar2 Default '****', SM_SUFFIX In Varchar2 Default '%M1')
IS
condition VARCHAR2(2000);
column_found BOOLEAN;
BEGIN
-- rechercher parmis les tables de l'utilisateur ****.
FOR c_table IN(
SELECT table_name
From All_Tables
Where Dropped ='NO' And Owner = Sm_Shema_Owner And Table_Name Like SM_SUFFIX )
LOOP
-- creer la requete de recherche ( en construisant trouvant et construisant les colonnes sur d )
condition:= '';
Column_Found:= False;
--dbms_output.put(c_table.table_name);
FOR c_column IN(
SELECT column_name
FROM all_tab_columns
WHERE
low_value <> high_value AND
( high_value IS NOT NULL OR low_value IS NOT NULL) AND
data_type = 'VARCHAR2' AND
table_name = c_table.table_name )
LOOP
-- dbms_output.put_line( c_column.column_name );
condition:= condition||'"'||c_column.column_name||'" like :pattern OR ';
column_found:=TRUE;
END LOOP;
-- maintenant on a la condition on l'affiche...
If Column_Found Then
Fulltext_Search_Onetable( Pattern, c_table.table_name, condition);
--ELSE
-- dbms_output.put_line (' not columns');
END IF;
END LOOP; --c_table cursor loop.
End;
End Ppn; -- end of pakage def |
Partager