Instruction
Great! Since we have implemented the custom logging function and already know the structure of the tables we'll be working with, we can move on the next exercise, where we'll implement a new ETL process: loading new customers.
Exercise
Implement a new ETL process that loads customers from the staging area (the stg_customer table) into the dim_customer table.
The new ETL process will be encapsulated in a function named load_customers() that takes no parameters and performs the following steps:
-
Logs a new message stating that the ETL process started. Using the
PERFORMcommand andlog_message()function, it should pass the following arguments:Parameter Value p_process_name 'load_customers()' p_message_text 'ETL process Load Customers Started' p_level 'info' - If there is a record for which
stg_customer.idanddim_customer.idmatch, the function should update that existing record in thedim_customertable with the new data coming from thestg_customertable. -
Logs a new message stating how many customers have been updated. Using the
PERFORMcommand andlog_message()function, pass in the following arguments:Parameter Value p_process_name 'load_customers()' p_message_text 'Updated Customers: {x}' p_level 'info' Where
{x}is the number of updated customers. - For each row where
stg_customer.idcolumn isNULL, the function should insert a new record into thedim_customertable. -
Logs a new message stating how many new customers have been inserted. Using the
PERFORMcommand andlog_message()function, pass in the following arguments:Parameter Value p_process_name 'load_customers()' p_message_text 'Inserted Customers: {x}' p_level 'info' Where
{x}is the number count of inserted customers. - Removes all rows from the
stg_customertable. -
Logs a new message saying stating that the ETL process finished. Using the
PERFORMcommand and functionlog_message()function and pass in the following arguments:Parameter Value p_process_name 'load_customers()' p_message_text 'ETL process Load Customers Finished' p_level 'info'
Note: The text values in all three columns (title, first_name, last_name) that you're updating/inserting in the dim_customer table should have an initial capital letter.
To retrieve the number of inserted/updated rows, use:
GET DIAGNOSTICS your_variable = ROW_COUNT;
Stuck? Here's a hint!
Use the built-in INITCAP() function to force the first letter of a word to be uppercase.



