Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part I Anonymous PL / SQL block Consider the table C _ WORKER with attributes WID, WName, and WSalary, and the table TAXVALUES with attributes

Part I Anonymous PL/SQL block Consider the table C_WORKER with attributes WID, WName, and WSalary, and the table TAXVALUES with attributes MaxAmount and TaxRate, defined and populated by the following script: DROP TABLE C_WORKER CASCADE CONSTRAINTS; CREATE TABLE C_WORKER ( WID CHAR(3) PRIMARY KEY, WName VARCHAR2(12), WSalary NUMBER(7,2)); INSERT INTO C_WORKER VALUES ('114', 'Alfred', 45000); INSERT INTO C_WORKER VALUES ('009', 'Bernard', 85000); INSERT INTO C_WORKER VALUES ('233', 'Cayenne', 72000); INSERT INTO C_WORKER VALUES ('903', 'Delta', 64000); INSERT INTO C_WORKER VALUES ('101', 'Eliza', 81000); INSERT INTO C_WORKER VALUES ('098', 'Francis', 87500); INSERT INTO C_WORKER VALUES ('092', 'Garfield', 56300); SELECT * FROM C_WORKER; DROP TABLE TAXVALUES CASCADE CONSTRAINTS; CREATE TABLE TAXVALUES ( MaxAmount NUMBER(7,2),--maximum tax amount TaxRate NUMBER(3,2)--tax rate ); INSERT INTO TAXVALUES VALUES (10000.00,0.13); SELECT * FROM TAXVALUES; COMMIT; Write a script containing just an anonymous PL/SQL block that will do the following: First, read the maximum tax amount and tax rate from the TAXVALUES table, store them in variables, and display their values. (You may assume that the TAXVALUES table contains exactly one record.) Next, for each worker in the C_WORKER table, compute the amount of tax to be withheld from their salary, as follows: -If the salary times the tax rate is less than the maximum tax amount, then the amount of tax to be withheld is the salary times the tax rate. (So, for the values in the sample TAXVALUES table, a worker with a salary of 40000 would have a tax amount of 40000*0.13=5200 withheld.)-If the salary times the tax rate is greater than or equal to the maximum tax amount, then the amount of tax to be withheld is the maximum tax amount. (So, for the values in the sample TAXVALUES table, a worker with a salary of 80000 would have a tax amount of 10000 withheld, since 80000*0.13=10400-> exceeds 10000.)-Output each workers information on a single line, showing their ID, salary, tax amount, and net pay (i.e., the salary minus the amount of tax withheld). Add a + to the end of each line in which the maximum tax amount is withheld. Also, compute the total tax withheld from all the workers salaries and report that total at the end. For the sample data given, the output should be: Tax rate: .13 Maximum Tax: 10000114: 45000585039150009: 850001000075000+233: 72000936062640903: 64000832055680101: 810001000071000+098: 875001000077500+092: 56300731948981 Total tax withheld: 60849 Note: Be aware that this is just an example your anonymous PL/SQL procedure and trigger should work in general, not just for the given sample data. Part II Triggers Consider the table T_AUDIT with attributes WID, OLD_Sal, NEW_Sal, NEW_Tax, auditDate defined and populated by the following script: DROP TABLE T_AUDIT CASCADE CONSTRAINTS; CREATE TABLE T_AUDIT ( WID CHAR(3) REFERENCES C_WORKER(WID), OLD_Sal NUMBER(7,2), NEW_Sal NUMBER(7,2), OLD_Tax NUMBER(7,2), NEW_Tax NUMBER(7,2), auditDate DATE DEFAULT SYSDATE, PRIMARY KEY (WID, auditDATE)); Write a SQL trigger that will do the following: -The trigger should be named NewTaxByLastFirst (replace Last and First with your last and first names, respectively. In my case, it should be NewTaxByPerazaEliecer). The trigger should be fired after a salary of a worker changes. It only should run for those workers not withholding the maximum tax before the update. It should insert all the information requested in the T_AUDIT table for each time the trigger body runs (once for each row meeting the condition). It should output each workers information on single line, showing their ID, old salary, old tax amount, new salary, new tax amount, and difference of tax withheld. The output should look like this: 114: 450005850495006435585233: 7200093607920010296936903: 640008320704009152832092: 563007319619308050.9731.9 Note: this output is the result of executing UPDATE C_WORKER SET WSalary =1.1* WSalary; Note: this is the result of running SELECT * FROM t_audit; after the above UPDATE has run. The tax rate and max amount may be hard coded for the trigger condition but must be retrieved from the taxvalues table when used in the body of the trigger. PLEASE ANSWER PART I AND II. I WILL GIVE THUMBS UP!!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions

Question

What are the three types of selling objectives? lop857

Answered: 1 week ago

Question

Did you add the logo at correct size and proportion?

Answered: 1 week ago