Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Freeware: Oracle Database Y2K Protection (Part II Rest of Code))

Freeware: Oracle Database Y2K Protection (Part II Rest of Code))

From: <carl_cribbs_at_my-deja.com>
Date: Tue, 22 Jun 1999 21:57:21 GMT
Message-ID: <7kp0rq$ld4$1@nnrp1.deja.com>


If the code I sent is helpful, please let me know so I can impress my management (jicbayr_at_ifx.net)

Attachment Number 3
Y2K_EXISTING_TRIGGER_UPGRADE.SQL SET ECHO OFF
SET LINESIZE 132
SET SERVEROUTPUT On SIZE 1000000
SET FEEDBACK OFF
SET SHOWMODE OFF
SET TERM OFF
SET HEADING OFF
SET LONG 100000
SET ARRAYSIZE 10
--






--

--
--

spool y2k_trigger_upgrade_code.sql
--
--

DECLARE
--




--

   CURSOR build_date_columns

      (
         table_date_columns
sys.dba_tab_columns.table_name%TYPE
      ) IS
      SELECT
         column_name
      FROM
         sys.dba_tab_columns
      WHERE
         owner      = '<OWNER>'
         AND
         table_name = table_date_columns
         AND
         data_type  = 'DATE';


--------------------------------------------------
------------------------------
--

   CURSOR build_update_columns_string

      (
         table_update_columns
sys.dba_trigger_cols.table_name%TYPE,
         update_of_trigger_name
sys.dba_trigger_cols.trigger_name%TYPE
      ) IS
      SELECT
         column_name
      FROM
         sys.dba_trigger_cols
      WHERE
         table_name    = table_update_columns
         AND
         trigger_name  = update_of_trigger_name
         AND
         trigger_owner = '<OWNER>'
         AND
         table_owner   = trigger_owner
         AND
         column_list  = 'YES';


--------------------------------------------------
------------------------------
--

   CURSOR existing_tiggers

      (
         table_with_date
sys.dba_tab_columns.table_name%TYPE
      ) IS
      SELECT
         table_name,
         owner,
         trigger_name,
         trigger_type,
         triggering_event,
         table_owner,
         referencing_names,
         when_clause,
         status,
         description,
         trigger_body
      FROM
         sys.dba_triggers
      WHERE
         table_name        = table_with_date
         AND
         owner             = '<OWNER>'
         AND
         trigger_type      = 'BEFORE EACH ROW'
         AND
         trigger_name NOT LIKE 'RR_%'
       ORDER BY table_name;


--------------------------------------------------
------------------------------
--

   CURSOR tables_with_dates IS

      SELECT DISTINCT
         table_name
      FROM
         sys.dba_tab_columns
      WHERE
         owner     = '<OWNER>'
         AND
         data_type = 'DATE';


--------------------------------------------------
------------------------------
-----
----- Variables
-----
--------------------------------------------------
------------------------------
-----

       var_beginning_of_line INTEGER;

       var_end_of_line INTEGER;

       var_length_trigger_string INTEGER;

       var_str_column VARCHAR2(1000);

       var_str_row                 VARCHAR2(132);

       var_trigger_type            VARCHAR2(100);


--------------------------------------------------
------------------------------
--------------------------------------------------
------------------------------
--

