Sie sind auf Seite 1von 8

1.What is the use of CASCADE CONSTRAINTS?

When we delete the record in parant table , the corresponding records in child table will be deleted automatically. 2. What is the difference between TRUNCATE and DELETE commands? By using DELETE DML command we can delete a particular record or all records in a table and can be<br>rollbacked later.In case of TRUNCATE DDL command we can truncate all records in a table and can't be rollbacked later. 3. 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. 4. What is the output of the following query SELECT TRUNC(1234.5678,-2) FROM DUAL;?
1200 5. what is the difference between replace and translate functions? Replace function searches for a string and replaces with the given string. REPLACE(char,search_str,replace_str); Translate function searches for a character and it replaces in occurrence of the character. TRANSLATE(Char,From,To);SQL> select Translate('1tech23', '123', '456') from dual; TRANSLAte ------4tech56 SQL> select replace('satyam','am','kam') from dual; REPLACE ------satykam 6. What are the advantages and disadvantages of primary key and foreign

key in SQL?
Primary key Advantages1) It is a unique key on which all the other candidate keys are functionally dependent

Disadvantage 1) There can be more than one keys on which all the other attributes are dependent on. Foreign Key Advantage 1)It allows refrencing another table using the primary key for the other table 7. Difference between decode and case. in which case we are using case and

in which case we are using decode? with an example.


Decode is the sql functions for the replacement of If- Then -else logic and case is similar to If-Then-else logic except that we can make logical comparison of columns involved in the case structures. Ex: select case snum when snum > 10 then 'High' when snum>5 then 'Low' end from sales.. Ex: select decode(snum,10,'high',5,'low') from sales... that is we cannot make logical comparison of columns in Decode() functions. 8. How we get second highest salary in database. Please show me this

coding.
select max(salary) from employee where salary!=(select max(salary) from employee); 9. What will be the output of the following query? SELECT

DECODE(TRANSLATE('A','1234567890','1111111111'), '1','YES', 'NO' );


SELECT DECODE(TRANSLATE('A','1234567890',' 1111111111'), '1','YES', 'NO' ) FROM DUAL; TRANSLATE('A','1234567890','1111111111') gives the value as the same string 'A'. because the string is only A. there is no numbers like 1234567890 exist in the string. So no translation is done. now the query is like DECODE('A','1','YES','NO') IF THE FIRST VALUE i.e A is matches with 1 then it returns YES else it returns NO. here A!=1 so ans is NO. SUPPOSE IF THE QUERY IS LIKE THIS: select DECODE(TRANSLATE('A','1234567890','1111111111'), 'A','YES', 'NO' ) FROM DUAL; ANS:YES 10. Which date function is used to find the difference between two dates? MONTHS_BETWEEN.

11. How can i hide a particular table name of our schema. you can hide the table name by creating synonyms. e.g) you can create a synonym y for table x ex:create synonym y for x;

12. What is the difference between cross product & Cartesian product? There is no difference between Cartesian product and cross join. although there syntax are different but they work as a same. Cartesian or cross product selects all rows from both the table. example tableA 6 rows tableB 6 rows Cartesian or cross product 36 rows. 13. What will be the output of the following query? SELECT REPLACE(TRANSLATE(LTRIM(RTRIM('!! ATHEN !!','!'), '!'), 'AN', '**'),'*','TROUBLE') FROM DUAL;

step by step i will explain: 1st step : rtrim('!!athen!!','!') its out put come like this "!!athen" 2nd step: ltrim('!!athen','!') its out put come "athen" 3rd step :trancelate('athen','an','**') its output come like this "*the*" 4th step :replace('*the*','*','trouble') finally its output being look like this "trouble the trouble"
14. What is the difference between varchar & varchar2? The difference between Varchar and Varchar2 is both are variable length but only 2000 bytes of character of data can be store in varchar where as 4000 bytes of character of data can be store in varchar2 varchar2 and varchar both are support strings,but varchar2 support alphanumeric string.and another one differece the total byte of the datatype are differ. 15. What does the following query do? SELECT SAL + NVL(COMM,0) FROM EMP; whrerever the commission is null, it is replaced by 0 & added to the salary.

16. How to delete same id in rows? For example empid=5 repeated for times in rows. How to delete which sql query is used? delete emp where rowid not in(select min(rowid) from emp group by name); 17. What command is used to create a table by copying the structure of another table? create table <table> as Select * from <existing Table> where 1=2; 18. Write a SQL statement to draw the second highest salary in Employee Table (Using Sub query) Table structure is: Employe ID Name Salary select * from employee a where 2 = (Select count(distinct(salary)) from employee b where a.salary >= b.salary ) 19. What is outer join?Explain with examples. You can perform outer join by using following keyword Left outer join: This include all rows from first table and matching rows from second table. Right outer join: This include all rows from second table and matching rows from first table. Full outer join: This include all non matching rows from both the tables. 20. How to retrieving the data from 11th column to n th column in a table. 21. What is normalization and different kinds of normalization? NORMALIZATION IS THE PROCESS OF DECOMPOSING THE DATABASE TABLES TO ACHIEVE CONSISTENCY AND DATA REDUNDANCY. THE FOLLOWING ARE NORMALIZATION FORMS 1.I normal form 2.II normal form 3.III normal form 4.BCNF 5.IV normal form 6.V normal form 22. What the difference between UNION and UNIONALL? Union:not allow duplicates, sorted with default. UnionAll: allow duplicates,not sorted with default.

