Question

Q2. Retrieve the names of all employees from the employee table to produce output on CSV...

Q2. Retrieve the names of all employees from the employee table to produce output on CSV format or delimited format with a common delimeter, rather than separete columns.

Hint:Put the whole row into a string with a semicolon as the seperator(delimeter) between thecolumns: FORMAT:(fname;minit;lname)

Example:

EMPLOYEES

--------------

James;E;Borg

Frank;T;Wong

Q3.

Write a query to show the employees name from the employee table in this format: first letter of the first name, followed by a dot, a blank, and the full last name

Example:

EMPLOYEES

------------------

J. Borg

F. Wong

Q4.

Run a query from the employee table to find the age of the employees and the Day(Ex:Monday) they were born. You may need to update these records if Age is shown as negative.

Example:

NAME BDATE AGE

------------------------------- ------------------ ----------

Ramesh Narayan Monday 09/15/52 61

Jennifer Wallace Saturday 06/20/31 82


Q5.

Find the names of all employees who are directly supervised by 'franklin wong'. Hint: You may need to work with CASE sensitivity.


Q6.

write and test a query to list the name and the total compensation(salary+commission) of all the instructors.Unknown commission should be treated as zero


Q7.

write a query to list superssn,ssn,bdate for employees was born in year 1926 or later.

Sort the rows by asc superssn with NULL at top. For each employees, they should be sorted by desc bdate


I have copied and pasted the following data from the .sql file (create-insert table data) to use to answer these above mentioned questions. Please copy and paste all the data to the oracle system and run them to create table and insert data. Then generate the queries to answer the above mentioned questions.

CREATE TABLE employee (
fname varchar2(15) not null,
minit varchar2(1),
lname varchar2(15) not null,
ssn char(9),
bdate date,
address varchar2(30),
sex char,
salary number(10,2),
superssn char(9),
dno number(4),
primary key (ssn)
);

DROP TABLE works_on CASCADE CONSTRAINTS;
CREATE TABLE works_on (
essn char(9),
pno number(4),
hours number(4,1),
primary key (essn,pno)
);

CREATE TABLE instructor (
   instructor_id number(3) not null,
   instructor_name varchar2(15) not null,
   salary number(6,2) not null,
   commission number(6,2),
   mentor_id number(3),
   date_hired date
);


INSERT INTO employee VALUES ('Alicia', 'J', 'Zelaya',
'999887777', TO_DATE('07-19-1958', 'MM-DD-YYYY'), '3321 Castle, Spring,TX', 'F', 25000,
'987654321', 4);
INSERT INTO employee VALUES ('Jennifer', 'S', 'Wallace',
'987654321', TO_DATE('06-20-1931', 'MM-DD-YYYY'), '291 Berry, Bellaire,TX', 'F', 43000,
'888665555', 4);
INSERT INTO employee VALUES ('Ramesh', 'K', 'Narayan',
'666884444', TO_DATE('09-15-1952', 'MM-DD-YYYY'), '975 Fire Oak, Humble,TX', 'M', 38000,
'333445555', 5);
INSERT INTO employee VALUES ('Joyce', 'A', 'English',
'453453453', TO_DATE('07-31-1962', 'MM-DD-YYYY'), '5631 Rice, Houston, TX', 'F', 25000,
'333445555', 5);
INSERT INTO employee VALUES ('Ahmad', 'V', 'Jabbar',
'987987987', TO_DATE('03-29-1959', 'MM-DD-YYYY'), '980 Dallas, Houston,TX', 'M', 25000,
'987654321', 4);
INSERT INTO employee VALUES ('James', 'E', 'Borg',
'888665555', TO_DATE('11-10-1927', 'MM-DD-YYYY'), '450 Stone, Houston,TX', 'M', 55000,
null, 1);
INSERT INTO employee VALUES ('New', 'V', 'Lost',
'777977977', TO_DATE('03-23-1977', 'MM-DD-YYYY'), 'NY,NY', 'M', 20000, '987654321', 4);
      
INSERT INTO employee VALUES ('Franklin', 'T', 'Wong',
'333445555', TO_DATE('12-08-1945', 'MM-DD-YYYY'), '638 Voss, Houston,TX', 'M', 40000, '888665555', 5);      

INSERT INTO employee(FNAME, MINIT, LNAME, SSN, BDATE, ADDRESS, SEX, SALARY, SUPERSSN, DNO)
VALUES ('John', 'B', 'Smith',
'123456789', TO_DATE('01-09-1955', 'MM-DD-YYYY'), '731 Fondren, Houston,TX', 'M', 30000,
'333445555', 5);
      
