Sunteți pe pagina 1din 8

CS457_WEEK10

HW_09
STUDENT_ID: 13852
NAME : LALITHA PRASANNA.G
1) Briefly describe when doing hierarchical reports, how you can eliminate a node or a
branch?
Ans: In hierarchical reporting, we can eliminate a node or a branch by pruning.
WHERE clause is used to eliminate a node
CONNECT BY clause is used to eliminate a branch
2) Briefly describe how you can format hierarchical reports in SQL?
Ans: Formatting hierarchical Reports:we use LEVEL and LPAD in formatting hierarchical reorts in sql .It helps in creating a report
displaying company management,university highest and lowest indenting each of the
following levels. The nodes in a tree are assigned level numbers from the root. Use the LPAD
function in conjunction with the pseudocolumn LEVEL to display a hierarchical report as an
intended tree.
3) Briefly describe how you can rank rows in SQL?
Ans: We can explicitly show the rank or level of a row in the hierarchy by using the LEVEL
pseudocolumn.
4) When working on a tree in the SQL, there two options to display the result, what are
they?
Ans: The results can be displayed in the following two options: Top down: Column1 = Parent Key
Column2 = Child Key
Bottom up: Column1 = Child Key
Column2 = Parent Key
5) Briefly describe how you can achieve hierarchical queries in SQL?
Ans: We can achieve the hierarchical queries in SQL by the presence of the CONNECT BY
and START WITH clauses.
6) Briefly describe how you can insert rows into multiple tables as part of a single DML
statement?
Ans: The INSERTSELECT statement can be used to insert rows into multiple tables as
part of a single DML statement.
7) Briefly describe how you can transfer data from one or more operational sources to a set
of target tables in SQL?

Ans: Multitable INSERT statements can be used in data warehousing systems to transfer data
from one or more operational sources to a set of target tables.

8) Briefly describe multi-table insert provide significant performance improvement over?


Ans: Multitable insert provide significant performance improvement over:
Single DML versus multiple INSERT SELECT statements
Single DML versus a procedure to do multiple inserts using IFTHEN syntax
9) Briefly describe types of multi-table insert statements are?
Ans: The different types of multitable insert statements are:
Unconditional INSERT
Conditional ALL INSERT
Conditional FIRST INSERT
Pivoting INSERT
10) Briefly describe how you can create an external table?
Ans: To create an external table
Use the external_table_clause along with the CREATE TABLE syntax to create an external
table.
Specify ORGANIZATION as EXTERNAL to indicate that the table is located outside the
database.
The external_table_clause consists of the access driver TYPE, external_data_properties,
and the REJECT LIMIT.
The external_data_properties consist of the following:
A. DEFAULT DIRECTORY
B. ACCESS PARAMETER
C. LOCATION
PART_2
1Q) select employee_id,last_name,job_id,manager_id from employee start with
employee_id=119 connect by prior first_name= 'tinlot' and last_name='hu';

2Q) ) Write a SQL statement that using bottom up tree to display employee Rayson Lee and his
manager information, the format as employee ID, Last Name, job ID and manager ID?

select employee_id,last_name,job_id,manager_id from employee start with employee_id=106


connect by prior manager_id=employee_id;

3Q)Write a SQL statement that using top down tree to display employee report to his manager by
manager Hu?
select last_name||'reports to'|| prior last_name "walk top down" from employee start with
last_name='hu' connect by prior employee_id= manager_id;

4Q) Write a SQL statement to create a report that displaying company management Levels,
beginning with the manager last name Hu and using => to indenting each level?
select lpad(last_name,length(last_name)+(level*2)-2,'_') as org_chart from employee start with
last_name ='Hu' connect by prior employee_id=manager_id;

5Q) Write a SQL statement that using top down tree to display manager Tinlot Hu manage
employees except employee last name Chen? The format follow by employee ID, Last Name,
job ID and manager ID ?
select employee_id,last_name,job_id,manager_id from employee where last_name!='chen' start
with employee_id=106 connect by prior employee_id=manager_id;

