Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

First : Create a user-defined function (F_CONVERT_TO_EURO) to do the following:

ID: 3772067 • Letter: F

Question

First : Create a user-defined function (F_CONVERT_TO_EURO) to do the following:

Convert a Canadian dollar amount to a Euro amount. You can use the conversion formula 1 CDN Dollar = 0.72 Euros.

The input and output need to be DECIMAL types but you can use whatever size of DECIMAL you want as long as you have 2 decimal places.

    Second : Create a store procedure (P_STAFF_COSTS_EURO) that selects Name, Department, Salary and Comm from the Staff table into a cursor.     Sum up Salary and Comm for each Name and Department and convert those values to Euro and return records (hint return the cursor) from the stored procedure.

Explanation / Answer

A user-defined function (F_CONVERT_TO_EURO):

CREATE FUNCTION F_CONVERT_TO_EURO(DOUBLE)

       RETURNS DOUBLE

       EXTERNAL NAME 'MYLIB/CURRENCIES(F_CONVERT_TO_EURO)'

       LANGUAGE C

       PARAMETER STYLE DB2SQL

       NO SQL

       NOT DETERMINISTIC

      

     CREATE FUNCTION F_CONVERT_TO_EURO (DECIMAL(9,2))

       RETURNS DECIMAL(9,2)

       SOURCE F_CONVERT_TO_EURO (DOUBLE)

     CREATE FUNCTION CANDIAN_DOLLAR(EURO) RETURNS CANDIAN_DOLLAR