INSERT INTO works_on VALUES ('123456789', 1, 32.5);
INSERT INTO works_on VALUES ('123456789', 2, 7.5);
INSERT INTO works_on VALUES ('666884444', 3, 40.0);
INSERT INTO works_on VALUES ('453453453', 1, 20.0);
INSERT INTO works_on VALUES ('453453453', 2, 20.0);
INSERT INTO works_on VALUES ('333445555', 2, 10.0);
INSERT INTO works_on VALUES ('333445555', 3, 10.0);
INSERT INTO works_on VALUES ('333445555', 10, 10.0);
INSERT INTO works_on VALUES ('333445555', 20, 10.0);
INSERT INTO works_on VALUES ('999887777', 30, 30.0);
INSERT INTO works_on VALUES ('999887777', 10, 10.0);
INSERT INTO works_on VALUES ('987987987', 10, 35.0);
INSERT INTO works_on VALUES ('987987987', 30, 5.0);
INSERT INTO works_on VALUES ('987654321', 30, 20.0);
INSERT INTO works_on VALUES ('987654321', 20, 15.0);
INSERT INTO works_on VALUES ('888665555', 20, null);


insert into instructor values (
835, 'SPARKS', 4000 , 200, 978, TO_DATE('16-Dec-1984', 'DD-MON-YYYY'));

insert into instructor values (
978, 'STEEL', 5000 , 250, 222, TO_DATE('16-Jan-1980', 'DD-MON-YYYY'));

insert into instructor values (
222, 'CAINE', 5500 , 350, NULL, TO_DATE('02-Nov-1976', 'DD-MON-YYYY'));

insert into instructor values (
243, 'TUCKER', 2000 , NULL, 835, TO_DATE('18-Dec-1990', 'DD-MON-YYYY'));

insert into instructor values (
263, 'JOHNSON', 4000 , NULL, 835, TO_DATE('18-Jul-1992', 'DD-MON-YYYY'));

insert into instructor values (
515, 'SHELLEY', 3500 , 200, 700, TO_DATE('20-Jan-1991', 'DD-MON-YYYY'));

insert into instructor values (
453, 'LODGE', 2500 , 100, 835, TO_DATE('14-Sep-1988', 'DD-MON-YYYY'));

insert into instructor values (
700, 'WAYNE', 4500 , 300, NULL, TO_DATE('16-May-1981', 'DD-MON-YYYY'));

insert into instructor values (
628, 'MONROE', 3000 , NULL, 700, TO_DATE('16-Jul-1984', 'DD-MON-YYYY'));

insert into instructor values (
790, 'NEWMAN', 3100 , 300, 700, TO_DATE('16-Dec-1982', 'DD-MON-YYYY'));

insert into instructor values (
795, 'BOGART', 3200 , NULL, 700, TO_DATE('16-Dec-1983', 'DD-MON-YYYY'));

insert into instructor values (
560, 'LAUREL', 5200 , 200, 978, TO_DATE('16-Dec-1983', 'DD-MON-YYYY'));

insert into instructor values (
123, 'FLINTSTONE,FRED', 1000 , NULL, 978, TO_DATE('16-Jun-1989', 'DD-MON-YYYY'));


select * from employee;
select * from works_on;
select * from instructor;

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

ANSWER:--

GIVEN THAT:--

  • 2.Select CONCAT(fname,':',minit,':',lname) as Employees from Employee;

    3.Select CONCAT(SUBSTRING(fname,1,1), '.' ,' ' ,lname) )as Employees from Employee;

    4.Select fname||' '|| lname , DATENAME(dw,bdate), FLOOR(DATEDIFF(DAY, bdate, getDate()) / 365.25) as Age from Employee;

    5.Select e1.fname, e1.minit, e1.lname from employee e1,employee e2 where e1.superssn = e2.ssn and e2.fname = 'Franklin' and lname = 'Wong';

    6.Select Name , Salary + NVL(Commission,0) as Compensation from Instructor;

    7.Select superssn,ssn,bdate from Employees where Year(bdate) >= 1926 order by superssn NULLS First , bdate desc;

