Skip to main content

Posts

Showing posts with the label select

Question 11: Oracle Tables Last Modifying Time

Suppose Database D1 contains 100 tables.. How 2 select the tables which are modified at 10am today? 1. SELECT table_name, table_owner FROM all_tab_modifications WHERE to_char(timestamp,'YYYYMMDDHH24MM') = to_char(sysdate,'YYYYMMDD')'1000' This will gives the table names which are modified (insert, update, delete, truncated) at 10 AM. 2. SELECT scn_to_timestamp(max(ora_rowscn)) FROM ;

Question 10. Inserting Rows

How many number of rows, I can insert into a table simultaenously? Answer : Method 1: If you want to insert multiple rows with a single INSERT statement, you can use a subquery instead of the VALUES clause. Rows returned from the subquery will be inserted the target table. Example: INSERT INTO tablename1 SELECT fieldnamelist FROM tablename WHERE condition

Question 7: Group By

Examine the description of the EMPLOYEES table: EMP_ID NUMBER(4) NOT NULL LAST_NAME VARCHAR2(30) NOT NULL FIRST_NAME VARCHAR2(30) DEPT_ID NUMBER(2) JOB_CAT VARCHARD2(30) SALARY NUMBER(8,2) Which statement shows the maximum salary paid in each job category of each department? A.SELECT dept_id, job_cat, MAX(salary) FROM employees WHERE salary > MAX(salary); B.SELECT dept_id, job_cat, MAX(salary) FROM employees GROUP BY dept_id, job_cat; C. SELECT dept_id, job_cat, MAX(salary) FROM employees; D. SELECT dept_id, job_cat, MAX(salary) FROM employees GROUP BY dept_id; Answer: B Explanation: This answer provides correct syntax and semantics to show the maximum salary paid in each job category of each department. Incorrect Answers A: This query will not return any row because condition SALARY > MAX(SALARY) is FALSE. C: This query will return error because you cannot show maximum salary with DEPT_ID and JOB_CAT without grouping by these columns. D: The GROUP BY clause is missing JOB_ID col...

Question 5: Where and having clauses

Which two statements are true about WHERE and HAVING clauses? (Choose two) A. A WHERE clause can be used to restrict both rows and groups. B. A WHERE clause can be used to restrict rows only. C. A HAVING clause can be used to restrict both rows and groups. D. A HAVING clause can be used to restrict groups only. Answer: B, C Explanation : HAVING clause to specify which groups are to be displayed and thus further restrict the groups on the basis of aggregate information. The Oracle server performs the following steps when youuse the Having clause 1. rows are grouped 2. the group function is applied to the group 3. the group that match the criteria in the Having clause are displayed. WHERE clause cannot be use to restrict groups HAVING clause use to restrict groups WHERE clause cannot be use when there is group functions. Incorrect Answers : A. Where clause cannot be use to restrict groups D. When HAVING clause is use rows are grouped as well.

Question: 4 - WHERE clause

The ORDERS table has these columns: ORDER_ID NUMBER(4) NOT NULL CUSTOMER_ID NUMBER(12) NOT NULL ORDER_TOTAL NUMBER(10,2) The ORDERS table tracks the Order number, the order total, and the customer to whom the Order belongs. Which two statements retrieve orders with an inclusive total that ranges between 100.00 and 2000.00 dollars? A.SELECT customer_id, order_id, order_total FROM orders RANGE ON order_total (100 AND 2000) INCLUSIVE; B.SELECT customer_id, order_id, order_total FROM orders HAVING order_total BETWEEN 100 and 2000; C. SELECT customer_id, order_id, order_total FROM orders WHERE order_total BETWEEN 100 and 2000; D. SELECT customer_id, order_id, order_total FROM orders WHERE order_total >= 100 and Answer:C Explanation: Answers C provides correct results to show. You can use BETWEEN or comparison operations to retrieve data. Incorrect Answers A: There is no RANGE ON or INCLUSIVE keyword in Oracle. B: HAVING clause can be use only in conjunction with the GROUP BY clause. D: ...
Question 1. You need to display the last names of those employees who have the letter "A" as the second character in their names. Which SQL statement displays the required results? A. SELECT last_nameFROM EMPWHERE last_name LIKE '_A%'; B. SELECT last_nameFROM EMPWHERE last name ='*A%' C. SELECT last_nameFROM EMPWHERE last name ='_A%'; D. SELECT last_nameFROM EMPWHERE last name LIKE '*A%' Answer: A Explanation: Statement in this answer will show correct results because usage of operator LIKE and format mask '_A%' extract the last names of those employees who have the letter 'A' as the second character in their names. Symbol '_' in format mask substitute exactly one symbol and cannot be NULL. Incorrect Answers B: This statement will return only names starting from symbol '*'. It cannot be used as substitution symbol. C: Usage of equity operator here is not appropriate in this case: query will look exact for fi...