How to import a higher TZ dump file into a lower TZ database [message #689950] |
Wed, 14 August 2024 13:28 |
|
Olexandr Siroklyn
Messages: 41 Registered: September 2018 Location: USA
|
Member |
|
|
A kind of hack.
a. Obtain a list of the import related tables so that you can delete them to ensure that a new import job starts with the SYS_IMPORT_FULL_01 table. SYS account is required.
SQL> select 'drop table '||OWNER||'.'||TABLE_NAME||';' from DBA_TABLES where TABLE_NAME like '%IMPORT_FULL%';
b. Adjust the PL/SQL code below where l_wrongTZ is a TZ number of the dump file and l_correctTZ is a TZ number of the database. Run the PL/SQL code in a SQL*Plus session in a separated terminal. SYS account is required.
declare
l_imptablename varchar2(64) := 'SYS_IMPORT_FULL_01';
l_imptableowner varchar2(12) := '';
l_cnt simple_integer := 0;
l_wrongTZ simple_integer := 41;
l_correctTZ simple_integer := 35;
begin
while (l_wrongTZ = l_wrongTZ)
loop
begin
select count(*) into l_cnt from DBA_TABLES where TABLE_NAME=l_imptablename;
if (l_cnt = 1)
then
select OWNER into l_imptableowner from DBA_TABLES where TABLE_NAME=l_imptablename;
while (l_wrongTZ = l_wrongTZ)
loop
begin
execute immediate 'select count(*) from '||l_imptableowner||'.'||l_imptablename||' where property='||to_char(l_wrongTZ) into l_cnt;
if (l_cnt = 1)
then begin
execute immediate 'update '||l_imptableowner||'.'||l_imptablename||' set property='||to_char(l_correctTZ)||' where property='||to_char(l_wrongTZ);
commit;
dbms_output.put_line('TZ info has been updated in '||upper(l_imptableowner)||'.'||upper(l_imptablename));
goto l_exit;
end;
else
dbms_lock.sleep(0.1);
end if;
end;
end loop;
end if;
end;
end loop;
<<l_exit>>
l_wrongTZ:=l_wrongTZ;
end;
c. Run impdp utility as usual
d. "TZ info has been updated ...." message means hack is applied.
e. impdp process should go smoothly
|
|
|
|
|
Re: How to import a higher TZ dump file into a lower TZ database [message #689956 is a reply to message #689951] |
Fri, 16 August 2024 05:25 |
cookiemonster
Messages: 13946 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
You know
while (l_wrongTZ = l_wrongTZ)
is always true right?
I'm not sure why you've written any loops there as it exits as soon as it finds something to update, and if it doesn't find anything with the wrong timezone type it'll infinite loop.
Looks to me like the whole thing reduces to this:
DECLARE
l_imptableowner varchar2(100);
begin
SELECT owner
INTO l_imptableowner
FROM dba_tables
WHERE table_name = 'SYS_IMPORT_FULL_01';
UPDATE SYS_IMPORT_FULL_01
SET property = '35'
WHERE property = '41';
IF sql%rowcount > 0 THEN
dbms_output.put_line('TZ info has been updated in '||upper(l_imptableowner)||'.SYS_IMPORT_FULL_01';
END IF;
END;
The code in your 2nd post reduces as well - for loops are wonderful things and you don't need to use obscure functions to check datatypes when you can just query dba_tab_cols:
begin
FOR rec IN (SELECT distinct table_name
FROM dba_tab_cols
where owner = '<owner>'
and data_type like 'TIMESTAMP% WITH TIME ZONE') LOOP
dbms_output.put_line(rec.table_name);
end loop;
end;
[Updated on: Fri, 16 August 2024 08:50] Report message to a moderator
|
|
|
|
|
|