BEGIN
   FOR table_loop
   IN tables_with_dates
   LOOP











         DBMS_OUTPUT.PUT_LINE ( '/*' );
         DBMS_OUTPUT.PUT_LINE (

'_________________________________________________
________'
            || '_______________________' );
         DBMS_OUTPUT.PUT_LINE ( '| Name   |  Date
|   Comment' );
         DBMS_OUTPUT.PUT_LINE (

'_________________________________________________
________'
            || '_______________________' );
         DBMS_OUTPUT.PUT_LINE (
            '| Cribbs | ' || TO_CHAR( SYSDATE,
'DD-MON-YYYY')
            || ' | Added Y2K protection to date
fields' );
         DBMS_OUTPUT.PUT_LINE (

'_________________________________________________
________'
            || '_______________________' );
         DBMS_OUTPUT.PUT_LINE ( '*/' );


--------------------------------------------------
------------------------------
--------
-------- BEGINNING OF TRIGGER'S CODE
--------
--------------------------------------------------
------------------------------

--------------------------------------------------
------------------------------
--------------------------------------------------
------------------------------
--------
'_________________________________________________
________'
            || '_______________________' );
         DBMS_OUTPUT.PUT_LINE (

'_________________________________________________
________'
            || '_______________________' );
         DBMS_OUTPUT.PUT_LINE (
            'Beginning of the new outer block to
encompass the added Y2K' );
         DBMS_OUTPUT.PUT_LINE ( 'conversion code
and the original code.' );
         DBMS_OUTPUT.PUT_LINE (

'_________________________________________________
________'
            || '_______________________' );
         DBMS_OUTPUT.PUT_LINE (

'_________________________________________________
________'
            || '_______________________' );
         DBMS_OUTPUT.PUT_LINE ( '*/' );
         DBMS_OUTPUT.PUT_LINE ( 'BEGIN' );  --
Beginning of outer block
         DBMS_OUTPUT.PUT_LINE ( '/*' );     --
Outer block comment text
         DBMS_OUTPUT.PUT_LINE (

'_________________________________________________
________'
            || '_______________________' );
         DBMS_OUTPUT.PUT_LINE (

'_________________________________________________
________'
            || '_______________________' );
         DBMS_OUTPUT.PUT_LINE ( 'Inserted Y2K
conversion code.' );
         DBMS_OUTPUT.PUT_LINE (
            'Convert "NEW" date value to be Y2K
complaint.' );
         DBMS_OUTPUT.PUT_LINE (

'_________________________________________________
________'
            || '_______________________' );
         DBMS_OUTPUT.PUT_LINE (

'_________________________________________________
________'
            || '_______________________' );
         DBMS_OUTPUT.PUT_LINE ( '*/' );


--------------------------------------------------
------------------------------
--------------------------------------------------
------------------------------
--------
-------- BEGINNING OF THE Y2K CONVERSION BLOCK
--------
--------------------------------------------------
------------------------------
--------------------------------------------------
------------------------------
DBMS_OUTPUT.PUT_LINE ( CHR (9) || 'BEGIN'
); -- Beginning of

         FOR date_cols IN build_date_columns ( modification_loop.table_name )

         LOOP
            DBMS_OUTPUT.PUT_LINE
               (
               CHR (9) || '   IF :NEW.' || LOWER(
date_cols.column_name )
               || ' IS NOT NULL '
               );
            DBMS_OUTPUT.PUT_LINE ( CHR (9) || '
THEN' );
            DBMS_OUTPUT.PUT_LINE
               (
               CHR (9) || '      :NEW.' || LOWER(
date_cols.column_name )
               || ' := ' || 'rr_date_conversion(
:NEW.'
               || LOWER( date_cols.column_name )
|| ' );'
               );
            DBMS_OUTPUT.PUT_LINE ( CHR (9) || '
END IF;' );
            DBMS_OUTPUT.PUT_LINE ( '--' );
         END LOOP;


--------
'_________________________________________________
________'
            || '_______________________' );
         DBMS_OUTPUT.PUT_LINE (

'_________________________________________________
________'
            || '_______________________' );
         DBMS_OUTPUT.PUT_LINE ( 'Beginning of
original code.' );
         DBMS_OUTPUT.PUT_LINE (

'_________________________________________________
________'
            || '_______________________' );
         DBMS_OUTPUT.PUT_LINE (

'_________________________________________________
________'
            || '_______________________' );
         DBMS_OUTPUT.PUT_LINE ( '*/' );


--------------------------------------------------
------------------------------
--------------------------------------------------
------------------------------
--------
-------- ORIGINAL TRIGGER CODE
--------
--------------------------------------------------
------------------------------
--------------------------------------------------
------------------------------
var_beginning_of_line := 1; var_end_of_line := 0; var_length_trigger_string := LENGTH (
modification_loop.trigger_body );

         WHILE var_end_of_line <
var_length_trigger_string

         LOOP


modification_loop.trigger_body,

                                      CHR( 10 ),

var_beginning_of_line
                                      );

modification_loop.trigger_body,

var_beginning_of_line,

                                  var_end_of_line
- var_beginning_of_line
                                  );


--------------------------------------------------
------------------------------



            SELECT NULL INTO var_str_row FROM DUAL;             var_beginning_of_line :=
var_end_of_line + 1;

         END LOOP;






'_________________________________________________
________'
            || '_______________________' );
         DBMS_OUTPUT.PUT_LINE (

'_________________________________________________
________'
            || '_______________________' );
         DBMS_OUTPUT.PUT_LINE (
            'End of the new outer block to
encompass the inserted Y2K' );
         DBMS_OUTPUT.PUT_LINE ( 'date conversion
code and the original code.' );
         DBMS_OUTPUT.PUT_LINE (

'_________________________________________________
________'
            || '_______________________' );
         DBMS_OUTPUT.PUT_LINE (

'_________________________________________________
________'
            || '_______________________' );
         DBMS_OUTPUT.PUT_LINE ( '*/' );
         DBMS_OUTPUT.PUT_LINE ( 'END;' );
         DBMS_OUTPUT.PUT_LINE ( '/' );     --
Trigger's terminating slash
      END LOOP;

   END LOOP;    ROLLBACK; END;
.
/
--
--

SPOOL OFF
--

SET ARRAYSIZE 15
SET LONG 80
SET SERVEROUTPUT OFF
SET FEEDBACK On
SET SHOWMODE On
SET TERM On
SET HEADING On
SET ECHO On

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't. Received on Tue Jun 22 1999 - 16:57:21 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US