Search Oracle database for row with exit

I am trying to find an Oracle database for any string containing a value %20or %2Fin a value. The values ​​I'm looking for were obtained from a website that was not encoded correctly and caused the HTML URL to be encoded into a string of values.

I used the following script to search for data in a database, but found that I cannot include an escape clause for a character %.

SET SERVEROUTPUT ON SIZE 100000

DECLARE
  match_count INTEGER;
-- Type the owner of the tables you are looking at
  v_owner VARCHAR2(255) :='OWNER';

-- Type the data type you are look at (in CAPITAL)
-- VARCHAR2, NUMBER, etc.
  v_data_type VARCHAR2(255) :='VARCHAR2';

-- Type the string you are looking at
  v_search_string VARCHAR2(4000) :='%\%2F%' ESCAPE '\';

--'-- Added to fix syntax highlighting on SO

BEGIN
  FOR t IN (SELECT table_name, column_name FROM all_tab_cols where owner=v_owner and data_type = v_data_type AND table_name LIKE '%') LOOP

    EXECUTE IMMEDIATE 
    'SELECT COUNT(*) FROM '||t.table_name||' WHERE '||t.column_name||' LIKE :1'
    INTO match_count
    USING v_search_string;

    IF match_count > 0 THEN
      dbms_output.put_line( t.table_name ||' '||t.column_name||' '||match_count );
    END IF;

  END LOOP;
END;
+4
source share
2 answers

You should add escape to the request, not a variable.

See escaping special characters in SQL

SELECT * FROM table WHERE column like '%\%20%' ESCAPE '\'

, %. http://docs.oracle.com/cd/B12037_01/server.101/b10759/conditions016.htm

+1

EXECUTE IMMEDIATE 
'SELECT COUNT(*) FROM '||t.table_name||' WHERE '||t.column_name||' LIKE :1'
INTO match_count
USING v_search_string;

EXECUTE IMMEDIATE 
'SELECT COUNT(*) FROM '||t.table_name||' WHERE '||t.column_name||' LIKE ''' || v_search_string || ''''
INTO match_count;
0

Source: https://habr.com/ru/post/1524608/


All Articles