sql paper

4
 1)What is NVL? NVL: Null value function converts a null value to a non-null value for the purpo se of evaluating an expression. Numeric Functions accept numeric I/P & return nu meric values. They are MOD, SQRT, ROUND, TRUNC & POWER. 2)How can variables be passed to a SQL routine? By use of the & symbol. For passing in variables the numbers 1-8 can be used (&1 , &2,...,&8) to pass the values after the command into the SQLPLUS session. To b e prompted for a specific variable, place the ampersanded variable in the code i tself: select * from dba_tables where owner=&owner_name; . Use of double ampersand s tells SQLPLUS to resubstitute the value for each subsequent use of the variabl e, a single ampersand will cause a reprompt for the value unless an ACCEPT state ment is used to get the value from the user. 3)Which function is used to find the largest integer less than or equal to a spe cific value? A) CEIL B) FLOOR c) ROUND D)TRUNCATE Ans: B 4)List the emps in the asc order of Designations of those joined after the secon d half of 1981. Ans: select * from emp where hiredate > ( 30-jun-81) and to_char(hiredate,YYYY) = 198 1 order by job asc; 5)List the emps who are senior to King. A) select * from emp where hiredate < ( select hiredate from emp where ename = KI NG); 6) List the Emps of Deptno 20 whose Jobs are same as Deptno10. A) select * from emp e ,dept d where d.deptno = 20 and e.deptno = d.deptno and e .job in ( select e.job from emp e,dept d where e.deptno = d.deptno and d.deptno =10); 7) List the emps whose sal is equal to the average of max and minimum A) select * from emp where sal =(select (max(sal)+min(sal))/2 from emp); 8) Find out the most recently hired emps in each Dept order by Hiredate. A) select * from emp e where hiredate in (select max(hiredate) from emp where e.deptno = deptno ) order by hiredate; 9)Which of the following has been achieved by the following SQL codes? SELECT em ployee_id FROM employees WHERE commission_pct = .5 OR salary > 23000; it returns employees who have a 50% of a salary greater than $23,000: it returns employees who have a 50% commission rate or a salary greater than $23 ,000: runtime error it returns employees who have a 50% of a salary less than $23,000: invalid syntax F. it returns employees who have a 50% commission rate and a sala ry greater than $23,000: Answer: B 10) what is the difference between NOT IN and NOT EXISTS?

description

SQL questions and answers

Transcript of sql paper

