Question

(PL/SQL Programming) Consider the table EMPLOYEE with attributes ID, Name, and Hours, and the table PAYINFO...

(PL/SQL Programming) Consider the table EMPLOYEE with attributes ID, Name, and Hours, and the table PAYINFO with attributes Regular, Overtime, and HourLimit, defined and populated by the following script:

DROP TABLE EMPLOYEE CASCADE CONSTRAINTS;

CREATE TABLE EMPLOYEE

(

       ID            CHAR(5),

       Name          VARCHAR2(16),

       Hours         NUMBER(2),

       CONSTRAINT PK_EMPLOYEE

              PRIMARY KEY (ID)

);

INSERT INTO EMPLOYEE VALUES ('22144', 'Anderson', 30);

INSERT INTO EMPLOYEE VALUES ('31902', 'Bruford', 45);

INSERT INTO EMPLOYEE VALUES ('42771', 'Wakeman', 20);

INSERT INTO EMPLOYEE VALUES ('82889', 'Howe', 40);

SELECT * FROM EMPLOYEE;

DROP TABLE PAYINFO;

CREATE TABLE PAYINFO

(

       Regular       NUMBER(5,2),

       Overtime     NUMBER(5,2),

       HourLimit    NUMBER(2)

);

INSERT INTO PAYINFO VALUES (12.00, 18.50, 30);

SELECT * FROM PAYINFO;

COMMIT;

Write a script file Problem1.sql containing an anonymous PL/SQL block that will do the following:

First, report three values found in the PAYINFO table and store them in variables. (You may assume that the PAYINFO table contains only one record.) Next, output the ID and Name of each employee in the EMPLOYEE table and their total pay, computed as:

Regular * Hours                                                                                               if Hours <= HourLimit

(Regular * HourLimit) + (Overtime * (Hours – HourLimit))                                if Hours > HourLimit

(In other words, each employee is paid at the regular rate for hours up to HourLimit, and is paid at the higher overtime rate for any hours beyond HourLimit.) Output each employee’s information on a separate line, and then the total pay for all employees. For the sample data given above, the output should be:

Payroll data is: 12, 18.5, 30

22144 Anderson 360

31902 Bruford 637.5

42771 Wakeman 240

82889 Howe 545

Payroll total is 1782.5

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

SET SERVEROUTPUT ON SIZE 200000

DECLARE
/*Declaring 3 variables to store payinfo data*/
V_Regular PAYINFO.Regular%type,
V_OverTime PAYINFO.Overtime%type
V_HourLimit PAYINFO.HourLimit%type;
  
