<legend id='Iv8VF'><style id='Iv8VF'><dir id='Iv8VF'><q id='Iv8VF'></q></dir></style></legend>

<small id='Iv8VF'></small><noframes id='Iv8VF'>

    <tfoot id='Iv8VF'></tfoot>
    <i id='Iv8VF'><tr id='Iv8VF'><dt id='Iv8VF'><q id='Iv8VF'><span id='Iv8VF'><b id='Iv8VF'><form id='Iv8VF'><ins id='Iv8VF'></ins><ul id='Iv8VF'></ul><sub id='Iv8VF'></sub></form><legend id='Iv8VF'></legend><bdo id='Iv8VF'><pre id='Iv8VF'><center id='Iv8VF'></center></pre></bdo></b><th id='Iv8VF'></th></span></q></dt></tr></i><div id='Iv8VF'><tfoot id='Iv8VF'></tfoot><dl id='Iv8VF'><fieldset id='Iv8VF'></fieldset></dl></div>

      • <bdo id='Iv8VF'></bdo><ul id='Iv8VF'></ul>

        Oracle 在所有表的所有列中搜索字符串

        时间:2023-09-19
          <tfoot id='4P68Y'></tfoot>
        • <small id='4P68Y'></small><noframes id='4P68Y'>

        • <i id='4P68Y'><tr id='4P68Y'><dt id='4P68Y'><q id='4P68Y'><span id='4P68Y'><b id='4P68Y'><form id='4P68Y'><ins id='4P68Y'></ins><ul id='4P68Y'></ul><sub id='4P68Y'></sub></form><legend id='4P68Y'></legend><bdo id='4P68Y'><pre id='4P68Y'><center id='4P68Y'></center></pre></bdo></b><th id='4P68Y'></th></span></q></dt></tr></i><div id='4P68Y'><tfoot id='4P68Y'></tfoot><dl id='4P68Y'><fieldset id='4P68Y'></fieldset></dl></div>

              • <bdo id='4P68Y'></bdo><ul id='4P68Y'></ul>
                  <tbody id='4P68Y'></tbody>
                <legend id='4P68Y'><style id='4P68Y'><dir id='4P68Y'><q id='4P68Y'></q></dir></style></legend>
                1. 本文介绍了Oracle 在所有表的所有列中搜索字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要在我们的 oracle 数据库中搜索所有表和列中的字符串.我在网上找到了以下查询,但是当我执行它时出现以下错误

                  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

                  感谢任何帮助

                  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;
                  /
                  

                  推荐答案

                  至少需要查询ALL_TAB_COLUMNS,而不是ALL_TABLES

                  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;
                  /
                  

                  然而,如果您正在寻找一个字符串,您几乎肯定希望限制自己寻找可以存储字符串的列.例如,在 DATE 列中搜索字符串是没有意义的.除非您对 BLOB 列包含的内容以及解析 BLOB 列的二进制格式的能力有大量先验知识,否则在 BLOB 列中搜索字符串是没有意义的.鉴于此,我怀疑您想要更像

                  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.

                  这篇关于Oracle 在所有表的所有列中搜索字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Oracle 插入如果不存在语句 下一篇:Oracle 中的递归

                  相关文章

                  <i id='h4ENs'><tr id='h4ENs'><dt id='h4ENs'><q id='h4ENs'><span id='h4ENs'><b id='h4ENs'><form id='h4ENs'><ins id='h4ENs'></ins><ul id='h4ENs'></ul><sub id='h4ENs'></sub></form><legend id='h4ENs'></legend><bdo id='h4ENs'><pre id='h4ENs'><center id='h4ENs'></center></pre></bdo></b><th id='h4ENs'></th></span></q></dt></tr></i><div id='h4ENs'><tfoot id='h4ENs'></tfoot><dl id='h4ENs'><fieldset id='h4ENs'></fieldset></dl></div>

                  <small id='h4ENs'></small><noframes id='h4ENs'>

                  • <bdo id='h4ENs'></bdo><ul id='h4ENs'></ul>

                2. <legend id='h4ENs'><style id='h4ENs'><dir id='h4ENs'><q id='h4ENs'></q></dir></style></legend>
                3. <tfoot id='h4ENs'></tfoot>