I am trying to wring a pl/sql script that will check every value for every column and every row for trailing whitespace.
My plan is to get the column and table name for my app from dba_tab_cols, then loop through each row of that table on that column and check for trailing whitespace and trim if needed.
My problem is that this requires my inner loop to have to update the table it is selecting from and am finding that such an action is not supported. I'm not sure if there is a way around this or another method I should consider. Every path I explore ends up at the same problem: I have to update the table the inner loop is selecting from.
My pseudocode is below:
BEGIN
for i in
(
--get table name and column name for all tables from MYAPP
select table_name, column_name from dba_tab_cols where owner='MYAPP'
)
LOOP
BEGIN
for k in
(
-- for each column in each table returned from outer loop, loop through each row and check for trailing whitespace
select i.column_name from MYAPP.i.table_name -- I know this is wrong, not sure what should go here
)
LOOP
-- compare value of column with value of trim(column)
-- if different then fix
END LOOP;
END;
END LOOP;
END;
/
EDIT: One requirement is to identify and print out the offending values so a simple update statement is not enough. I have been trying to understand sys_refcursor because it seems like that might be what I need but I'm strugging to get a grasp on it.