BEGIN
/*Inserting data from payinfo to variables*/
SELECT Regular,Overtime,HourLimit INTO V_Regular,V_OverTime,V_HourLimit FROM PAYINFO;
/*Displaying payinfo data*/
dbms_output.put_line('Payroll data is: '||V_Regular ||','||V_OverTime||','||V_HourLimit);
/*Creating cursor to loop data of employee table and display using DBMS_Output*/
FOR Cur_C1 IN
(SELECT ID,Name, CASE WHEN hours > ((V_Regular * V_HourLimit) + (V_Overtime * (hours – V_HourLimit)) THEN (V_Regular* hours )
ELSE (V_Regular * hours) END AS hoursCal
FROM EMPLOYEE
)
LOOP
dbms_output.put_line(Cur_C1.Name|| ' ' ||Cur_C1.Name || ' '||Cur_C1.hoursCal)
END LOOP;

END;

/




Add a comment
Know the answer?
Add Answer to:
(PL/SQL Programming) Consider the table EMPLOYEE with attributes ID, Name, and Hours, and the table PAYINFO...
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 PL/SQL Procedure that returns the names of people who spent over $100. Create table Resturauntorder...

    Write PL/SQL Procedure that returns the names of people who spent over $100. Create table Resturauntorder ( resturauntorder_id int, resturaunt_name varchar2(50), hotel_name varchar2(50), customer_name varchar2(50), order_date date, items_orderd varchar2(100), order_total decimal(5,2), payment_type varchar2(50), tip_amount decimal(5,2), primary key(resturauntorder_id) ); Insert into Resturauntorder values (123,'Terrace Restaurant', 'Hilton Palm Springs', 'John Smith', date '2019-01-10', 'Omelet Pan, Cinnamon French Toast, California eggs, Orange Juice', 60.49, 'cash', 10.33); Insert into Resturauntorder values (345,'Spiaggia', 'Hilton Chicago/Magnificent Mile Suite','Ashley Scott', date '2019-02-21', 'Polpo, Tonno Vitellato, Rabarbaro', 189.29,...

  • SQL query: Write an SQL query that will output the last name, employee id, hire date and department from the employee table. Pick only those employees whose department ID is specified in the employee...

    SQL query: Write an SQL query that will output the last name, employee id, hire date and department from the employee table. Pick only those employees whose department ID is specified in the employee table. If the employee id is 777, name is ABC and hire date is 01-JAN-2016, the output should look as follows - 'Stephen (Employee ID - 777) was hired on the 1st of January, 2016 – Department: 90'. Note - The date should not have preceding...

  • Write SQL authorization statements on the employee table as per the following requirements: Employee (id, name,...

    Write SQL authorization statements on the employee table as per the following requirements: Employee (id, name, job_name, dept_name, salary) - You have three managers with manager1, manager2 and manager3 user ids. All of them are members of the role manager. - All managers have the same privileges: select, insert, update, delete. - No managers can transfer his privileges on the employee table.

  • Lesson 10Create the DEPARTMENT tables based on the following: Column Name   ID      Name Data Type     Number...

    Lesson 10Create the DEPARTMENT tables based on the following: Column Name   ID      Name Data Type     Number Varchar2 Length        7      25 Populate the DEPARTMENT table with data from the DEPT table. Include only columns that you need. Create the EMPLOYEE table based on the following table chart: Column Name    ID      LAST_NAME     FIRST_NAME     DEPT_ID Data Type      Number Varchar2      Varchar2       Number Length         7       25            25             7 Modify the EMPLOYEE table to allow for longer employee last names. Confirm your modification. Confirm that both the...

  • DROP TABLE EMPLOYEE; DROP TABLE JOB; DROP TABLE EMP; DROP TABLE EMP_1; DROP TABLE EMP_2; CREATE...

    DROP TABLE EMPLOYEE; DROP TABLE JOB; DROP TABLE EMP; DROP TABLE EMP_1; DROP TABLE EMP_2; CREATE TABLE JOB(JOB_CODE CHAR (3) PRIMARY KEY, JOB_DESCRIPTION VARCHAR (20) NOT NULL,JOB_CHG_HOUR NUMBER (5,2) NOT NULL,JOB_LAST_UPDATE DATE NOT NULL); INSERT INTO JOB VALUES('500','Programmer','35.75','20-Nov-2017'); INSERT INTO JOB VALUES('501','System Analyst','96.75','20-Nov-2017'); INSERT INTO JOB VALUES('502','Database Designer','125.00','24-Mar-2018'); CREATE TABLE EMPLOYEE(EMP_NUM CHAR (3) PRIMARY KEY,EMP_LNAME VARCHAR (15) NOT NULL,EMP_FNAME VARCHAR (15) NOT NULL, EMP_INITIAL CHAR (1),EMP_HIREDATE DATE NOT NULL,JOB_CODE CHAR (3), EMP_YEARS NUMBER (2),FOREIGN KEY (JOB_CODE) REFERENCES JOB (JOB_CODE)); INSERT...

  • Write a pl/sql block of code that will make a reservation for a customer for any...

    Write a pl/sql block of code that will make a reservation for a customer for any destination. The destination id, number of peolpe going and date will be entered by the user. Your code should calculate the cost and enter the data in the sales table. No destination can have more than 10 people going during the same dates. If the number is greater than 10 raise 'Sold_out' exception and print a message 'Sorry we are sold out for ths...

  • Given the following table structure, write the SQL code to display all the first and last...

    Given the following table structure, write the SQL code to display all the first and last names of the individuals that have a last name that begins with the letter 'M! CREATE TABLE Persons Personi int LastName varchar(80). FirstName varchar(80). Address varchar(125). State char(2) Given the following table structure, write the SQL code to display all the first and last names of the individuals that have a last name that does not contain the letter 'S: CREATE TABLE Persons PersonlDint,...

  • I try to insert data into one of the table causes but I got an error...

    I try to insert data into one of the table causes but I got an error message, I don't know how to resolve this SQL> CREATE TABLE Causes(cid NUMBER(5) PRIMARY KEY, name VARCHAR2(20) REFERENCES Signup, problem VARCHAR2(256), location VARCHAR2(200),fund NUMBER(30)); Table created. SQL> CREATE TABLE Causes(cid NUMBER(5) PRIMARY KEY, name VARCHAR2(20) REFERENCES Signup, problem VARCHAR2(256), location VARCHAR2(200),fund NUMBER(30)); Table created. SQL> describe Signup; Name                                      Null?    Type ----------------------------------------- -------- ---------------------------- USERNAME                                  NOT NULL VARCHAR2(50) PASSWORD                                           VARCHAR2(50) NAME                                      NOT NULL VARCHAR2(100) AGE                                               ...

  • 1. Create a PL/SQL program block that determines the top students with respect to GPA. Assume...

    1. Create a PL/SQL program block that determines the top students with respect to GPA. Assume that the database has four tables. Student(SSN, SName, DOB, Major) , Grade(SSN, CNo, Grade(0,1,2,3,4)) and Course table(CNo,CName, Credit Hour), Prerequisite(CNo, PreCNo); Student and couse data ae given in the following SQL statements a. Accept a number n as user input with SQL*Plus telling top n%. b. In a loop get the SName and GPA of the top n% people with respect to GPA. c....

  • drop table department cascade constraints; create table department ( Dname   varchar2(15)   not null, Dnumber int   not...

    drop table department cascade constraints; create table department ( Dname   varchar2(15)   not null, Dnumber int   not null, Mgr_ssn   char(9)   not null, mgr_start_date   Date, primary key (Dnumber), Unique    (Dname)); insert into DEPARTMENT values ('Research', '5', '333445555', '22-May-1988'); insert into DEPARTMENT values ('Administration', '4', '987654321', '01-Jan-1995'); insert into DEPARTMENT values ('Headquarters', '1', '888665555', '19-Jun-1981'); drop table employee cascade constraints; create table employee ( Fname   varchar2(15) not null, Minit   char(1), Lname   varchar2(15) not null, Ssn   char(9), Bdate   date, Address   varchar2(30), Sex   char(1),...

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
ADVERTISEMENT