How to query all tables in oracle

Source: Internet
Author: User

Many new users may not know how to query all tables and data in oracle. The following describes how to query all tables in oracle for your reference.

 
 
  1. SELECT t. data_type
  2. FROM user_tab_columns t
  3. Group by t. data_type;
  4. -- Created on 2010-8-26 by RONGZHI_LI
  5. DECLARE
  6. CURSOR ot (namelike IN VARCHAR2)
  7. IS
  8. (SELECT owner AS uname,
  9. Object_name AS tname
  10. FROM all_objects
  11. WHERE object_type = 'table'
  12. AND owner LIKE namelike
  13. );
  14. CURSOR tc (username IN all_tab_columns.owner % TYPE, tablename IN all_tab_columns.table_name % type)
  15. IS
  16. (SELECT t. owner as uname,
  17. T. table_name AS tab,
  18. T. column_name AS col,
  19. T. data_type data
  20. FROM all_tab_columns t
  21. WHERE t. owner = username
  22. AND t. table_name = tablename
  23. );
  24. Sqlstr VARCHAR2 (200 );
  25. Findsqlstr VARCHAR2 (200 );
  26. Foundcount NUMBER;
  27. Data_type VARCHAR2 (100): = '';
  28. Logic_symbol VARCHAR2 (10): = ';
  29. Data_value VARCHAR2 (100 );
  30. -- Set it by yourself
  31. Name_like VARCHAR2 (100): = '% HS _ % ';
  32. Find_type VARCHAR2 (100): = 'varchar2'; -- 'varchar2'; number
  33. Find_value VARCHAR2 (100): = 'icbc ';
  34. Use_like BOOLEAN: = true;
  35. BEGIN
  36. Data_type: = upper (find_type );
  37. Data_value: = find_value; -- default value first

-- 1. Determine whether the type is a string

 
 
  1. IF data_type = 'varchar2' THEN -- special character string judgment
  2. Data_value: = ''' | find_value | '''; -- Note: the pl/SQL display ''is''
  3. End if;

-- 2. determine whether to use like. This should be compatible with the varchar2 type.

 
 
  1. IF use_like THEN
  2. Logic_symbol: = 'like ';
  3. Data_value: = ''' % '| find_value |' % '''; -- Note: pl/SQL displays ''''
  4. End if;
  5. --
  6. FOR aot IN ot (name_like)
  7. LOOP
  8. FOR atc IN tc (aot. uname, aot. tname)
  9. LOOP
  10. Foundcount: = 0;
  11. IF atc. DATA = data_type THEN
  12. Sqlstr: = 'select count (*) from' | atc. uname | '.' | atc. tab | 'where' | atc. col
  13. | Logic_symbol | data_value;
  14. -- Dbms_output.put_line (sqlstr); -- used for debug
  15. EXECUTE immediate sqlstr INTO foundcount;
  16. IF foundcount> 0 THEN
  17. Findsqlstr: = 'select * from' | atc. uname | '.' | atc. tab | 'where' | atc. col |
  18. Logic_symbol | data_value | '; --' | foundcount;
  19. Dbms_output.put_line (findsqlstr );
  20. End if;
  21. End if;
  22. End loop;
  23. End loop;
  24. Dbms_output.put_line ('end of lookup ');
  25. END;

The preceding describes how to query all tables in oracle.

Oracle Stored Procedure debugging method

Learn about the physical structure of Oracle

Setting of Oracle automatic archiving Mode

Provides you with an in-depth understanding of the Oracle archiving mode.

How to delete ORACLE archive logs

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.