Home » RDBMS Server » Server Utilities » How to import a higher TZ dump file into a lower TZ database (19c, below and higher than 19c)
How to import a higher TZ dump file into a lower TZ database [message #689950] Wed, 14 August 2024 13:28 Go to next message
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 #689951 is a reply to message #689950] Wed, 14 August 2024 13:44 Go to previous messageGo to next message
Olexandr Siroklyn
Messages: 41
Registered: September 2018
Location: USA
Member
Almost forgot. Before taking above actions, it is a good idea to check what data will be affected. Obviously it's about data type "TIMESTAMP WITH TIME ZONE".

declare
	l_object_id simple_integer:=0;
	l_table_name string(128):='';
	l_tstz_presence char(1):='';
	cursor l_cursor is 
		 select OBJECT_ID, OBJECT_NAME 
	           from dba_objects 
		  where OWNER='schema-name-is-here' 
		    and OBJECT_TYPE='TABLE'
	  	  order by OBJECT_NAME;
		
begin
	open l_cursor;
	loop
	fetch l_cursor into l_object_id, l_table_name;
	exit when l_cursor%NOTFOUND;
	l_tstz_presence:=sys.dbms_metadata_util.has_tstz_cols(l_object_id);
        if (l_tstz_presence) = 'Y' 
	then
	    dbms_output.put_line(l_table_name||':'||l_tstz_presence);
	end if;	
	end loop;
	close l_cursor;
end;
Re: How to import a higher TZ dump file into a lower TZ database [message #689955 is a reply to message #689950] Fri, 16 August 2024 05:19 Go to previous messageGo to next message
John Watson
Messages: 8954
Registered: January 2010
Location: Global Village
Senior Member
This may well be a very useful hack. THank you, I shall remember it.
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 Go to previous messageGo to next message
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

Re: How to import a higher TZ dump file into a lower TZ database [message #689964 is a reply to message #689956] Sat, 17 August 2024 09:06 Go to previous messageGo to next message
Olexandr Siroklyn
Messages: 41
Registered: September 2018
Location: USA
Member
Dear cookiemonster,

The hack code is completely disposable.
Re: How to import a higher TZ dump file into a lower TZ database [message #689965 is a reply to message #689964] Mon, 19 August 2024 03:40 Go to previous messageGo to next message
cookiemonster
Messages: 13946
Registered: September 2008
Location: Rainy Manchester
Senior Member
Disposable code is no excuse for coding infinite loops.
Re: How to import a higher TZ dump file into a lower TZ database [message #689966 is a reply to message #689965] Mon, 19 August 2024 09:06 Go to previous message
Olexandr Siroklyn
Messages: 41
Registered: September 2018
Location: USA
Member
I'm gonna print out this precious wisdom, frame it, and read it every morning.
Previous Topic: Not able to run expdp
Goto Forum:
  


Current Time: Sat Oct 12 14:00:33 CDT 2024