473,545 Members | 2,639 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to search all columns of all tables in a database for a keyword?

2 New Member
Dear Team,

i have an requirement that : i want to search all the columns of all the tables in the particular database based on the specific key word or an free text.

example :

table 1: columns data
empname sam
empid 01

table 2 columns data
deptname sam
departmentid 10

table 3 columns data
organization name sam
organization id 1

when i search for text " SAM"

it should search me from the entire database, all tables and columns of it and display the result

output : tablename cloumn value
table1 empname sam
table2 deptname sam
table3 organizationame sam

the example is just an sample not the real data .

please help me with sample code or any link related to it .


thanks in advance
Dec 14 '08 #1
4 15757
debasisdas
8,127 Recognized Expert Expert
you need to use cursor for that using a number of OR conditions.
Dec 14 '08 #2
Pilgrim333
127 New Member
Hi,

You can also try to write a procedure to do this for you. I think this would be easier. Make use of the all_tables view etc.

Pilgrim.
Dec 14 '08 #3
abdulgani
2 New Member
Can you please provide any link that will help me out or any code . thanx in advance
Dec 15 '08 #4
amitpatel66
2,367 Recognized Expert Top Contributor
The following code would help you to proceed further. It works fine for columns of data type number,varchar, char etc but not for LONG.

You will need to check the following:

1. If you want to check for all the tables of a database then you need to make sure that SELECT for all the tables is GRANTED to the schema from where you are running this code
2. Convert LONG TO VARCHAR explicitly and then do the comparison.

Expand|Select|Wrap|Line Numbers
  1. declare
  2. cursor c1 is select table_name from all_tables WHERE owner = (SELECT user FROM dual);
  3. col_names SYS_REFCURSOR;
  4. TYPE dat_res IS RECORD(tab_name VARCHAR2(100),col_name VARCHAR2(100));
  5. TYPE dr is table of dat_res;
  6. act_dat dr:= dr();
  7. status NUMBER := 0;
  8. cnt NUMBER := 1;
  9. sql_stmt VARCHAR2(10000);
  10. tab_name1 VARCHAR2(100);
  11. col_name1 VARCHAR2(100);
  12. BEGIN
  13. FOR I IN C1 LOOP
  14. sql_stmt:= 'SELECT table_name,column_name FROM all_Tab_cols WHERE table_name = '||CHR(39)||I.table_name||CHR(39);
  15. OPEN col_names FOR sql_stmt;
  16. LOOP
  17. FETCH col_names INTO tab_name1,col_name1;
  18. EXIT WHEN col_names%NOTFOUND;
  19. BEGIN
  20. EXECUTE IMMEDIATE 'SELECT 1 FROM '||tab_name1|| ' WHERE '||'TO_CHAR('||col_name1||') LIKE '||CHR(39)||'BCD'||CHR(39) INTO status;
  21. EXCEPTION
  22. WHEN NO_DATA_FOUND THEN
  23. NULL;
  24. WHEN OTHERS THEN
  25. DBMS_OUTPUT.PUT_LINE('Error In table: '||tab_name1||' Column:'||col_name1||' '||SQLERRM);
  26. END;
  27. IF (status = 1) THEN
  28. act_dat.extend;
  29. act_dat(cnt).tab_name:= tab_name1;
  30. act_dat(cnt).col_name:= col_name1;
  31. status := 0;
  32. cnt:= cnt + 1;
  33. END IF;
  34. END LOOP;
  35. CLOSE col_names;
  36. END LOOP;
  37. dbms_output.put_line('Table Name : Column Name');
  38. FOR K IN act_dat.FIRST..act_dat.LAST LOOP
  39. dbms_output.put_line(act_dat(K).tab_name||' : '||act_dat(K).col_name);
  40. END LOOP;
  41. END;
  42.  
  43. SQL> /
  44. Error In table: PLAN_TABLE Column:OTHER ORA-00932: inconsistent datatypes: expected CHAR got LONG
  45. Error In table: PLAN_TABLE Column:OTHER ORA-00932: inconsistent datatypes: expected CHAR got LONG
  46. Table Name : Column Name
  47. EMP : EMPNAME
  48. EMP1 : EMPNAME
  49.  
  50. PL/SQL procedure successfully completed.
  51.  
  52. SQL> 
  53.  
  54.  
If you see above , it list the tables that were errored out due to column datatype LONG and the list of tables that contain the value 'BCD'

Just BUILD on this and create your code as per your requirement
Dec 15 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2096
by: Millie Niss | last post by:
I am new to PHP and mySQL, and I am trying to build a database of services (on a service table) provided by agencies (another table), where one agency can provide many services, but a service belongs to a single agency. There are about 10 fields in the services table, including a comments field which needs to be searchable. I don't know how...
1
7375
by: Nikola Pecigos | last post by:
Hi, I have the following problem: We have an Oracle 9.2 with one table "document" which contains a path to the filesystem. If I want to index these files (HTML, PDF, World, Excel, etc.), I have to use the datastore type "FILE_DATASTORE". Another table "lng_text" stores the titles and descriptions for multiple languages for each row in...
2
2626
by: Ryan | last post by:
I'm looking for a stored procedure (or query) to search an entire database for a specific string value and replace it with another. I'm sure I saw an SP for this a while back by someone, but cannot find it again. The SP took the search string and replace string as parameters and did the rest. Any ideas where I can find this ? Bear in mind,...
2
7685
by: Teknik & System | last post by:
Hi, I need to search all tables and all records in a large database (v. 7.2) for at text string. Are there any _easy_ ways of doing this? TIA! Jakob
4
12965
by: Gobi | last post by:
Hello, I have a Database with lists of Clients in each. Every year a new tables is created with the naming convention "CloseYear" ie close1999, close2000 There are tables from this year back to 1989. I need to be able to 1) Go to a Search for 2) Enter Criteria -(Client_Last_Name) (Client_First_Name) (File_Number)
3
1365
by: wsnyder3 | last post by:
I am trying to create a search where the user can type in a word and if there are any matching word(s) on any table that it will display the tables matches. I am not real familiar with Access I am still learning. If anyone has any ideas of how to accomplish this it would be greatly appreciated. Thank you -D
1
11661
by: atl10spro | last post by:
Hello Everyone, I am new to MS Access and although I have created several different databases I lack the VB knowledge to code a search function. I am turning to your expertise for assistance. I am using MS Access 2003. This is what I am looking for: A text field for the user to enter the search string or keyword.
2
1138
by: Sid Price | last post by:
I have an application that has already been deployed and we need to add a new column to some of the tables in the application database. We are using an access database. We have a solution working that basically opens a dataset for each of the tables that needs updating, this dataset selects all rows with the new column and the exception that...
0
1517
by: SamKhazary | last post by:
I have created a database that has a main table with a description of different products. I have 5 other data bases that are linked sheets that have returns for the 5 different prduct groups. I'd like to have a query run and pull in all the products with their respective return. Is there a way to have it search for the same field on multiple...
0
7490
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7682
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7935
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7780
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5351
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3479
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3465
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1037
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.