23. I have a table with duplicate names in it. Write me a query which returns only duplicate rows with number of times they are repeated. SELECT NAME,COUNT(NAME) FROM TABLE1 GROUP BY NAME HAVING COUNT(NAME) > 1 24. How to find out the database name from SQL*PLUS command prompt? select name from v$database will give u the database name from which u r currently Connected 25. Which system tables contain information on privileges granted and privileges obtained? USER_TAB_PRIVS_MADE, USER_TAB_PRIVS_RECD. 26. What is denormalization and difference between normalization and denormalization? Denormalization is the process of introducing redundancy into a table by incorporating data from a related table. Tables are usually denormalized to prevent expensive SQL join operations between them. 27. What is the default format of date in Oracle? How can I change my default date format?

Default format:-'DD-Mon-YY H:MI:SS' Can Convert format using To_Date(Input_Date,'dd/mm/yyyy'); eg:select TO_DATE(sysdate,'dd/mm/yyyy') from dual
28. How to display duplicate rows in a table? Select distinct *from <table> 29. What is the value of comm and sal after executing the following query if the initial value of ?sal? is 10000 UPDATE EMP SET SAL = SAL + 1000, COMM = SAL*0.1; sal = 11000, comm = 1000. 30. What is the use of DESC in SQL?

DESC: This Command displays column names and data types for a given table. Syntax : DESC[RIBE] <table-name>

31. Cursor Syntax brief history To process multiple records in pl/sql. Type: Explicit - Declare by user and used by user Implicit - Delare by Oracle and used by user and Oracle. Life Cycle of Explicit Cursor: Declare: Used to declare explicit cursor. Cursor <Cursorname> is Select stmt; Open: Execution is done here. Open <Cursorname>; Fetch: Retrieval of data into variable is done through this section. Fetch <Cursorname> into <Var>; Close: Explicitly closes the Cursor. Close <Cursorname>; 32. What is output of following query Select 2 from employee;

It will generate a new column in the result set with 2 as the value in all the rows. The number os rows will be the total number of rows present in the employee table.
33. What is the parameter substitution symbol used with INSERT INTO command? & is substitution variable. eg. insert into table_name values (&column1, &column2); The statement prompts for values of column1 and column2. 34. What is DML,DDL? DATA MANIPULATION LANGUAGE(D.M.L) SOME OF THE COMMANDS OF D.D.L ARE; 1)CREATE;THIS COMMAND IS USED TO CREATE AN OBJECT LIKE TABLE,VIEW,E.T.C 2)ALTER; THIS IS USED TO ALTER AN OBJECT TO DROP A COLUMN ARE MODIFY A COLUMN I.E TO CHANGE THE CHARACTER LENGTH ARE NUMBER LENGTH AND TO RENAME ACOLUMN NAME WITH NEW IN THE PLACE OF OLD ONE 3)DROP;THIS IS USED TO DROP AN OBJECT FROM A DATABASE PERMANENTLY 4)TRUNCATE;THIS IS USED TO DELETE THE RECORDS PERMANENTLY ND WE CANT ROLLBACK IT AFTER TRUNCATING THE STRUCTURE OF THE TABLE WILL NOT BE DELETED ONLY THE RECORDS IN THE TABLE

ARE DELETED 5) RENAME;THIS COMMAND IS USED TO RENAME A OBJECT DATA MANIPULATION LANGUAGE (D.M.L) SELECT; THIS COMMAND IS USED TO RETRIEVE THE DATA FROM THE DATABASE INSERT ; THIS COMMAND IS USED TO INSERT THE RECORDS INTO AN OBJECT UPDATE; THIS COMMAND IS USED TO UPDATE THE RECORDS INA OBJECT WE CAN UPDATE THE RECORDS BY USING THE WHERE CONDITION ALSO IF "WHERE" CONDITION IS OMMITED TOTAL RECORDS IN AN OBJECT WILL BE UPDATED DELETE;THIS COMMAND IS USED TO DELETE THE RECORDS FROM AN OBJECT 35.How to find out the 10th highest salary in SQL query? Nth highest sal: select rownum,empno,ename,salary from(select rownum,empno,ename,salary from emp order by salary desc) group by rownum,empno,ename,salary having rownum=&n Highest sal: select * from emp e where &n=(select count(distinct salary) from emp y where e.salary<y.salary) 37. Explain about predicates and statements?

Statements have a prolonged effect on the functioning and behavior of the data, care should be taken before defining a statement to the data. It may control transactions, query, sessions, connections and program flow Predicates specified conditions which can be evaluated to three valued logic. Boolean truth values can limit the effect of the statements, program functioning, queries, etc.
38. Which command executes the contents of a specified file? START <filename> or @<filename>. 39. what is the query for to select multiple columns to generate single row in the sql and how come we can bring grid views in sql for getting those datas are demolished select empno||' '||ename "emp detail" from emp like this u can combine your column values and give a unique name sory dear i dont have idea about grid view.

Das könnte Ihnen auch gefallen