Rem Filename   : header_dbinfo.sql
Rem 
Rem Parameters : &1 = length of separator lines, if 0 or a negative value is specified, then
Rem                   no separator lines are displayed.
Rem              &2 = content indicator : D   = database identification
Rem                                       DC  = database identification + current date and time
Rem                                       DS  = database identification + startup date and time
Rem                                       DCS = database identification + current date and time
Rem                                             + startup date and time
Rem
Rem Author     : 
Rem RDBMS      : Oracle V8.x, V9.x
Rem
Rem Modification history
Rem --------------------
Rem 28-Aug-2002  Initial creation.
Rem
Rem ====================================================================================================
Rem
Rem Description : Displays a database identification header.
Rem
Rem Sample output
Rem -------------
Rem MXXXXXXX<GLORYETL> @@header_dbinfo 100 DCS
Rem
Rem ----------------------------------------------------------------------------------------------------
Rem Database              : GLORYETL on server beahs661640
Rem Startup date and time : 27-AUG-2002 05:51:14  ( uptime = 1 days, 8 hours and 40 minutes )
Rem Current date and time : 28-AUG-2002 14:31:22
Rem ----------------------------------------------------------------------------------------------------
Rem
Rem ====================================================================================================

SET SERVEROUTPUT  ON

declare
  v_inst_name       varchar2(30);
  startup_time      date;
  v_host_name       varchar2(100);
  uptime            number;
  uptime_days       number;
  uptime_hours      number;
  uptime_minutes    number;

begin
  SELECT instance_name, startup_time, host_name
    INTO v_inst_name, startup_time, v_host_name
    FROM v$instance;

  uptime := sysdate - startup_time;
  uptime_days := trunc(uptime);
  uptime_hours := trunc((uptime - uptime_days)*24);
  uptime_minutes := trunc((uptime - ( uptime_days + uptime_hours/24 ))*60*24);

  if ( 107 > 0 ) then dbms_output.put_line( chr(10) || rpad( '-', 107, '-' ) ); end if;
  dbms_output.put_line( 'BBDD              : ' || v_inst_name || ' en el servidor ' || v_host_name );
  if ( instr( 'DC', 'S' ) > 0 ) then
    dbms_output.put_line( 'Startup date and time : ' || to_char( startup_time, 'DD-MON-YYYY HH24:MI:SS')
                                                     || '  ( uptime = ' || trunc(uptime) || ' days, ' 
                                                     || uptime_hours || ' hours and '
                                                     || uptime_minutes || ' minutes )');
  end if;
  if ( instr( 'DC', 'C' ) > 0 ) then
    dbms_output.put_line( 'Fecha actual      : ' || to_char( SYSDATE, 'DD-MON-YYYY HH24:MI:SS' ) );
  end if;
  if ( 107 > 0 ) then dbms_output.put_line( rpad( '-', 107, '-' ) ); end if;
end;
/
