I get the error "Binding error ORA01006 on line 15" in the following code:
DECLARE
v_search_string varchar2(4000) := 'OK';
v_query_str VARCHAR2(4000);
match_count integer;
BEGIN
FOR t IN (SELECT owner,
table_name,
column_name
FROM all_tab_columns
WHERE data_type in ('CHAR', 'VARCHAR2', 'NCHAR', 'NVARCHAR2') And TABLE_NAME = 'T1' And OWNER = 'O1')
LOOP
Begin
v_query_str := 'SELECT COUNT(*) FROM '|| t.table_name || ' WHERE ' || t.column_name || ' Like ''' || '%:1%' || '''';
dbms_output.put_line(v_query_str);
EXECUTE Immediate v_query_str
INTO match_count
USING v_search_string;
IF match_count >= 0 THEN
dbms_output.put_line( t.owner || '.' || t.table_name ||' '||t.column_name||' '||match_count );
END IF;
END;
END LOOP;
END;
I'm just trying to skip all the columns of characters in a table and count how many values in each correspond to a v_search_string value.
String "dbms_output.put_line (v_query_str);" prints one line: SELECT COUNT (*) FROM T1 WHERE Col1 Like '%: 1%'
The table shows 10 columns, which are the specified types.
Obviously, there is a binding variable (% 1), so I can not understand what is happening.
source
share