6Q)Complete tasks as select the employee ID, hire date, salary, and manager ID from the
employee table for those employees whose employee ID is greater than 105 and using
unconditional insert all to insert these values into the SAL_HISTORY and MGR_HISTORY
table using a multi-table insert?
create table sal_history(employee_id number not null,hire_date date,salary number,constraint
sal_history_pk primary key (employee_id) enable);
create table mgr_history(employee_id number not null,manager_id number,salary
number,constraint mgr_history_pk primary key (employee_id) enable);
insert all into sal_history values(empid,hiredate,sal) into mgr_history values(empid,mgr,sal)
select employee_id empid,hire_date hiredate,salary sal,manager_id mgr from employees where
employee_id>105;

7) Complete tasks as select the employee ID, hire date, salary and manager ID from the
employee table for those employees whose employee ID is greater than 104. If the salary is
greater than $3,000, insert these values into the SAL_HISTORY table using a conditional multitable INSERT statement. If the manager ID is greater than 104, insert these values into the
MGR_HISTORY table using a conditional multi-table INSERT statement?
truncate table sal_history;
truncate table mgr_history;
insert all when sal>3000 then into sal_history values(empid,hiredate,sal) when mgr>104 then
into mgr_history values(empid,mgr,sal) select employee_id empid,hire_date hiredate,salary
sal,manager_id mgr from employees where employee_id>104;

8)Complete tasks as select the department ID, summary of salary and maximize hire date from
the employee table. If the summary of salary is greater than $2,500 then insert these values into
the SPECIAL_SAL table, using a conditional FIRST multi-table insert. If the first WHEN clause
evaluates to true, the subsequent WHEN clauses for this row should be skipped. For the rows
that do not satisfy the first WHEN condition, insert into the HIREDATE_HISTORY_00, or
HIREDATE_HISTORY_99, or HIREDATE_HISTORY tables, based on the value in the
HIRE_DATE column using a conditional multi-table insert
insert first when sal>2500 then into special_sal values(deptid,sal) when hireedate like ('%00%')
then into hiredate_history_00 values(deptid,hiredate)when hiredate like('%99%') then into
hiredate_history_99 values(deptid,hiredate) else into hiredate_history values(deptid,hiredate)

select dept_id deptid,sum(salary) sal,max(hire_date) hiredate from emp4 group by dept_id;

9) Complete tasks as create a directory object EMP_DIR that corresponds to the directory on the
files system /oracle/sqldeveloper/txt where the external data source resides. And create a text
file, file name as EMP.TXT and contain data as 001,Ablert,01-Jan-1985 002,Ablertson,02-Feb1986 003,Brand,03-Mar-1987 004,Chen,04-Apr-1988 005,David,05-May-1989 006,Frank,06Jun-1990 007,Edwin,07-Jul-1991 008,Grace,08-Aug-1992 009,Henry,09-Sep-1993 010,Iowa,10Oct-1994 011,Jerry,11-Nov-1995 012,Kelly,12-Dec-1996 ?
create directory empll_dir as 'oracle/sqldeveloper/txt';

10) Complete tasks as create an external table call OLDEMP then use the EMP_DIR directory as
source location and EMP.TXT as data source. Once you created the OLDEMP table tries to
query the table to see how many rows inside the table?
create table oldemp(empno number,empname char(20),birthdate date) organization external(type
oracle_loader default directory emp_dir access parameters(reco rds delimited by newline badfile
'bad_emp' logfile 'log_emp' fields terminated b y','(empno char,empname char,birthdate char
date_format date mask "dd-mon-yyyy") ) location('emp.txt')) parallel 5 reject limit 200;

10.create table oldemp(empno number,empname char(20),birthdate date) organization


external(type oracle_loader default directory emp_dir access parameters(reco rds delimited by
newline badfile 'bad_emp' logfile 'log_emp' fields terminated b y','(empno char,empname
char,birthdate char date_format date mask "dd-mon-yyyy") ) location('emp.txt')) parallel 5 reject
limit 200;

S-ar putea să vă placă și