Tampilkan postingan dengan label SELECT statement. Tampilkan semua postingan
Tampilkan postingan dengan label SELECT statement. Tampilkan semua postingan

Senin, 04 Desember 2017

Database programming section 15

1. Using the pseudocolumn ROWNUM in a view has no implications on the ability to do DML's through the view. True or False?
False (*)

2. Given the following view, which operations would be allowed on the emp_dept view?
CREATE OR REPLACE VIEW emp_dept
AS SELECT SUBSTR(e.first_name,1,1) ||' '||e.last_name emp_name,
    e.salary,
    e.hire_date,
    d.department_name
FROM employees e, departments d
WHERE e.department_id = d.department_id
AND d.department_id >=50;
SELECT, UPDATE of some columns, DELETE (*)

3. Which statement about performing DML operations on a view is true?
You cannot modify data in a view if the view contains a group function. (*)

4. You administer an Oracle database. Jack manages the Sales department. He and his employees often find it necessary to query the database to identify customers and their orders. He has asked you to create a view that will simplify this procedure for himself and his staff. The view should not accept INSERT, UPDATE, or DELETE operations. Which of the following statements should you issue?
CREATE VIEW sales_view
   AS (SELECT c.companyname, c.city, o.orderid, o. orderdate, o.total
   FROM customers c, orders o
   WHERE c.custid = o.custid)
WITH READ ONLY;
(*)

5. Only one type of view exists. True or False?
False (*)

6. You want to create a view based on the SALESREP table. You plan to grant access to this view to members of the Sales department. You want Sales employees to be able to update the SALESREP table through the view, which you plan to name SALESREP_VIEW. What should not be specified in your CREATE VIEW statement?
A GROUP BY clause (*)

7. Which of the following is true about ROWNUM?
It is the number assigned to each row returned from a query as it is read from the table. (*)

8. Evaluate this SELECT statement:
SELECT ROWNUM "Rank", customer_id, new_balance
FROM (SELECT customer_id, new_balance
     FROM customer_finance
     ORDER BY new_balance DESC)
WHERE ROWNUM <= 25;
Which type of query is this SELECT statement?
A Top-n query (*)

9. A Top-N Analysis is capable of ranking a top or bottom set of results. True or False?
True (*)

10. The EMPLOYEES table contains these columns:
EMPLOYEE_ID NUMBER
LAST_NAME VARCHAR2(25)
FIRST_NAME VARCHAR2(25)
DEPARTMENT_ID NUMBER
JOB_ID NUMBER
MANAGER_ID NUMBER
SALARY NUMBER(9,2)
COMMISSOIN NUMBER(7,2)
HIRE_DATE DATE
Which SELECT statement could be used to display the 10 lowest paid clerks that belong to department 70?
SELECT ROWNUM "Ranking",last_name||','||first_name "Employee", salary "Salary"
FROM (SELECT last_name, first_name, salary, job_id
     FROM employees
     WHERE job_id LIKE 'CLERK' AND department_id = 70
     ORDER BY salary)
WHERE ROWNUM <=10;
(*)

11. Which statement would you use to alter a view?
CREATE OR REPLACE VIEW (*)

12. Evaluate this view definition:
CREATE OR REPLACE VIEW part_name_v
AS SELECT DISTINCT part_name
FROM parts
WHERE cost >= 45;
Which of the following statements using the PART_NAME_V view will execute successfully?

SELECT *
FROM part_name_v;
(*)

13. Unlike tables, views contain no data of their own. True or False?
True (*)

14. You need to create a view on the SALES table, but the SALES table has not yet been created. Which statement is true?

You can use the FORCE option to create the view before the SALES table has been created. (*)

15. Views must be used to select data from a table. As soon as a view is created on a table, you can no longer select directly from the table. True or False?
False (*)

Database programming section 9

1. The difference between UNION and UNION ALL is
UNION will remove duplicates; UNION ALL returns all rows from all queries including the duplicates. (*)

2. To control the order of rows returned using SET operators, the ORDER BY clause is used ______ and is placed in the _____ SELECT statement of the query.
ONCE; LAST (*)

