Question

Write a script in MySQL that creates and calls a stored procedure name test. This procedure...

Write a script in MySQL that creates and calls a stored procedure name test. This procedure should calculate the factorial for the number 10. (To calculate a factorial, you multiply an integer less than itself.) Then, it should display a string that includes the factorial like this: The factorial of 10 is: 3,628,800.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

DELIMITER $$
CREATE PROCEDURE factorial()
BEGIN
DECLARE n INT;
DECLARE fact INT;
DECLARE str TEXT;

   SET n = 10;
SET fact = 1;
   WHILE n > 0 DO
SET fact = fact * n;
SET n = n - 1;
END WHILE;
SET str = CONCAT('The factorial of 10 is: ', fact);
SELECT str;
END$$

DELIMITER ;

Explanation: factorial () procedure is created. It have n and fact as a integer variable and str as string variable.

n used to store number 10, fact is used to store factorial of 10 and str is used to store result.

While loop is used to calculate factorial.

Calling the Procedure: Execute following command,

CALL factorial();

Screen:

Add a comment
Know the answer?
Add Answer to:
Write a script in MySQL that creates and calls a stored procedure name test. This procedure...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a script that creates and calls a stored procedure named spInsertProduct that inserts a row...

    Write a script that creates and calls a stored procedure named spInsertProduct that inserts a row into the Products table. This stored procedure should accept five parameters. One parameter for each of these columns: CategoryID, ProductCode, ProductName, ListPrice, and DiscountPercent. This stored procedure should set the Description column to an empty string, and it should set the DateAdded column to the current date. If the value for the ListPrice column is a negative number, the stored procedure should raise an...

  • Write a PowerShell script. Make sure to: Comment your script by including your name, date, and...

    Write a PowerShell script. Make sure to: Comment your script by including your name, date, and short description what the script does The script receives two arguments/parameters, first one should be a string and the second one an integer number. Both should be passed to the script as (positional) arguments/parameters Check if there are two passed parameters Check if passed parameters are as expected (check if first is string and secondis integer). You can use param() here. Displays on the...

  • Programming Exercise 4.9 Write a script named numberlines.py. This script creates a program listing from a...

    Programming Exercise 4.9 Write a script named numberlines.py. This script creates a program listing from a source program. This script should: Prompt the user for the names of two files. The input filename could be the name of the script itself, but be careful to use a different output filename! The script copies the lines of text from the input file to the output file, numbering each line as it goes. The line numbers should be right-justified in 4 columns,...

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • UNIX Write and run a simple shell script name mymenu that creates a simple command menu....

    UNIX Write and run a simple shell script name mymenu that creates a simple command menu. The script should present menu items (see below), prompts the user for a selection, and then executes the appropriate command selected. [Submit your script and the results of a test case for a, b, c, and d selections]     COMMAND MENU a. Current date and time b. Name of the working directory c. Contents of the working directory Enter a, b, or c:

  • Write a script named listEmptyDir.sh that will do the following: (a) take a name of a...

    Write a script named listEmptyDir.sh that will do the following: (a) take a name of a directory as a parameter; (b) loop through all files in this directory and display their names; (c) if a file is a directory and has no files in it (empty directory), add the name of this empty directory to the file EmptyDir.txt in your current directory. If the number of parameters is not 1 or a parameter is not a directory, display the “usage”...

  • Write the program in C The following statistics for cities of the Vege country are stored...

    Write the program in C The following statistics for cities of the Vege country are stored in a file: Name: a string of characters less than 15 characters long. Population: an integer value. Area: square miles of type double Write a program that: asks and gets the name of the input file from the user. Read the contents of the file into an array length 10 of structures -ask the user for the name of a city (less than 15...

  • 1. Write the command to set the following permissions on a script file with the following...

    1. Write the command to set the following permissions on a script file with the following name; myscript.sh Owner: full access; read, write and execute Group: read and execute Other: no access 2. Create a new file with the name "myfirstscript.sh". Write a new script that performs the following tasks in sequence; Display the usernames of currently logged in users; sorted from a-z HINT: You will need to filter the output of the whocommand Display a list of usernames who...

  • Programming question. Using Visual Studio 2019 C#. Windows Forms Application. Write the code to display the message “Entry error” in the msgLabel when the value in the Integer units variable is less t...

    Programming question. Using Visual Studio 2019 C#. Windows Forms Application. Write the code to display the message “Entry error” in the msgLabel when the value in the Integer units variable is less than or equal to 0. Otherwise, calculate the total owed as follows: If the value stored in the units variable is less than 20, multiply the value by $10; otherwise, multiply it by $5. Store the total owed in the total variable.

  • thank you!! c++ 9. Write the code to prompt the User for website name and a...

    thank you!! c++ 9. Write the code to prompt the User for website name and a domain name. Display the website name, then add “www.” to the beginning of it and“. <domain name>” to the end of it, where <domain name> is the domain name they entered (e.g. “com”, “edu”, “net”, etc.). If the user included the “.” (dot) in the <domain name>, do not add an additional dot. If they did not include the dot, then add the dot...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT