Để tìm kiếm nội dung của tất cả các cột của tất cả các bảng của cơ sở dữ liệu Oracle, có thể làm như sau:
- Kết nối với Cơ sở dữ liệu Oracle: Trước tiên, kết nối tới cơ sở dữ liệu Oracle bằng SQL*Plus hoặc bất kỳ công cụ client để truy cập CSDL.
- Thực hiện truy vấn: Thực hiện câu lệnh SELECT tìm kiếm nội dung của tất cả các cột trong tất cả các bảng.
-- Step 1: Connect to your Oracle database using SQL*Plus or other Oracle client tools.
-- Step 2: Execute the following PL/SQL script.
DECLARE
search_value VARCHAR2(100) := 'your_search_value_here';
sql_query VARCHAR2(1000);
BEGIN
FOR t IN (SELECT table_name, column_name
FROM all_tab_columns
WHERE owner = 'YOUR_SCHEMA_NAME' -- Replace with the schema name where the tables are located
)
LOOP
sql_query := 'SELECT COUNT(*) FROM ' || t.table_name || ' WHERE ' || t.column_name || ' LIKE ''%' || search_value || '%''';
-- You can modify the search condition as per your requirement, for example, you can use UPPER() function for case-insensitive search.
-- sql_query := 'SELECT COUNT(*) FROM ' || t.table_name || ' WHERE UPPER(' || t.column_name || ') LIKE ''%' || UPPER(search_value) || '%''';
-- Uncomment the following line if you want to see the generated SQL queries.
-- DBMS_OUTPUT.PUT_LINE(sql_query);
EXECUTE IMMEDIATE sql_query;
-- If you want to display the table and column names along with the count of matching rows, you can use the following line.
-- DBMS_OUTPUT.PUT_LINE(t.table_name || '.' || t.column_name || ': ' || sql_query);
END LOOP;
END;