Add a comment
Know the answer?
Add Answer to:
Q2. Retrieve the names of all employees from the employee table to produce output on CSV...
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
  • Query 1: Retrieve names of all the projects as well as First and Last name of...

    Query 1: Retrieve names of all the projects as well as First and Last name of managers if they are working on any of these projects. Database: //STEP #1: CREATE TABLE employee ( fname varchar(15) not null, minit varchar(1), lname varchar(15) not null, ssn char(9), bdate date, address varchar(50), sex char, salary decimal(10,2), Super_ssn char(9), dno char(4), primary key (ssn)); CREATE TABLE department ( dname varchar(25) not null, dnumber char(4), Mgr_ssn char(9) not null, Mgr_start_date date, primary key (dnumber)); CREATE...

  • Query #2:       List the name of the project and total number of hours worked on by...

    Query #2:       List the name of the project and total number of hours worked on by all the employees on this project, also report the number of employees working on each project. Database: //STEP #1: CREATE TABLE employee ( fname varchar(15) not null, minit varchar(1), lname varchar(15) not null, ssn char(9), bdate date, address varchar(50), sex char, salary decimal(10,2), Super_ssn char(9), dno char(4), primary key (ssn)); CREATE TABLE department ( dname varchar(25) not null, dnumber char(4), Mgr_ssn char(9) not null,...

  • 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),...

  • Search all employee who work total on all project less than 40 hrs from works_on table....

    Search all employee who work total on all project less than 40 hrs from works_on table. Please give me a query for this. Figure 5.6 One possible database state for the COMPANY relational database schema. EMPLOYEE Fname Minit Lname Sex Salary Super ssn Dno B Smith 123456789 1965-01-09 731 Fondren, Houston, TX M 30000 333445555 5 FranklinT Wong 333445555 1955-12-08 638 Voss, Houston, TX M 40000 888665555 5 JZelaya 999887777 1968-01-19 3321 Castle, Spring, TX F 25000 9876543214 JenniferSWallace 9876543211941-06-20...

  • I need help with the following SQL query for a company database (script given below). The...

    I need help with the following SQL query for a company database (script given below). The name of the Department. The number of employees working in that department. The number of different projects controlled by this department. The name of the project controlled by this department that has the maximum number of employees of the company working on it. The number of the above project. The cumulative sum of the number of employees of the company working on the projects...

  • (SELECT pnumber FROM project, department, employee WHERE dnum=dnumber AND mgr_ssn=ssn AND lname='Smith') UNION (SELECT pnumber FROM...

    (SELECT pnumber FROM project, department, employee WHERE dnum=dnumber AND mgr_ssn=ssn AND lname='Smith') UNION (SELECT pnumber FROM project, works_on, employee WHERE pnumber=pno AND essn=ssnAND lname='Smith') Can you draw the relation step by step , how to solve it ?! Figure 5.6 One possible database state for the COMPANY relational database schema. EMPLOYEE Sex Salary Super ssn Dno B Smith 123456789 1965-01-09 731 Fondren, Houston, TX M 30000 3334455555 Ssn Fname Minit Lname John Franklin TWong 333445555 1955-12-08 638 Voss, Houston, TXM40000...

  • Please provide the relation algebra, the oracle SQL code and the output tuples for the following (Answer #6 only the BONUS question). I have the others actually I have the BONUS, but I want to compar...

    Please provide the relation algebra, the oracle SQL code and the output tuples for the following (Answer #6 only the BONUS question). I have the others actually I have the BONUS, but I want to compare with your solution to make sure I did it correctly. Thank you very much! LAB exercises 2 Write the Oracle DML query codes for the following questions and take the screen shot of the output. 1. Retrieve the name and address of all employees...

  • ONE SQL STATEMENT for "Retrieve the social security numbers of all direct and indirect supervisees James...

    ONE SQL STATEMENT for "Retrieve the social security numbers of all direct and indirect supervisees James E Borg has" NAME                SSN       BDATE     SEX     SALARY SUPERSSN DNO            ------------------- --------- --------- --- ---------- --------- --------       John B Smith        123456789 09-JAN-55 M        30000 333445555 5              Franklin T Wong     333445555 08-DEC-45 M        40000 888665555 5              Alicia J Zelaya     999887777 19-JUL-85 F        25000 987654321 4              Jennifer S Wallace 987654321 20-JUN-31 F        43000 888665555 4               Ramesh K Narayan    666884444 15-SEP-52 M        38000 333445555 5              Joyce...

  • Use the tables in the next page to answer the following questions in SQL. 1. Print...

    Use the tables in the next page to answer the following questions in SQL. 1. Print the names of employees who work in a project located in Houston. 2. Print the names of employees with no dependents. 3. Print the names of employees who are managers. 4. Print the names of employees who have more than one wife. 5. Print the names of employees who work in all the projects. EMPLOYEE Frame John Franklin Minit B T S K A...

  • write the following queris in sql : a) Using nested query , retreive the sependent names...

    write the following queris in sql : a) Using nested query , retreive the sependent names of male employees whose salary > 30000 b ) list the female employee, who are not managers EMPLOYEE Fname MinitLname John Franklin T Wong 333445555 1955-12-08 638 Voss, Houston, TX M 4 Ssn Sex Salary Super sen Dno B Smith 123456789 1965 01-09 731 Fondren, Houston, TX M 30000 13334455 AliciaZelaya 999987777 1968-01-19 3321 Castle, Spring, TXF Jennifer S Wallace 987654321 1941-06-20 291 Berry,...

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