3. When using SET operators, the number of columns and the data types of the columns must be identical in all of the SELECT statements used in the query. True or False.
True(*)

4. Evaluate this SELECT statement:
SELECT COUNT(emp_id), mgr_id, dept_id
FROM employees
WHERE status = 'I'
GROUP BY dept_id
HAVING salary > 30000
ORDER BY 2;
Why does this statement return a syntax error?
MGR_ID must be included in the GROUP BY clause. (*)

5. Evaluate this SELECT statement:
SELECT MIN(hire_date), department_id
FROM employees
GROUP BY department_id;
Which values are displayed?

The earliest hire date in each department (*)

6. Which statement about the GROUP BY clause is true?
To exclude rows before dividing them into groups using the GROUP BY clause, you should use a WHERE clause. (*)

7. Evaluate this SELECT statement:
SELECT MAX(salary), department_id
FROM employees
GROUP BY department_id;
Which values are displayed?
The highest salary in each department (*)

8. Group functions can be nested to a depth of?
Two(*)

9. Evaluate this SELECT statement:
SELECT SUM(salary), department_id, department_name
FROM employees
WHERE department_id = 1
GROUP BY department;
Which clause of the SELECT statement contains a syntax error?
GROUP BY (*)

10. You use GROUPING functions to ______ database rows from tabulated rows.
DISTINGUISH(*)

11. Examine the following statement:
SELECT department_id, manager_id, job_id, SUM(salary)
FROM employees
GROUP BY GROUPING SETS(.......);
Select the correct GROUP BY GROUPING SETS clause from the following list:
GROUP BY GROUPING SETS ((department_id, manager_id), (department_id, job_id), (manager_id, job_id)) (*)

12. GROUPING SETS is another extension to the GROUP BY clause and is used to specify multiple groupings of data but provide a single result set. True or False?
Trus (*)

13. Examine the following statement:
SELECT department_id, manager_id, job_id, SUM(salary)
FROM employees
GROUP BY ROLLUP(department_id, manager_id)
What extra data will this query generate?
The statement will fail. (*)

14. You use GROUPING functions to:
Identify the extra row values created by either a ROLLUP or CUBE operation (*)

15. If you want to include subtotals and grand totals for all columns mentioned in a GROUP BY clause, you should use which of the following extensions to the GROUP BY clause?
CUBE (*)

Database programming section 7

1. If table A has 10 rows and table B has 5 rows, how many rows will be returned if you perform a cartesian join on those two tables?
50 (*)

2. Evaluate this SQL statement:
SELECT e.employee_id, e.last_name, e.first_name, d.department_name
FROM employees e, departments d
WHERE e.department_id = d.department_id AND employees.department_id > 5000
ORDER BY 4;
Which clause contains a syntax error?
AND employees.department_id > 5000 (*)

3. You need to create a report that lists all employees in department 10 (Sales) whose salary is not equal to $25,000 per year. Which query should you issue to accomplish this task?
SELECT last_name, first_name, salary
FROM employees
WHERE salary != 25000 AND dept_id = 10; (*)

4. When must column names be prefixed by table names in join syntax?
When the same column name appears in more than one table of the query (*)

5. What happens when you create a Cartesian product?
All rows from one table are joined to all rows of another table (*)

6. What is produced when a join condition is not specified in a multiple-table query using Oracle proprietary Join syntax?
A Cartesian product (*)

7. What is the minimum number of join conditions required to join 5 tables together?
4 (*)

8. Will the following statement work?
SELECT department_name, last_name
FROM employees, departments
WHERE department_id = department_id;
No, Oracle will return a Column Ambiguously Defined error. (*)

9. Which symbol is used to perform an outer join?
(+) (*)

10. Evaluate this SELECT statement:
SELECT p.player_id, m.last_name, m.first_name, t.team_name
FROM player p
LEFT OUTER JOIN player m ON (p.manager_id = m.player_id)
LEFT OUTER JOIN team t ON (p.team_id = t.team_id);
Which join is evaluated first?

The self-join of the player table (*)