Sunteți pe pagina 1din 6

1)can you create a table having same structure of another table only name differ and having no data

of olf table? 1) Create new_table as select * from old_table where 1=2; 2) i hve two tables EMP1&EMP2 both having same fields if any updations made in emp1 how to reflect on emp2. 2) try to write update/delete/insert trigger on emp2 which will fire on updation/deletion/insertion in emp1

3) what is the full form of tns in oracle? 3) Transparent Network Substrate

4) How to delete the duplicate row from the employee table? 4) Delete from <table_name> where rowid not in (select min(rowid) from <table_name> group by col1,col2....) 5) What is the difference between DROP,DELETE and TRUNCATE.. Can anyone tell why we require EXISTS with example. 5) Drop and Truncate are DDL, With Drop Command we can remove entire Table or columns from database. With Truncate we can remove the records in the table by keeping table structure. Drop and Truncate are AutoCommit. By using Delete command we can remove rows in the table but its not autocommit Or Delete:It's an DML command which is used for deleting particular table in the database...even though we delete the data we can regain it by rollback command. Example:SQL> SELECT COUNT(*) FROM emp; COUNT(*) ---------14 SQL> DELESQL> SELECT COUNT(*) FROM emp;

COUNT(*) ---------14 SQL> DELETE FROM emp WHERE job = 'CLERK'; 4 rows deleted. SQL> COMMIT; Commit complete. Truncate:This command is a DDL Command which is used to delete a table...I Just Conclude it as Truncate=Delete+Commit...once u applied this on table u can't get the data back...but the structure will be there.. Example: SQL> TRUNCATE TABLE emp; Table truncated. SQL> SELECT COUNT(*) FROM emp; COUNT(*) ---------0 Drop:It is used to destroy entire structure of a table...once we apply this command on any particular table we can't get it in anyway...so be cautious while applying this command. Example: SQL> DROP TABLE emp; Table dropped. SQL> SELECT * FROM emp; SELECT * FROM emp 6) There is a varchar2 column ,How can I insert data which contains ' in it ,eg-Ora'cle ?? The value to be inserted may vary with every insertion and we can't specifically tell as to whats the position of single quotes .. 6) insert into test values('ora''cle');

use two single quotes side by side..(its not a double quote) hope this will work 7) Select * from tab; - means we can see all the tables,right! is there any option similar to this..? 7) You can also use select * from cat; 8) What is join? Types of Join & Difference between each. 8) Join is used to retrieve data from more than one table simultaneously....

There are two types of join: 1. INNER JOIN 2. OUTER JOIN

1. INNER JOIN: Inner Join is used to retrieve only matching data from two or more table. It is represented by the symbol '=' in the where clause in the query.

2. OUTER JOIN: There are three different types of outer join: a. LEFT OUTER JOIN b. RIGHT OUTER JOIN c. FULL OUTER JOIN

a. LEFT OUTER JOIN: It retrieves all the records from left most table (irrespective of the condition specified) and retrieves only matching records from the right most table and assigns NULL for unmatched fields. Represented by the symbol '*='.

b. RIGHT OUTER JOIN: It retrieves all the records from right most table (irrespective of the condition specified) and retrieves only matching records from the left most table and assigns NULL for unmatched fields. (opposite to LEFT OUTER JOIN). Represented by the symbol '=*'.

c. FULL OUTER JOIN: It retrieves records from both the table (irrespective of the condition) and for unmatched fields it assigns NULL.

9) When we retrieve data from table in SQL Queries, and want to select second, third,........rows from table, then what is the coding of that program? 9) select * from employee where rownum<=3 minus select * from employee where rownum<=1 with this u can retrieve 2nd and 3rd rows only. Or SELECT *FROM (SELECT emp.*, rownum rank FROM emp)WHERE rank BETWEEN 2 AND 3 10) how to delete a duplicate records in a table without using rowid 10) To eliminate duplicate records there are Three Methods .. 1) using rowid: Delete from <tablename> a where rowid > ( Select min(rowid) from <tablename> B where a.keyvalues=b.keyvalues ); In the above query Keyvalues means column names which we have to compare. 2) Creating another table create table <tablename2> as select distinct *from <tablename1>; drop <tablename1> rename <tablename2> to <tablename1>; Remember to recreate all indexes, constrains ,triggers ..etc on the table 3) using rowid:

Delete from <tablename> a where exists(select 'x' from <tablename> b where b.keyvalue1=a.keyvalue2 and b.keyvalue2=b.keyvalue2 and b.rowid>a.rowid ); 11) what is rep cursor? 11)Rep Cursor is a Cursor which dynamically assigns the condition(s) 12) Why output give error message when i write select stmt, ROWNUM=2 in where clause.? 12) Rownum does not assign the number like 1,2,3,4 to the rows as it appears. Case-1 if the order is arranged in ascending order then the first item gets row num=1 Case-2 if the order is arranged in descending order then also the first item gets row num=1 instead to use rownum=2 use alias name for rownum exp :-select rownum ro,columnname from table where ro=2; If not understood pls contact me in my mail id pranabp @ aztecsoft.com 13) How can i disable a trigger trough sql prompt. 13) 1. alter table <tname> enable/disable all triggers; (to disable all triggers on table). 2.alter table <tname> enable/disable <trigger name>;(to disable specified trigger). 14) Can a function take OUT parameters. If not why? 14) he function can not hav an out parameter Because function have a return statement.

15) what is the difference between whereclause and having clause 15)The fundamental difference between "WHERE" and "HAVING" is this: "WHERE" selects input rows before groups and aggregates are computed (thus, it controls which rows go into the aggregate computation), whereas "HAVING" selects group rows after groups and aggregates are computed. Thus, the "WHERE" clause must not contain aggregate functions; it makes no sense to try to use an aggregate to determine which rows will be inputs to the aggregates. On the other hand, the "HAVING" clause always contains aggregate functions. (Strictly speaking, you are allowed to write a "HAVING" clause that doesn't use aggregates, but it's seldom useful. The same condition could be used more efficiently at the "WHERE" stage.) 16) How to find out department wise second maximum salary. select max(salary) from dept where max(salary)<(select max (salary) from dept);

17)

S-ar putea să vă placă și