Last active
September 13, 2024 12:21
-
-
Save felclef/1357982 to your computer and use it in GitHub Desktop.
Atualizando um campo no banco todo.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare | |
cursor c_sql_stmt is | |
select | |
cl.table_name, | |
cl.column_name, | |
'UPDATE '||cl.table_name||' set '||cl.column_name||' = :1 where regexp_like('||cl.column_name||', :2, ''i'')' as cmd | |
from | |
user_tab_columns cl | |
inner join user_tables tb | |
on tb.table_name = cl.table_name | |
where | |
regexp_like(cl.column_name, 'codmat', 'i') | |
and cl.data_type = 'CHAR'; | |
codigo_antigo varchar2(40) := 'MOLDET7035'; | |
codigo_novo varchar2(40) := 'MOLDET7035'; | |
begin | |
for sql_stmt in c_sql_stmt loop | |
begin | |
dbms_output.put_line('Atualizando '||sql_stmt.table_name||'.'||sql_stmt.column_name||' ...'); | |
execute immediate sql_stmt.cmd using codigo_novo, codigo_antigo; | |
dbms_output.put_line('... Atualizado!'); | |
exception | |
when others then | |
dbms_output.put_line('... '||sqlerrm); | |
end; | |
end loop; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment