Question: Now you will use the following steps to create a function that inserts a new customer record including the associated name. The function will need

  1. Now you will use the following steps to create a function that inserts a new customer record including the associated name. The function will need to update three tables; the CUSTOMER, CNAME, and CUSTOMER_NAME tables. The function then returns the numeric value of the IDCUSTOMER for the new customer table entry:

fn_insertCustomer (birthdate, password, firstname, lastname)

  1. Create three sequences: CUSTOMER_SEQ, and CNAME_SEQ, and CN_SEQ that increment by 1. (Have each start 1 past the current maximum in the existing data in the table hard code the starting value)
    1. The function should use the CUSTOMER_SEQ to generate the IDCUSTOMER value.
    2. The function should use the CNAME_SEQ to generate the key value for the CNAME table (even if both the firstname and lastname values are NULL).
    3. The function should use the CN_SEQ to generate the key value for the CUSTOMER_NAME table.
  2. The value of the STARTDATE field in the CUSTOMER_NAME table should be the current SYSDATE.
  3. The value of the ENDDATE field in the CUSTOMER_NAME table should be NULL to indicate that this is the currently valid name.
  4. Provide screenshots showing the successful running of your function.

  1. Use SQL Developer to create a VIEW that contains the IDCUSTOMER, birthdate, password, firstname, and current lastname.
    1. Name the view CUSTOMER_VIEW.
    2. Identify the current name by looking for the entry where the ENDDATE is NULL.

  1. Once the view has been created, create an INSTEAD OF trigger on the CUSTOMER_VIEW to allow updates to the customers name, while maintaining the history of previous names; by following these criteria:
    1. The trigger should be invoked for INSERTs or UPDATEs.
    2. The trigger should update the CUSTOMER_NAME table entry that matches the IDCUSTOMER and has the ENDDATE as NULL, to have the current SYSDATE as the ENDDATE.
    3. The trigger should use the CNAME_SEQ sequence and insert a new record into the CNAME table.
    4. The trigger should use the CN_SEQ sequence to insert a new record into the CUSTOMER_NAME table. The new record should link the new CNAME record to the existing CUSTOMER record; using the current SYSDATE as the STARTDATE, and also setting ENDATE to the value NULL to indicate that the new name is the currently valid name.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!