Modified

 -- Update modified records in master table

MERGE INTO $master_table m

USING (

    SELECT DISTINCT

        child_correlation_id,

        parent,

        parent_sys_class_name,

        child_sys_class_name,

        child_u_cmdb_ci_used_for,

        parent_correlation_id,

        type,

        child,

        modified_date

    FROM $child_table

) c

ON (m.child_correlation_id = c.child_correlation_id)

WHEN MATCHED THEN

UPDATE SET 

    m.parent = c.parent, 

    m.parent_sys_class_name = c.parent_sys_class_name,

    m.child_sys_class_name = c.child_sys_class_name,

    m.child_u_cmdb_ci_used_for = c.child_u_cmdb_ci_used_for, 

    m.parent_correlation_id = c.parent_correlation_id, 

    m.type = c.type, 

    m.child = c.child, 

    m.modified_date = SYSDATE

WHERE 

    m.parent != c.parent OR 

    m.parent_sys_class_name != c.parent_sys_class_name OR

    m.child_sys_class_name != c.child_sys_class_name OR 

    m.child_u_cmdb_ci_used_for != c.child_u_cmdb_ci_used_for OR 

    m.parent_correlation_id != c.parent_correlation_id OR 

    m.type != c.type OR 

    m.child != c.child;


-- Log updated rows

SPOOL $updated_rows_file

SELECT

    c.parent,

    c.parent_sys_class_name,

    c.child_sys_class_name,

    c.child_u_cmdb_ci_used_for,

    c.parent_correlation_id,

    c.type,

    c.child_correlation_id,

    c.child,

    c.modified_date

FROM $child_table c

JOIN $master_table m ON c.child_correlation_id = m.child_correlation_id

WHERE

    m.parent != c.parent OR

    m.parent_sys_class_name != c.parent_sys_class_name OR

    m.child_sys_class_name != c.child_sys_class_name OR

    m.child_u_cmdb_ci_used_for != c.child_u_cmdb_ci_used_for OR

    m.parent_correlation_id != c.parent_correlation_id OR

    m.type != c.type OR

    m.child != c.child;

SPOOL OFF;

Comments

Popular posts from this blog

SQL Loader V3

Db Unix

Standby redo log add