Question

In: Computer Science

Note: There is no database to test against FactoryUsers WorkerId Number(4) Not Null [PK] WorkerName Varchar2(20)...

Note: There is no database to test against

FactoryUsers
WorkerId Number(4) Not Null [PK]
WorkerName Varchar2(20)
CreatedDate DATE
CreatedBy Varchar2(20)

Create a stored procedure (SP) called Add_Worker that will add an employee to a factory. This SP has two parameters:

a) A parameter (WorkerId) that the SP can read or write to. When the procedure is called it will contain the PK value that should be used to add the row.

b) A parameter (WorkerName) that the SP can read only, it contains the new worker's username.

c) A parameter (Result) that the SP can write to. If the new record is added successfully, the parameter will be set to the value 'Entered Successfully'. If the add fails the parameter is set to the value 'Unsuccessful'.

Declare an exception named WORKER_NOT_ADDED. Associate the number -20444 with this exception.

Execute an insert statement to add the row to the table. Use the values of the passed parameters on the insert statement. Today's date should be used for the Created_date column. Use 'abcuser' for the CreatedBy column.

If the workerID is added:

a) Set the parameter 'Result' to 'Entered Successfully'

b) Commit the changes

Next, add exception processing to the SP

a) For all exceptions, set the parameter 'Result' to 'Unsuccessful'

b) If the WORKER_NOT_ADDED exception occurs, display the message 'New WorkerId already exists on the table.'

c_ For any other error, display the error number and the message associated with that error number.

Solutions

Expert Solution

The code snippet for the stored procedure Add_Worker is attached below, the code is documented and relevant information is available at the end.

--Drop the procedure if it already exists

DROP PROCEDURE IF EXISTS Add_Worker;

DELIMITER $$

--creating procedure Add_Worker

CREATE PROCEDURE Add_Worker(
    IN WorkerId INT(4), 
    IN WorkerName varchar(20),
    OUT Result varchar(20)
)
BEGIN

    -- error handling
    -- exit if the duplicate key occurs

    DECLARE CONTINUE HANDLER FOR 1062

    BEGIN
        SELECT CONCAT('Duplicate key (',WorkerId,') occurred') AS message;
    SET Result = "Unsucessful";
    END;
    
    -- insert a new row into the Worker Table

    INSERT INTO Worker(WorkerId,WorkerName,CreatedDate,CreatedBy)
    VALUES(WorkerId,WorkerName,NOW(),'abcuser');
    
    -- if insert successful than
    
    IF @ROWCOUNT > 0 THEN
       SET Result = "Entered successfully";
    ELSE
       SET Result = "Unsucessful";
    END IF;
    
END$$

DELIMITER;

In the above code, the following things happen in sequence:

Drop if the stored procedure already exists.

Create procedure Add_Worker

2 parameters two IN and one OUT( WorkerId, WorkerName, Result )

Error handling - If WorkerId already exists then a 1062 error message will be shown and Result will be set to unsuccessful

Insert into Worker table values WorkerId,WorkerName, NOW() which is today's date and 'abcuser' for createdBy

If @ROWCOUNT > 0 meaning if a row is added then set Result = "Entered successfully" else Result = "Unsuccessful"

END


Related Solutions