1)What is NVL?NVL: Null value function converts a null value to a non-null value for the purpose of evaluating an expression. Numeric Functions accept numeric I/P & return numeric values. They are MOD, SQRT, ROUND, TRUNC & POWER.2)How can variables be passed to a SQL routine?By use of the & symbol. For passing in variables the numbers 1-8 can be used (&1, &2,...,&8) to pass the values after the command into the SQLPLUS session. To be prompted for a specific variable, place the ampersanded variable in the code itself: select * from dba_tables where owner=&owner_name; . Use of double ampersands tells SQLPLUS to resubstitute the value for each subsequent use of the variable, a single ampersand will cause a reprompt for the value unless an ACCEPT statement is used to get the value from the user. 3)Which function is used to find the largest integer less than or equal to a specific value?A) CEILB) FLOOR c) ROUNDD)TRUNCATEAns: B4)List the emps in the asc order of Designations of those joined after the second half of 1981.Ans: select * from emp where hiredate > (30-jun-81) and to_char(hiredate,YYYY) = 1981 order by job asc;5)List the emps who are senior to King.A) select * from emp where hiredate < ( select hiredate from emp where ename = KING);6) List the Emps of Deptno 20 whose Jobs are same as Deptno10.A) select * from emp e ,dept d where d.deptno = 20 and e.deptno = d.deptno and e.job in ( select e.job from emp e,dept d where e.deptno = d.deptno and d.deptno =10);7) List the emps whose sal is equal to the average of max and minimumA) select * from emp where sal =(select (max(sal)+min(sal))/2 from emp);8) Find out the most recently hired emps in each Dept order by Hiredate.A) select * from emp e where hiredate in(select max(hiredate) from emp where e.deptno = deptno )order by hiredate;9)Which of the following has been achieved by the following SQL codes? SELECT employee_id FROM employees WHERE commission_pct = .5 OR salary > 23000;it returns employees who have a 50% of a salary greater than $23,000:it returns employees who have a 50% commission rate or a salary greater than $23,000:runtime errorit returns employees who have a 50% of a salary less than $23,000:invalid syntax F. it returns employees who have a 50% commission rate and a salary greater than $23,000:Answer: B10) what is the difference between NOT IN and NOT EXISTS?Ans: EXISTS is more faster than IN because EXISTS returns a Boolean value whereas IN returns a value.11. What command is used to create a table by copying the structure of another table?Answer : Create table as select * from where 1=2;12) Why does the following command give a compilation error?DROP TABLE &TABLE_NAME;Variable names should start with an alphabet. Here the table name starts with an '&' symbol.13) What are the various types of queries ?Answer: The types of queries are:Normal QueriesSub QueriesCo-related queriesNested queriesCompound queries14) What is the maximum no.of columns a table can have ?Answer: 254.15) What is the significance of the & and && operators in PL SQL ?Answer: The & operator means that the PL SQL block requires user input for a variable.The && operator means that the value of this variable should be the same as inputted by the user previously for this same variable16) Can you use %RowCount as a parameter to a cursor ?Answer: Yes17) How many rows will the following SQL return : Select * from emp Where rownum = 10;Answer: No rows18) Can you alter synonym of view or view ?Answer: No19) Can you create index on viewAnswer: No.20) Which SQL statement returns a numeric value?A. SELECT ADD_MONTHS(MAX (hire_date), 6) FROM EMP;B. SELECT ROUND(hire_date)FROM EMP;C. SELECT sysdate-hire_date FROM EMP;D. SELECT TO_NUMBER(hire_date + 7)FROM EMP;Ans: C21) Which two statements about sequences are true?(choose any 2) A. You use a NEXTVAL pseudo column to look at the next possible value that would be generated from a sequence, without actually retrieving the value.B. You use a CURRVAL pseudo column to look at the current value just generated from a sequence, without affecting the further values to be generated from the sequence.C. You use a NEXTVAL pseudo column to obtain the next possible value from a sequence by actually retrieving the value form the sequenceD. You use a CURRVAL pseudo column to generate a value from a sequence that would be used for a specified database column.Ans:B,C22) Which operator can be used with a multiple row subquery?A. =B. LIKEC. BETWEEND. NOT INE. IsF. Ans:D23) Which two statements about subqueries are true? (Choose two.)A. A subquery should retrieve only one row.B. A subquery can retrieve zero or more rows.C. A subquery can be used only in SQL query statements.D. Subqueries CANNOT be nested by more than two levels.E. A subquery CANNOT be used in an SQL query statement that uses group functions.F. When a subquery is used with an inequality comparison operator in the outer SQL statement, the column list in the SELECT clause of the subquery should contain only one columnAns:B,F24) Which two statements about views are true? (Choose two)A. A view can be created as read onlyB. A view can be created as a join on two or more tables.C. A view cannot have an ORDER BY clause in the SELECT statement.D. A view cannot be created with a GROUP BY clause in the SELECT statement.E. A view must have aliases defined for the column names in the SELECT statement.Ans:A,B25) what is the difference between rowid and rownum26)SUBSTR(SQUARE ANS ALWAYS WORK HARD,14,6) will returna] ALWAYb} S ALWAc] ALWAYSAns : C27) TRANSLATE('333SQD234','0123456789ABCDPQRST','0123456789') will returna] 333234b] 333333c] 234333d] None of the aboveAns : A