Question

In: Computer Science

Consider these two Oracle Stored Procedures / Functions: Assume that both have been successfully compiled. CREATE...

Consider these two Oracle Stored Procedures / Functions:

Assume that both have been successfully compiled.

CREATE OR REPLACE FUNCTION CALC(pamt number) RETURN number AS

vTot number;

BEGIN

    vTot := pamt + pamt ;

     Return vTot;

END;

CREATE OR REPLACE PROCEDURE SHOW(pstr VARCHAR2) AS

BEGIN

    dbms_output.put_line(pstr);

END;

Write an anonymous block that executes the function named CALC and then the procedure called SHOW.

The output generated by SHOW must be: The total is 20

Solutions

Expert Solution

-- Function to calculate sum of itself.
CREATE OR REPLACE FUNCTION CALC(pamt number) RETURN number AS

vTot number;

BEGIN

    vTot := pamt + pamt ;

     Return vTot;

END;

-- Procedure to print the given string.
CREATE OR REPLACE PROCEDURE SHOW(pstr VARCHAR2) AS

BEGIN

    dbms_output.put_line(pstr);

END;


-- Anonymous block to call function to find sum and then print the result by calling procedure SHOW.
DECLARE
    pamt varchar2(50);
    result varchar2(50);
BEGIN
    SELECT CALC(10) into pamt FROM DUAL; -- This is how you call function in PL/SQL 
    result := 'The Total is ' || pamt;
    SHOW(result); -- Usually procedure are called using EXEC statement. But since we are calling this inside anonymous block we can call it directly without exec statement.
END;

Summary:

Anonymous block is nothing but a procedure without any name. It contains three blocks DECLARE, BEGIN and END. Just like a stored procedure in Oracle.

Way to call function is :-

Select function_name( if any parameters) from dual;

Way to call procedure:-

EXEC procedure_name(if any parameters);


Related Solutions

SQL stored procedures Create 2 stored procedures: sp_AddNewUser and sp_AddNewRole. Use the ManyToMany script as your...
SQL stored procedures Create 2 stored procedures: sp_AddNewUser and sp_AddNewRole. Use the ManyToMany script as your base table structures. The stored procedure should accept the parameters needed to input the data for each table. NOTE: You do not need to input the UserID or RoleID. These are surrogate keys and the system automatically inserts them when you insert a row in the tables.   On execution, the stored procedure should check the database to see if the user exists, if so,...
Step 2: Create Stored Procedures to Add/Update/Delete an entity table Create a script to create a...
Step 2: Create Stored Procedures to Add/Update/Delete an entity table Create a script to create a table named ProjectBilling which will have the following columns: • projectBillID char(6) : A 6 character unique identifier (numbers and letters) • TransAmount decimal(16,9) : The amount of the transaction • TransDesc varchar(255): A description of the transaction • TransDate datetime: The date of the transaction • projectID char(4):The Id of the project • accountMgr char(8):The employee who manages the bill ledger Include this...
Assume that the United States and Cambodia both have similar demand functions and similar taste preferences....
Assume that the United States and Cambodia both have similar demand functions and similar taste preferences. The United States however is capital abundant while Cambodia is labour abundant. Assume that the two countries produce only two goods: capital-intensive cars and labour-intensive shoes. Currently, the two countries are in the process of negotiating a bilateral free trade agreement (FTA). Part (a) Use the concepts of supply and demand to illustrate the situation of bilateral trade between the United States and Cambodia...
Consider two countries, France and Russia, and two goods, wine and vodka. Assume that in both...
Consider two countries, France and Russia, and two goods, wine and vodka. Assume that in both countries, both wine and vodka account for equal shares in their respective consumption baskets. Suppose that the dollar-price of wine in France is half of the dollar-price of wine in Russia. In order for absolute PPP to hold, what must be the ratio of the dollar-price of vodka in France relative to the dollar-price of vodka in Russia?
This exercise has two parts. Please respond to both. The calculation formulas and procedures for both...
This exercise has two parts. Please respond to both. The calculation formulas and procedures for both parts are included in the mini-lecture titled “Rates and Percentages” Part One The Mayors of two small towns that adjoin a large community have engaged in an argument on which of their cities is safer, with respect to its crime rate. City A has a residential population of 123,000 people and reported 185 violent crimes. City B has a residential population of 84,000 people...
Consider a model in which individuals live for two periods and have utility functions of the...
Consider a model in which individuals live for two periods and have utility functions of the form ? = ??(?1) + .5??(?2). They earn income of $10,000 in the first period and save S to finance consumption in the second period. The interest rate, r, is 20. a. Set up the individual’s lifetime utility maximization problem. Solve for the optimal C1, C2, and S. (Hint: ????1,?2 = −.5?2/?1 and the budget line is given by C2= (10,000-C1)(1+r) hence the slope...
Assume the following functions have already been defined, write a main() using c++ that uses them...
Assume the following functions have already been defined, write a main() using c++ that uses them to fill a vector with random integers, remove the smallest and largest integers from the vector, save the result in a file called "trimmed.txt" void fillRandom(vector & nums, int howMany); // fill with specified number of integers int minValue(vector nums); // return smallest value in vector int maxValue(vector <;int> nums); // return largest value in vector void writeFile(string outFileName, vector nums ); // writes...
Assume that you have an array of 100 elements representing the grades students are stored in...
Assume that you have an array of 100 elements representing the grades students are stored in memory. Suppose the grades are in IEEE single precision format. Write a MIPS program to compute the average of the students grades and store the result in register $f0. Assume the array base address is stored in register $s0 and a floating point value of 100 is stored in memory with it address given in register $s2.
Assume you have successfully made a buffer solution, such that you have 0.250 M phosphate buffer...
Assume you have successfully made a buffer solution, such that you have 0.250 M phosphate buffer at pH 7.2. You dissolve in this solution sufficient histidine (side chain pKa = 6.0), such that the final histidine concentration is 5 mM, all at 25°C. Therefore, the pH of the solution is controlled by the phosphate buffer. In this solution, what is the percent of histidine with a protonated side chain? What is the total charge on molecules in this fraction? Explain.
Assume that you have two firms that face marginal abatement cost functions of ???1 = 4.5?...
Assume that you have two firms that face marginal abatement cost functions of ???1 = 4.5? and ???1 = 2.5?, where A is units of abatement undertaken by a firm. Both companies can sell up to two units of output and each unit of output generates one unit of pollution. The price for each unit of output is $12.00 that yields a revenue of $24 dollars per period. Each company is required to hold a permit for each unit of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT