Top Banner
1. Briefly describe when doing hierarchical reports, how you can eliminate a node or a branch? A. Use the WHERE clause to eliminate the node. Use the CONNECT BY clause to eliminate a branch. 2. Briefly describe how you can format hierarchical reports in SQL? A 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? A. 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? A. 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? A. 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? A. The INSERT..SELECT statement can be used to insert rows into multiple tables as part of a single DML statement.
18

Cs457k HW#9 12538 Manoj Kandepu

Nov 21, 2015

Download

Documents

ManojKandepu

db
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript

1. Briefly describe when doing hierarchical reports, how you can eliminate a node or a branch?A. Use the WHERE clause to eliminate the node. Use the CONNECT BY clause to eliminate a branch.

2. Briefly describe how you can format hierarchical reports in SQL?

A 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?

A. 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?

A. The results can be displayed in the following two options

Top down: Column1 = Parent Key,Column2 = Child KeyBottom up: Column1 = Child Key,Column2 = Parent Key

5. Briefly describe how you can achieve hierarchical queries in SQL?

A. 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?

A. The INSERT..SELECT 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?

A. 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?

A. Multitable insert provide significant performance improvement over:

Single DML versus multiple INSERT.. SELECT statementsSingle DML versus a procedure to do multiple inserts using IF..THEN syntax.

9. Briefly describe types of multi-table insert statements are?

A. The different types of multi-table insert statements are:

Unconditional INSERTConditional ALL INSERTConditional FIRST INSERTPivoting INSERT

10. Briefly describe how you can create an external table?

A. To create an external tableUse 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:DEFAULT DIRECTORYACCESS PARAMETERSLOCATION

01) Write a SQL statement that using top down tree to display manager Tinlot Hu manage employees and format as employee ID, Last Name, job ID and manager ID?

SELECT EMPLOYEE_ID, LAST_NAME, JOB_ID, MANAGER_ID2 FROM EMPLOYEE START WITH LAST_NAME ='Hu' CONNECT BY PRIOR EMPLOYEE_ID = MANAGER_ID;

02) 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_ID2 FROM EMPLOYEE START WITH LAST_NAME ='Lee' CONNECT BY PRIOR MANAGER_ID = EMPLOYEE_ID;

03) Write a SQL statement that using top down tree to display employee report to his manager by manager Hu?

SELECT LAST_NAME || 'REPORT TO' || PRIOR LAST_NAME " WALK TOP DOWN " FROM EMPLOYEE START WITH LAST_NAME ='Hu'2 CONNECT BY PRIOR EMPLOYEE_ID = MANAGER_ID;

04) 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;

05) 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 DEPARTMENT_ID, EMPLOYEE_ID, LAST_NAME, JOB_ID, SALARY FROM EMPLOYEE WHERE LAST_NAME != 'Chen' START WITH MANAGER_ID IS NULL CONNECT BY PRIOR EMPLOYEE_ID = MANAGER_ID;

06) 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 (EMPID,SAL) AS SELECT EMPLOYEE_ID,SALARY FROM EMPLOYEE;

CREATE TABLE MGR_HISTORY (EMPID,MGR) AS SELECT EMPLOYEE_ID,MANAGER_ID FROM EMPLOYEE;TRUNCATE TABLE SAL_HISTORY;TRUNCATE TABLE MGR_HISTORY;

INSERT ALL2 INTO SAL_HISTORY VALUES (EMPID, SAL)3 INTO MGR_HISTORY VALUES (EMPID, MGR)4 SELECT EMPLOYEE_ID EMPID,SALARY SAL,MANAGER_ID MGR FROM EMPLOYEE WHERE EMPLOYEE_ID > 105;

07) 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 multi-table 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 ALL2 WHEN SAL > 3000 THEN3 INTO SAL_HISTORY VALUES (EMPID, SAL)4 WHEN MGR > 104 THEN5 INTO MGR_HISTORY VALUES(EMPID,MGR)6 SELECT EMPLOYEE_ID EMPID,MANAGER_ID MGR FROM EMPLOYEE WHERE EMPLOYEE_ID > 104;

08) 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

CREATE TABLE SPECIAL_SAL AS SELECT DEPARTMENT_ID DEPTID, SALARY SAL FROM EMPLOYEE;CREATE TABLE HIREDATE_HISTORY_00 AS SELECT DEPARTMENT_ID DEPTID, HIRE_DATE HIREDATE FROM EMPLOYEE;CREATE TABLE HIREDATE_HISTORY_99 AS SELECT DEPARTMENT_ID DEPTID,HIRE_DATE HIREDATE FROM EMPLOYEE;CREATE TABLE HIREDATE_HISTORY AS SELECT DEPARTMENT_ID DEPTID, HIRE_DAT E HIREDATE FROM EMPLOYEE;

INSERT FIRST2 WHEN SAL > 2500 THEN3 INTO SPECIAL_SAL VALUES (DEPTID, SAL)4 WHEN HIREDATE LIKE ('%00%') THEN5 INTO HIREDATE_HISTORY_00 VALUES (DEPTID, HIREDATE)6 WHEN HIREDATE LIKE ('%99%') THEN7 INTO HIREDATE_HISTORY_99 VALUES (DEPTID, HIREDATE)8 ELSE9 INTO HIREDATE_HISTORY VALUES (DEPTID, HIREDATE)10 SELECT DEPARTMENT_ID DEPTID, SUM (SALARY) SAL, MAX (HIRE_DATE) HIREDATE11 FROM EMPLOYEE GROUP BY DEPARTMENT_ID;

09) 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-1985002,Ablertson,02-Feb-1986003,Brand,03-Mar-1987004,Chen,04-Apr-1988005,David,05-May-1989006,Frank,06-Jun-1990007,Edwin,07-Jul-1991008,Grace,08-Aug-1992009,Henry,09-Sep-1993010,Iowa,10-Oct-1994011,Jerry,11-Nov-1995012,Kelly,12-Dec-1996

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 DIRECTORY EMP_DIR_NEW AS 'ORACLE/SQLDECELOPER/TXT';

CREATE TABLE OLDEMP2 (EMPNO NUMBER, EMPNAME CHAR(20), BIRTHDATE DATE)3 ORGANIZATION EXTERNAL4 (TYPE ORACLE_LOADER5 DEFAULT DIRECTORY EMP_DIR6 ACCESS PARAMETERS7 (RECORDS DELIMITED BY NEWLINE8 BAD FILE 'BAD_EMP'9 LOGFILE 'LOG_EMP'10 FIELDS TERMINATED BY ','11 (EMPNO CHAR, EMPNAME CHAR,12 BIRTHDATE CHAR DATE_FORMAT DATE MASK "DD-MON-YYYY"))13 LOCATION ('EMP.TXT'))14 PARALLEL 515 REJECT LIMIT 200;