Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6044221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:59:14+00:00 2026-05-23T06:59:14+00:00

I need to search our oracle database for a string in all tables and

  • 0

I need to search our oracle database for a string in all tables and columns. I have the below query I found online but when I execute it I get the following error

Any help is appreciated

ORA-06550: line 6, column 31:
PL/SQL: ORA-00904: "COLUMN_NAME": invalid identifier
ORA-06550: line 6, column 12:
PL/SQL: SQL Statement ignored
ORA-06550: line 8, column 30:
PLS-00364: loop index variable 'T' use is invalid
ORA-06550: line 7, column 4:
PL/SQL: Statement ignored
ORA-06550: line 12, column 38:
PLS-00364: loop index variable 'T' use is invalid
ORA-06550: line 12, column 16:
PL/SQL: Statement ignored

BEGIN  
  FOR t IN (SELECT table_name, column_name FROM all_tables) LOOP   
   EXECUTE IMMEDIATE    
    'SELECT COUNT(*) FROM '||t.table_name||' WHERE '||t.column_name||' = :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;
/
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:59:14+00:00Added an answer on May 23, 2026 at 6:59 am

    At a minimum, you need to query ALL_TAB_COLUMNS, not ALL_TABLES

    DECLARE
      match_count integer;
      v_search_string varchar2(4000) := <<string you want to search for>>;
    BEGIN  
      FOR t IN (SELECT owner, table_name, column_name FROM all_tab_columns) LOOP   
        EXECUTE IMMEDIATE    
          'SELECT COUNT(*) FROM '||t.owner || '.' || t.table_name||
          ' WHERE '||t.column_name||' = :1'   
           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 LOOP;
    END;
    /
    

    If you are looking for a string, however, you would almost certainly want to restrict yourself to looking for columns that could store a string. It wouldn’t make sense, for example, to search a DATE column for a string. And unless you have a great deal of a priori knowledge about what a BLOB column contains and the ability to parse the BLOB column’s binary formatting, it wouldn’t make sense to search a BLOB column for a string. Given that, I suspect you want something more like

    DECLARE
      match_count integer;
      v_search_string varchar2(4000) := <<string you want to search for>>;
    BEGIN  
      FOR t IN (SELECT owner,
                       table_name, 
                       column_name 
                  FROM all_tab_columns
                 WHERE data_type in ('CHAR', 'VARCHAR2', 'NCHAR', 'NVARCHAR2', 
                                     'CLOB', 'NCLOB') ) 
      LOOP   
        BEGIN
          EXECUTE IMMEDIATE    
            'SELECT COUNT(*) FROM '||t.owner || '.' || t.table_name||
            ' WHERE '||t.column_name||' = :1'   
             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; 
        EXCEPTION
          WHEN others THEN
            dbms_output.put_line( 'Error encountered trying to read ' ||
                                  t.column_name || ' from ' || 
                                  t.owner || '.' || t.table_name );
        END;
      END LOOP;
    END;
    /
    

    Of course, this is going to be insanely slow– you’d full scan every table once for every string column in the table. With moderately large tables and a moderate number of string columns, that is likely to take quite a while.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to search across multiple columns from two tables in my database using
I have a need to search names in our table, but we don't have
I need to search a string and replace all occurrences of %FirstName% and %PolicyAmount%
I need to search for all users containing a certain text string in their
I have a need to use the DOS command FINDSTR to search in all
I need to search a string in the string array. I dont want to
I've done a search on this subject already, and have found the same data
I'm looking into implementing full text search on our Firebird database. Our requirements are:
I need to do a search for people who are violating our don't use
We have a function in our code which isn't being called, but should be.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.