I want to return a list of all table names of a row in that table contains like specific value "%searchString%"
I have seen similar questions in the form but couldn't fine one related to oracle database "i am using sqldeveloper to connect". I am not an expert to know how to map the script from one environment to another.
I am able to get the list of all available tables by
SELECT table_name FROM all_tables
And I am able to get the list of all column names for a specific table by
SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS WHERE TABLE_NAME='tableName'
Pseudo Code
result = [] #empty list
searchString = "desiredString"
tableNames = getTableNames() #all tables in DB
for (int i = 0; i < tableNames.length; i++){
match = false
tableRows = # list containing all rows of that table
columnNames = # list of all column names of that table
for (int j = 0; j< tableRows.length; j++){
for (int k = 0; k<columnName.length ; k++){
if(tableNames[i].tableRows[j].columnNames[k].value.contains(searchString)){
match = true
break
}
if (match == true) break
}
if(match == true) result.append(tableNames[i])
}
print result
Thanks to comments below, I was able to combine some solutions and it is working fine as below
variable val varchar2(255)
exec :val := 'oldDomain.com'
WITH char_cols AS
(SELECT /*+materialize */ table_name, column_name
FROM cols
WHERE data_type IN ('CHAR', 'VARCHAR2'))
SELECT DISTINCT SUBSTR (:val, 1, 11) "Searchword",
SUBSTR (table_name, 1, 14) "Table",
SUBSTR (column_name, 1, 14) "Column"
FROM char_cols,
TABLE (xmlsequence (dbms_xmlgen.getxmltype ('select "'
|| column_name
|| '" from "'
|| table_name
|| '" where upper("'
|| column_name
|| '") like upper(''%'
|| :val
|| '%'')' ).extract ('ROWSET/ROW/*') ) ) t
ORDER BY "Table"
/
ok the idea is I want to replace this value for a new one.
let's say that I want to replace "oldDomain.com" to "newDomain.com"