FILL IN THE BLANKS: At an alpha level of .01, test the null hypothesis against the...
FILL IN THE BLANKS: At an alpha level of .01, test the null hypothesis against the alternative that the mean WEIGHT of this sample is no different from the average population weight (u = 152 (151.67 pounds). (5 points) Step 1: Ho: = 152 pounds Ha: (not equal to) 152 pounds Step 2: Alpha level = 0.01 Step 3: Sampling distribution is ____________________ Step 4: Decision Rule — I will reject the Ho if the |_____| value falls at or...
Use a t-test to test the null hypothesis H0: µX = µY against the two-sided alternative...
Use a t-test to test the null hypothesis H0: µX = µY against the two-sided alternative Ha: µX ≠ µY. Use R program (a) Generate 30 values from X ~ N (µX = 10, σX = 4) and 30 values from Y ~ N (µY = 10, σY = 4). . Use a t-test to test the hypotheses given above. (b) Include a comment in your code that identifies the p-value and clearly state the conclusion of the test in...
A hypothesis test is to be performed with a Null hypothesis Ho: µ ≤ 20 and...
A hypothesis test is to be performed with a Null hypothesis Ho: µ ≤ 20 and an alternative hypothesis H1: µ > 20,  the population standard deviation is σ=3.0, the sample size is; n=30, and the significance level is α=0.025. 1) what is a type l error? a. reject h0 when h0 is incorrect b. reject h0 when h0 is correct c. do not reject h0 when h0 is incorrect d. do not reject h0 when h0 is correct 2) What...
Suppose we want to test the null hypothesis H0 : p = 0.28 against the alternative...
Suppose we want to test the null hypothesis H0 : p = 0.28 against the alternative hypothesis H1 : p ≠ 0.28. Suppose also that we observed 100 successes in a random sample of 400 subjects and the level of significance is 0.05. What are the critical values for this test? a. -1.96 and 1.96 b. 0.05 and 0.01 c. -1.39 and 1.39 d. -1.6449 and 1.6449
Test the null hypothesis that the mean difference in the number of cases lost on appeal...
Test the null hypothesis that the mean difference in the number of cases lost on appeal for the two groups of judges is zero against the alternative hypothesis that the untrained judges lose more cases on appeal. Use an alpha level of .01. Judge Untrained Trained 1 3 0 2 1 3 3 2 4 4 7 4 5 5 2 6 4 5 7 6 1 8 2 1 9 7 0 10 5 6 11 3 4 12...
4. Suppose that we want to test the null hypothesis that the mean of a normal...
4. Suppose that we want to test the null hypothesis that the mean of a normal population with    σ2 =1. Ho: μ = 10 vs Ha: μ > 10.   Determine the minimum sample size needed to test with β(11) = 0.06.
A Three students independently collect different samples of size 20 to test a null hypothesis that...
A Three students independently collect different samples of size 20 to test a null hypothesis that the average number of eggs in a fairy wren's nest is 2. In reality, the null hypothesis is true, but the students do not know this. Each student sets the level of significance of his/her hypothesis test at 0.05. What is the probability that at least one student will commit a Type I error? a. 0.86 b. 0.05 c. 0.95 d. 0.14 B In...
Given some stock price data "test null of symmetry at the a%" "test null of normal...
Given some stock price data "test null of symmetry at the a%" "test null of normal tails at the b%" "test null of normality at the c%" What do they mean exactly? Can we anwer this question with Jarque-Bera? Please explain how Can we answer all 3 things with Jarque Bera?
In the following research, identify 1. test type, 2. null hypothesis, 3. alternate hypothesis, 4. test...
In the following research, identify 1. test type, 2. null hypothesis, 3. alternate hypothesis, 4. test statistic, 5. p-value, and 6. conclusion. Researchers examined the effect of phosphate supplementation on bone formation in six healthy adult dogs. For each dog, bone formation was measured twice: once after 12 weeks of phosphate supplementation and once after a 12-week control period. The results in percent bone growth are shown below. Do the data provide evidence that phosphate supplementation significantly stimulates bone formation?...
Evan is using a one-sample ?t‑test to test the null hypothesis ?0:?=48H0:μ=48 against the alternative ?1:?≠48H1:μ≠48....
Evan is using a one-sample ?t‑test to test the null hypothesis ?0:?=48H0:μ=48 against the alternative ?1:?≠48H1:μ≠48. A simple random sample of size 11 is used for the test. Determine the positive and negative critical values of the test statistic ?t that will reject the null hypothesis at significance level ?=0.05α=0.05. Round your answers to three decimal places. -t = t = Alejandra is using a one-sample ?t‑test to test the null hypothesis ?0:?=10.0H0:μ=10.0 against the alternative ?1:?<10.0H1:μ<10.0 using a simple...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT